Skip to content

Commit

Permalink
Merge instrumented test assertion to half the total test duration (#37)
Browse files Browse the repository at this point in the history
```diff
-BUILD SUCCESSFUL in 4m 36s
+BUILD SUCCESSFUL in 2m 24s
```
  • Loading branch information
SimonMarquis authored Sep 18, 2022
1 parent ec97aa0 commit ca76064
Showing 1 changed file with 33 additions and 117 deletions.
150 changes: 33 additions & 117 deletions venom/src/androidTest/java/com/github/venom/test/VenomTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.github.venom.test

import android.app.ActivityManager
import android.content.Context
import android.content.Context.ACTIVITY_SERVICE
import android.content.Intent
import androidx.annotation.IntRange
Expand All @@ -48,17 +47,13 @@ import org.junit.runner.RunWith
@RequiresApi(18)
class VenomTest {

private lateinit var device: UiDevice
private lateinit var appContext: Context
private lateinit var venom: Venom
private val instrumentation = InstrumentationRegistry.getInstrumentation()
private val device = UiDevice.getInstance(instrumentation)
private val appContext = instrumentation.targetContext
private val venom = Venom.createInstance(appContext)

@Before
fun setupEach() {
val instrumentation = InstrumentationRegistry.getInstrumentation()
device = UiDevice.getInstance(instrumentation)
appContext = instrumentation.targetContext
venom = Venom.createInstance(appContext)

venom.start()
collapseNotifications()
}
Expand All @@ -69,171 +64,87 @@ class VenomTest {
}

@Test
fun suicide_oneActivityInForeground_sameActivityCount() {
launchActivities(count = 1)
commitSuicide()
assertEquals(1, activityCount())
}

@Test
fun suicide_oneActivityInForeground_topRestored() {
fun suicide_oneActivityInForeground() {
launchActivities(count = 1)
commitSuicide()
assertTrue(device.hasObject(activitySelector(1)))
}

@Test
fun suicide_oneActivityInBackground_sameActivityCount() {
launchActivities(count = 1)
moveToBackgroundAndCommitSuicide()
assertEquals(1, activityCount())
assertActivities(count = 1)
}

@Test
fun suicide_oneActivityInBackground_topRestored() {
fun suicide_oneActivityInBackground() {
launchActivities(count = 1)
moveToBackgroundAndCommitSuicide()
assertTrue(device.hasObject(activitySelector(1)))
}

@Test
fun suicide_oneActivityInForegroundWithLongStop_sameActivityCount() {
launchActivities(count = 1, longStop = true)
commitSuicide()
assertEquals(1, activityCount())
assertActivities(count = 1)
}

@Test
fun suicide_oneActivityInForegroundWithLongStop_topRestored() {
fun suicide_oneActivityInForegroundWithLongStop() {
launchActivities(count = 1, longStop = true)
commitSuicide()
assertTrue(device.hasObject(activitySelector(1)))
assertActivities(count = 1)
}

@Test
fun suicide_oneActivityInBackgroundWithLongStop_sameActivityCount() {
fun suicide_oneActivityInBackgroundWithLongStop() {
launchActivities(count = 1, longStop = true)
moveToBackgroundAndCommitSuicide()
assertEquals(1, activityCount())
assertActivities(count = 1)
}

@Test
fun suicide_oneActivityInBackgroundWithLongStop_topRestored() {
launchActivities(count = 1, longStop = true)
moveToBackgroundAndCommitSuicide()
assertTrue(device.hasObject(activitySelector(1)))
}

@Test
fun suicide_oneActivityInForegroundWithLongSaveState_sameActivityCount() {
launchActivities(count = 1, longSaveState = true)
commitSuicide()
assertEquals(1, activityCount())
}

@Test
fun suicide_oneActivityInForegroundWithLongSaveState_topRestored() {
fun suicide_oneActivityInForegroundWithLongSaveState() {
launchActivities(count = 1, longSaveState = true)
commitSuicide()
assertTrue(device.hasObject(activitySelector(1)))
}

@Test
fun suicide_oneActivityInBackgroundWithLongSaveState_sameActivityCount() {
launchActivities(count = 1, longSaveState = true)
moveToBackgroundAndCommitSuicide()
assertEquals(1, activityCount())
assertActivities(count = 1)
}

@Test
fun suicide_oneActivityInBackgroundWithLongSaveState_topRestored() {
fun suicide_oneActivityInBackgroundWithLongSaveState() {
launchActivities(count = 1, longSaveState = true)
moveToBackgroundAndCommitSuicide()
assertTrue(device.hasObject(activitySelector(1)))
assertActivities(count = 1)
}

@Test
fun suicide_multipleActivityInForeground_sameActivityCount() {
fun suicide_multipleActivityInForeground() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT)
commitSuicide()
assertEquals(MULTIPLE_ACTIVITY_COUNT, activityCount())
assertActivities(count = MULTIPLE_ACTIVITY_COUNT)
}

@Test
fun suicide_multipleActivityInForeground_topRestored() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT)
commitSuicide()
assertTrue(device.hasObject(activitySelector(MULTIPLE_ACTIVITY_COUNT)))
}

@Test
fun suicide_multipleActivityInBackground_sameActivityCount() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT)
moveToBackgroundAndCommitSuicide()
assertEquals(MULTIPLE_ACTIVITY_COUNT, activityCount())
}

@Test
fun suicide_multipleActivityInBackground_topRestored() {
fun suicide_multipleActivityInBackground() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT)
moveToBackgroundAndCommitSuicide()
assertTrue(device.hasObject(activitySelector(MULTIPLE_ACTIVITY_COUNT)))
}

@Test
fun suicide_multipleActivityInForegroundWithLongStop_sameActivityCount() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longStop = true)
commitSuicide()
assertEquals(MULTIPLE_ACTIVITY_COUNT, activityCount())
assertActivities(count = MULTIPLE_ACTIVITY_COUNT)
}

