i有一个测试套件,该套件在类中具有mutiple Testcase每个测试案例都是隔离的因此,当我执行TestSuite类时,我想为每个TestCase重新启动该应用
在浓缩咖啡中的每个单独的测试用例
中,我如何从开始重新启动应用程序预先感谢
@Test
public void testcase1() {
//from first screen
}
@Test
public void testcase2() {
//from first screen
}
还有另一个堆栈溢出答案似乎可以回答这个问题。如果您想在Kotlin中这样做,尽管我将答案转换为多次重新启动以进行不同的测试。
@RunWith(AndroidJUnit4::class)
class ExampleEspressoTest {
@get:Rule
val rule = ActivityTestRule(
activityClass = MainActivity::class.java,
initialTouchMode = false,
launchActivity = false) //set to false to customize intent
@Test
fun testCustomIntent() {
val intent = Intent().apply {
putExtra("your_key", "your_value")
}
rule.launchActivity(intent)
//continue with your test
}
}
如果您需要启动方法/测试,并且何时完成清晰的数据并启动下一个数据,则应使用命令。
查看此文档:https://developer.android.com/studio/test/command-line
我正在使用此命令:
./gradlew testVariantNameUnitTest --tests *.sampleTestMethod
可能有几种方法可以做到这一点,但是我们想要一种在本地和Google Fire Base Test Lab上都起作用的方法,因此最终在默认配置下使用build.gradle
文件中使用配置。
defaultConfig{
testInstrumentationRunnerArguments clearPackageData: 'true'
}
参考:https://developer.android.com/training/testing/junit-runner#ato-gradle
另外,您还使用这些跑步者参数来配置您想要基于构建变体或其他配置选项运行的不同测试,如果您想要更多详细信息,请查看我的帖子。