screenshot-tests-for-android
screenshot-tests-for-android copied to clipboard
How to run specific test cases in a specific class?
I have a class that contains screenshot-tests with the following code:
class ScreenshotTestingTests {
@get:Rule
var activityTestRule = ActivityTestRule(MainActivity::class.java)
@Test
fun testHomeActivity() {
val intent = Intent()
val activity = activityTestRule.launchActivity(intent)
Screenshot.snapActivity(activity).record()
}
}
and another class that contains normal instrumented tests with the following code:
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.andalus.screenshottestingdemo", appContext.packageName)
}
@Test
fun testMainActivity_buttonHasCorrectId() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.button)).check(matches(withText("BUTTON")))
}
}
@Test
fun testMainActivity_buttonHasCorrectId1() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.button)).check(matches(withText("BUTTON")))
}
}
@Test
fun testMainActivity_buttonHasCorrectId2() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.button)).check(matches(withText("BUTTON")))
}
}
@Test
fun testMainActivity_buttonHasCorrectId3() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.button)).check(matches(withText("BUTTON")))
}
}
@Test
fun testMainActivity_buttonHasCorrectId4() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.button)).check(matches(withText("BUTTON")))
}
}
@Test
fun testMainActivity_buttonHasCorrectId5() {
ActivityScenario.launch(MainActivity::class.java).use {
onView(withId(R.id.button)).check(matches(withText("BUTTON")))
}
}
}
When I try to run recordDebugAndroidTestScreenshotTest
, runDebugAndroidTestScreenshotTest
, or verifyDebugAndroidTestScreenshotTest
,
all the test cases are started and I get in the log
Starting 8 tests on Google Pixel C - 7.1.1
I want only to start the "screenshot-related" tests only.
Is this possible?
./gradlew :app:verifyDebugAndroidTestScreenshotTest -Pandroid.testInstrumentationRunnerArguments.class=full_package_name.ClassName#methodName
You can change :app: by your module name, and verify to record or other tasks.
@malkes when you run the above command on a given testclass or testclass.method, using record instead of verify, it seems to delete all previously recorded screenshots locally.. is there a way to have it not delete other screenshots?