@Test
fun suicide_multipleActivityInForegroundWithLongStop_topRestored() {
fun suicide_multipleActivityInForegroundWithLongStop() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longStop = true)
commitSuicide()
assertTrue(device.hasObject(activitySelector(MULTIPLE_ACTIVITY_COUNT)))
assertActivities(count = MULTIPLE_ACTIVITY_COUNT)
}

@Test
fun suicide_multipleActivityInBackgroundWithLongStop_sameActivityCount() {
fun suicide_multipleActivityInBackgroundWithLongStop() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longStop = true)
moveToBackgroundAndCommitSuicide()
assertEquals(MULTIPLE_ACTIVITY_COUNT, activityCount())
assertActivities(count = MULTIPLE_ACTIVITY_COUNT)
}

@Test
fun suicide_multipleActivityInBackgroundWithLongStop_topRestored() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longStop = true)
moveToBackgroundAndCommitSuicide()
assertTrue(device.hasObject(activitySelector(MULTIPLE_ACTIVITY_COUNT)))
}

@Test
fun suicide_multipleActivityInForegroundWithLongSaveState_sameActivityCount() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longSaveState = true)
commitSuicide()
assertEquals(MULTIPLE_ACTIVITY_COUNT, activityCount())
}

@Test
fun suicide_multipleActivityInForegroundWithLongSaveState_topRestored() {
fun suicide_multipleActivityInForegroundWithLongSaveState() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longSaveState = true)
commitSuicide()
assertTrue(device.hasObject(activitySelector(MULTIPLE_ACTIVITY_COUNT)))
assertActivities(count = MULTIPLE_ACTIVITY_COUNT)
}

@Test
fun suicide_multipleActivityInBackgroundWithLongSaveState_sameActivityCount() {
fun suicide_multipleActivityInBackgroundWithLongSaveState() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longSaveState = true)
moveToBackgroundAndCommitSuicide()
assertEquals(MULTIPLE_ACTIVITY_COUNT, activityCount())
}

@Test
fun suicide_multipleActivityInBackgroundWithLongSaveState_topRestored() {
launchActivities(count = MULTIPLE_ACTIVITY_COUNT, longSaveState = true)
moveToBackgroundAndCommitSuicide()
assertTrue(device.hasObject(activitySelector(MULTIPLE_ACTIVITY_COUNT)))
assertActivities(count = MULTIPLE_ACTIVITY_COUNT)
}

@Test
Expand Down Expand Up @@ -304,6 +215,11 @@ class VenomTest {
return testActivitiesTask?.numActivities ?: 0
}

private fun assertActivities(count: Int) {
assertEquals("Activity count", count, activityCount())
assertTrue("Activity displayed", device.hasObject(activitySelector(count)))
}

private fun moveToBackgroundAndCommitSuicide() {
device.pressHome()
commitSuicide()
Expand Down

0 comments on commit ca76064

Please sign in to comment.