Skip to content

Commit

Permalink
Finish main integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Leing committed Aug 2, 2023
1 parent 32f7856 commit d455339
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ test-compose-junit = { module = "androidx.compose.ui:ui-test-junit4", version.r
test-compose-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose" }
test-espresso = "androidx.test.espresso:espresso-core:3.5.1"
test-junit = "junit:junit:4.13.2"
test-mockk = "io.mockk:mockk:1.13.4"
test-mockk-android = "io.mockk:mockk-android:1.13.4"
# downgrading mockk due to https://github.com/mockk/mockk/issues/1035
test-mockk = "io.mockk:mockk:1.13.2"
test-mockk-android = "io.mockk:mockk-android:1.13.2"
test-robolectric = "org.robolectric:robolectric:4.9.2"
debug-ui-test-manifest = "androidx.compose.ui:ui-test-manifest:1.5.0-beta01"

Expand Down
14 changes: 7 additions & 7 deletions liveness/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ dependencies {
implementation(libs.tensorflow.support)

testImplementation(projects.testing)
androidTestImplementation(dependency.amplify.auth)
androidTestImplementation(dependency.test.compose.junit)
androidTestImplementation(dependency.test.androidx.monitor)
androidTestImplementation(dependency.test.androidx.rules)
androidTestImplementation(dependency.test.junit)
androidTestImplementation(dependency.test.mockk.android)
debugImplementation(dependency.debug.ui.test.manifest)
androidTestImplementation(libs.amplify.auth)
androidTestImplementation(libs.test.compose.junit)
androidTestImplementation(libs.test.androidx.monitor)
androidTestImplementation(libs.test.androidx.rules)
androidTestImplementation(libs.test.junit)
androidTestImplementation(libs.test.mockk.android)
debugImplementation(libs.debug.ui.test.manifest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.amplifyframework.predictions.models.FaceLivenessSessionInformation
import com.amplifyframework.predictions.options.FaceLivenessSessionOptions
import com.amplifyframework.ui.liveness.camera.FrameAnalyzer
import com.amplifyframework.ui.liveness.ml.FaceDetector
import com.amplifyframework.ui.liveness.model.LivenessCheckState
import com.amplifyframework.ui.liveness.state.LivenessState
import com.amplifyframework.ui.liveness.ui.FaceLivenessDetector
import io.mockk.CapturingSlot
Expand Down Expand Up @@ -66,7 +67,8 @@ class LivenessFlowInstrumentationTest {
private lateinit var noFaceString: String
private lateinit var multipleFaceString: String
private lateinit var connectingString: String
private lateinit var countdownString: String
private lateinit var moveCloserString: String
private lateinit var holdStillString: String

@get:Rule
val composeTestRule = createComposeRule()
Expand Down Expand Up @@ -102,8 +104,9 @@ class LivenessFlowInstrumentationTest {
R.string.amplify_ui_liveness_challenge_instruction_multiple_faces_detected,
)
connectingString = context.getString(R.string.amplify_ui_liveness_challenge_connecting)
countdownString = context.getString(
R.string.amplify_ui_liveness_challenge_instruction_hold_face_during_countdown,
moveCloserString = context.getString(R.string.amplify_ui_liveness_challenge_instruction_move_face_closer)
holdStillString = context.getString(
R.string.amplify_ui_liveness_challenge_instruction_hold_face_during_freshness,
)
}

Expand Down Expand Up @@ -303,10 +306,11 @@ class LivenessFlowInstrumentationTest {
every { faceTargetMatchingParameters.faceIouHeightThreshold }.returns(0.15f)

val faceTargetChallenge = mockk<FaceTargetChallenge>()
every { faceTargetChallenge.targetWidth }.returns(422f)
every { faceTargetChallenge.targetHeight }.returns(683f)
every { faceTargetChallenge.targetCenterX }.returns(230f)
every { faceTargetChallenge.targetCenterY }.returns(292f)
val faceRect = RectF(19f, -49f, 441f, 633f)
every { faceTargetChallenge.targetWidth }.returns(faceRect.right - faceRect.left)
every { faceTargetChallenge.targetHeight }.returns(faceRect.bottom - faceRect.top)
every { faceTargetChallenge.targetCenterX }.returns((faceRect.left + faceRect.right) / 2)
every { faceTargetChallenge.targetCenterY }.returns((faceRect.top + faceRect.bottom) / 2)
every { faceTargetChallenge.faceTargetMatching }.returns(faceTargetMatchingParameters)

val colors = listOf(
Expand Down Expand Up @@ -350,23 +354,44 @@ class LivenessFlowInstrumentationTest {
),
)

composeTestRule.waitUntil(5000) {
composeTestRule.onAllNodesWithText("asdlkfjasdf")
// update face location to show oval
livenessState?.onFrameFaceUpdate(
RectF(0f, 0f, 400f, 400f),
FaceDetector.Landmark(60f, 60f),
FaceDetector.Landmark(140f, 60f),
FaceDetector.Landmark(100f, 160f),
)

// in the same spot as it was originally, the face is too far
composeTestRule.waitUntil(1000) {
composeTestRule.onAllNodesWithText(moveCloserString)
.fetchSemanticsNodes().size == 1
}

composeTestRule.waitForIdle()

// update face to be inside the oval position
livenessState?.onFrameFaceUpdate(
faceRect,
FaceDetector.Landmark(60f, 60f),
FaceDetector.Landmark(140f, 60f),
FaceDetector.Landmark(100f, 160f),
)

// now, the face is inside the oval. wait for the colors to finish
composeTestRule.waitForIdle()

assertTrue(livenessState?.readyToSendFinalEvents == true)
val state = livenessState?.livenessCheckState?.value
assertTrue(state is LivenessCheckState.Success)
assertTrue((state as LivenessCheckState.Success).faceGuideRect == faceRect)

onLivenessComplete.captured.call()
assertTrue(completesSuccessfully)

unmockkConstructor(FrameAnalyzer::class)
}

// TODO: this gets to the camera page! next up:
// 1. figure out how to trigger the next step
// 2. test on virtual device, might be fine...

companion object {
@BeforeClass
@JvmStatic
Expand Down

0 comments on commit d455339

Please sign in to comment.