Skip to content

Commit d455339

Browse files
author
Thomas Leing
committed
Finish main integration test
1 parent 32f7856 commit d455339

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

gradle/libs.versions.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ test-compose-junit = { module = "androidx.compose.ui:ui-test-junit4", version.r
4545
test-compose-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "compose" }
4646
test-espresso = "androidx.test.espresso:espresso-core:3.5.1"
4747
test-junit = "junit:junit:4.13.2"
48-
test-mockk = "io.mockk:mockk:1.13.4"
49-
test-mockk-android = "io.mockk:mockk-android:1.13.4"
48+
# downgrading mockk due to https://github.com/mockk/mockk/issues/1035
49+
test-mockk = "io.mockk:mockk:1.13.2"
50+
test-mockk-android = "io.mockk:mockk-android:1.13.2"
5051
test-robolectric = "org.robolectric:robolectric:4.9.2"
5152
debug-ui-test-manifest = "androidx.compose.ui:ui-test-manifest:1.5.0-beta01"
5253

liveness/build.gradle.kts

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ dependencies {
5757
implementation(libs.tensorflow.support)
5858

5959
testImplementation(projects.testing)
60-
androidTestImplementation(dependency.amplify.auth)
61-
androidTestImplementation(dependency.test.compose.junit)
62-
androidTestImplementation(dependency.test.androidx.monitor)
63-
androidTestImplementation(dependency.test.androidx.rules)
64-
androidTestImplementation(dependency.test.junit)
65-
androidTestImplementation(dependency.test.mockk.android)
66-
debugImplementation(dependency.debug.ui.test.manifest)
60+
androidTestImplementation(libs.amplify.auth)
61+
androidTestImplementation(libs.test.compose.junit)
62+
androidTestImplementation(libs.test.androidx.monitor)
63+
androidTestImplementation(libs.test.androidx.rules)
64+
androidTestImplementation(libs.test.junit)
65+
androidTestImplementation(libs.test.mockk.android)
66+
debugImplementation(libs.debug.ui.test.manifest)
6767
}

liveness/src/androidTest/java/com/amplifyframework/ui/liveness/LivenessFlowInstrumentationTest.kt

+38-13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.amplifyframework.predictions.models.FaceLivenessSessionInformation
2727
import com.amplifyframework.predictions.options.FaceLivenessSessionOptions
2828
import com.amplifyframework.ui.liveness.camera.FrameAnalyzer
2929
import com.amplifyframework.ui.liveness.ml.FaceDetector
30+
import com.amplifyframework.ui.liveness.model.LivenessCheckState
3031
import com.amplifyframework.ui.liveness.state.LivenessState
3132
import com.amplifyframework.ui.liveness.ui.FaceLivenessDetector
3233
import io.mockk.CapturingSlot
@@ -66,7 +67,8 @@ class LivenessFlowInstrumentationTest {
6667
private lateinit var noFaceString: String
6768
private lateinit var multipleFaceString: String
6869
private lateinit var connectingString: String
69-
private lateinit var countdownString: String
70+
private lateinit var moveCloserString: String
71+
private lateinit var holdStillString: String
7072

7173
@get:Rule
7274
val composeTestRule = createComposeRule()
@@ -102,8 +104,9 @@ class LivenessFlowInstrumentationTest {
102104
R.string.amplify_ui_liveness_challenge_instruction_multiple_faces_detected,
103105
)
104106
connectingString = context.getString(R.string.amplify_ui_liveness_challenge_connecting)
105-
countdownString = context.getString(
106-
R.string.amplify_ui_liveness_challenge_instruction_hold_face_during_countdown,
107+
moveCloserString = context.getString(R.string.amplify_ui_liveness_challenge_instruction_move_face_closer)
108+
holdStillString = context.getString(
109+
R.string.amplify_ui_liveness_challenge_instruction_hold_face_during_freshness,
107110
)
108111
}
109112

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

305308
val faceTargetChallenge = mockk<FaceTargetChallenge>()
306-
every { faceTargetChallenge.targetWidth }.returns(422f)
307-
every { faceTargetChallenge.targetHeight }.returns(683f)
308-
every { faceTargetChallenge.targetCenterX }.returns(230f)
309-
every { faceTargetChallenge.targetCenterY }.returns(292f)
309+
val faceRect = RectF(19f, -49f, 441f, 633f)
310+
every { faceTargetChallenge.targetWidth }.returns(faceRect.right - faceRect.left)
311+
every { faceTargetChallenge.targetHeight }.returns(faceRect.bottom - faceRect.top)
312+
every { faceTargetChallenge.targetCenterX }.returns((faceRect.left + faceRect.right) / 2)
313+
every { faceTargetChallenge.targetCenterY }.returns((faceRect.top + faceRect.bottom) / 2)
310314
every { faceTargetChallenge.faceTargetMatching }.returns(faceTargetMatchingParameters)
311315

312316
val colors = listOf(
@@ -350,23 +354,44 @@ class LivenessFlowInstrumentationTest {
350354
),
351355
)
352356

353-
composeTestRule.waitUntil(5000) {
354-
composeTestRule.onAllNodesWithText("asdlkfjasdf")
357+
// update face location to show oval
358+
livenessState?.onFrameFaceUpdate(
359+
RectF(0f, 0f, 400f, 400f),
360+
FaceDetector.Landmark(60f, 60f),
361+
FaceDetector.Landmark(140f, 60f),
362+
FaceDetector.Landmark(100f, 160f),
363+
)
364+
365+
// in the same spot as it was originally, the face is too far
366+
composeTestRule.waitUntil(1000) {
367+
composeTestRule.onAllNodesWithText(moveCloserString)
355368
.fetchSemanticsNodes().size == 1
356369
}
357370

358371
composeTestRule.waitForIdle()
359372

373+
// update face to be inside the oval position
374+
livenessState?.onFrameFaceUpdate(
375+
faceRect,
376+
FaceDetector.Landmark(60f, 60f),
377+
FaceDetector.Landmark(140f, 60f),
378+
FaceDetector.Landmark(100f, 160f),
379+
)
380+
381+
// now, the face is inside the oval. wait for the colors to finish
382+
composeTestRule.waitForIdle()
383+
384+
assertTrue(livenessState?.readyToSendFinalEvents == true)
385+
val state = livenessState?.livenessCheckState?.value
386+
assertTrue(state is LivenessCheckState.Success)
387+
assertTrue((state as LivenessCheckState.Success).faceGuideRect == faceRect)
388+
360389
onLivenessComplete.captured.call()
361390
assertTrue(completesSuccessfully)
362391

363392
unmockkConstructor(FrameAnalyzer::class)
364393
}
365394

366-
// TODO: this gets to the camera page! next up:
367-
// 1. figure out how to trigger the next step
368-
// 2. test on virtual device, might be fine...
369-
370395
companion object {
371396
@BeforeClass
372397
@JvmStatic

0 commit comments

Comments
 (0)