Closed kokoichi206 closed 2 years ago
It took a lot of time to execute this intent test. (mainly dependency problems ??)
@Test
public void onActivityResultTest() {
//
// CHECK:
// The physical device is NOT locked.
//
// Is this always zero ?
onView(withId(R.id.display_high_score)).check(matches(withText("max combo: 0")));
// The activity is mocked
Intent resultData = new Intent();
resultData.putExtra(MainActivity.INTENT_KEY_MAX_COMBO, 123);
android.app.Instrumentation.ActivityResult result =
new android.app.Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
intending(toPackage("io.kokoichi.sample.rhythmgame")).respondWith(result);
// Click the start button
onView(withId(R.id.play)).perform(click());
// Check whether other activity is called.
intended(toPackage("io.kokoichi.sample.rhythmgame"));
// Check whether the max_combo is updated according to the ACTIVITY RESULT or not.
onView(withId(R.id.display_high_score)).check(matches(withText("max combo: 123")));
}
This is the dependencies in build.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
}
The usage of intend, intending (Official)
MainActivity UI test