mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Use Android Test Orchestrator to have a clean state for each test
fixes flaky/broken espresso tests
This commit is contained in:
@@ -40,6 +40,7 @@ android test:
|
|||||||
paths:
|
paths:
|
||||||
- kernel.log
|
- kernel.log
|
||||||
- logcat.txt
|
- logcat.txt
|
||||||
|
- briar-android/build/reports/androidTests/connected/flavors/*
|
||||||
expire_in: 3 days
|
expire_in: 3 days
|
||||||
when: on_failure
|
when: on_failure
|
||||||
when: manual
|
when: manual
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ android {
|
|||||||
buildConfigField "Long", "BuildTimestamp",
|
buildConfigField "Long", "BuildTimestamp",
|
||||||
"${getStdout(['git', 'log', '-n', '1', '--format=%ct'], now)}000L"
|
"${getStdout(['git', 'log', '-n', '1', '--format=%ct'], now)}000L"
|
||||||
testInstrumentationRunner 'org.briarproject.briar.android.BriarTestRunner'
|
testInstrumentationRunner 'org.briarproject.briar.android.BriarTestRunner'
|
||||||
testInstrumentationRunnerArguments disableAnalytics: 'true'
|
testInstrumentationRunnerArguments disableAnalytics: 'true', clearPackageData: 'true'
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -80,6 +80,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testOptions {
|
testOptions {
|
||||||
|
execution 'ANDROIDX_TEST_ORCHESTRATOR'
|
||||||
unitTests {
|
unitTests {
|
||||||
includeAndroidResources = true
|
includeAndroidResources = true
|
||||||
}
|
}
|
||||||
@@ -148,6 +149,8 @@ dependencies {
|
|||||||
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
|
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
|
||||||
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
|
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
|
||||||
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
|
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
|
||||||
|
androidTestImplementation 'androidx.test:runner:1.3.0'
|
||||||
|
androidTestUtil 'androidx.test:orchestrator:1.3.0'
|
||||||
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
||||||
androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
|
androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
|
||||||
androidTestImplementation 'junit:junit:4.13.1'
|
androidTestImplementation 'junit:junit:4.13.1'
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public abstract class UiTest {
|
|||||||
@Override
|
@Override
|
||||||
protected void beforeActivityLaunched() {
|
protected void beforeActivityLaunched() {
|
||||||
super.beforeActivityLaunched();
|
super.beforeActivityLaunched();
|
||||||
accountManager.deleteAccount();
|
// Android Test Orchestrator already clears existing accounts
|
||||||
accountManager.createAccount(USERNAME, PASSWORD);
|
accountManager.createAccount(USERNAME, PASSWORD);
|
||||||
Intent serviceIntent =
|
Intent serviceIntent =
|
||||||
new Intent(getApplicationContext(), BriarService.class);
|
new Intent(getApplicationContext(), BriarService.class);
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
@Override
|
@Override
|
||||||
protected void inject(BriarUiTestComponent component) {
|
protected void inject(BriarUiTestComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
accountManager.deleteAccount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.junit.ClassRule;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
import tools.fastlane.screengrab.FalconScreenshotStrategy;
|
import tools.fastlane.screengrab.FalconScreenshotStrategy;
|
||||||
import tools.fastlane.screengrab.Screengrab;
|
import tools.fastlane.screengrab.Screengrab;
|
||||||
import tools.fastlane.screengrab.locale.LocaleTestRule;
|
import tools.fastlane.screengrab.locale.LocaleTestRule;
|
||||||
@@ -26,6 +27,10 @@ public abstract class ScreenshotTest extends UiTest {
|
|||||||
@Inject
|
@Inject
|
||||||
protected Clock clock;
|
protected Clock clock;
|
||||||
|
|
||||||
|
protected void screenshot(String name, ActivityScenarioRule<?> rule) {
|
||||||
|
rule.getScenario().onActivity(activity -> screenshot(name, activity));
|
||||||
|
}
|
||||||
|
|
||||||
protected void screenshot(String name, Activity activity) {
|
protected void screenshot(String name, Activity activity) {
|
||||||
try {
|
try {
|
||||||
Screengrab.screenshot(name, new FalconScreenshotStrategy(activity));
|
Screengrab.screenshot(name, new FalconScreenshotStrategy(activity));
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.uiautomator.UiDevice;
|
import androidx.test.uiautomator.UiDevice;
|
||||||
import androidx.test.uiautomator.UiObject;
|
import androidx.test.uiautomator.UiObject;
|
||||||
@@ -22,26 +22,22 @@ import static androidx.test.espresso.action.ViewActions.click;
|
|||||||
import static androidx.test.espresso.action.ViewActions.typeText;
|
import static androidx.test.espresso.action.ViewActions.typeText;
|
||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
|
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||||
|
import static org.hamcrest.Matchers.allOf;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SetupDataTest extends ScreenshotTest {
|
public class SetupDataTest extends ScreenshotTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public IntentsTestRule<SetupActivity> testRule =
|
public ActivityScenarioRule<SetupActivity> testRule =
|
||||||
new IntentsTestRule<SetupActivity>(SetupActivity.class) {
|
new ActivityScenarioRule<>(SetupActivity.class);
|
||||||
@Override
|
|
||||||
protected void beforeActivityLaunched() {
|
|
||||||
super.beforeActivityLaunched();
|
|
||||||
accountManager.deleteAccount();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(BriarUiTestComponent component) {
|
protected void inject(BriarUiTestComponent component) {
|
||||||
@@ -59,7 +55,7 @@ public class SetupDataTest extends ScreenshotTest {
|
|||||||
onView(withId(R.id.nickname_entry))
|
onView(withId(R.id.nickname_entry))
|
||||||
.perform(waitUntilMatches(withText(USERNAME)));
|
.perform(waitUntilMatches(withText(USERNAME)));
|
||||||
|
|
||||||
screenshot("manual_create_account", testRule.getActivity());
|
screenshot("manual_create_account", testRule);
|
||||||
|
|
||||||
onView(withId(R.id.next))
|
onView(withId(R.id.next))
|
||||||
.check(matches(isDisplayed()))
|
.check(matches(isDisplayed()))
|
||||||
@@ -73,7 +69,7 @@ public class SetupDataTest extends ScreenshotTest {
|
|||||||
.check(matches(isDisplayed()))
|
.check(matches(isDisplayed()))
|
||||||
.perform(typeText(PASSWORD));
|
.perform(typeText(PASSWORD));
|
||||||
onView(withId(R.id.next))
|
onView(withId(R.id.next))
|
||||||
.check(matches(isDisplayed()))
|
.check(matches(allOf(isDisplayed(), isEnabled())))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
|
|
||||||
// White-list Doze if needed
|
// White-list Doze if needed
|
||||||
@@ -94,14 +90,6 @@ public class SetupDataTest extends ScreenshotTest {
|
|||||||
lifecycleManager.waitForStartup();
|
lifecycleManager.waitForStartup();
|
||||||
assertTrue(accountManager.hasDatabaseKey());
|
assertTrue(accountManager.hasDatabaseKey());
|
||||||
createTestData();
|
createTestData();
|
||||||
|
|
||||||
// close expiry warning
|
|
||||||
onView(withId(R.id.expiryWarning))
|
|
||||||
.perform(waitUntilMatches(isDisplayed()));
|
|
||||||
onView(withId(R.id.expiryWarningClose))
|
|
||||||
.check(matches(isDisplayed()));
|
|
||||||
onView(withId(R.id.expiryWarningClose))
|
|
||||||
.perform(click());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTestData() {
|
private void createTestData() {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.junit.runner.RunWith;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.test.espresso.contrib.DrawerActions;
|
import androidx.test.espresso.contrib.DrawerActions;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.rule.ActivityTestRule;
|
|
||||||
|
|
||||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
import static androidx.test.espresso.Espresso.onView;
|
||||||
@@ -38,8 +37,8 @@ import static org.junit.Assume.assumeTrue;
|
|||||||
public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ActivityTestRule<SettingsActivity> testRule =
|
public CleanAccountTestRule<SettingsActivity> testRule =
|
||||||
new ActivityTestRule<>(SettingsActivity.class);
|
new CleanAccountTestRule<>(SettingsActivity.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(BriarUiTestComponent component) {
|
protected void inject(BriarUiTestComponent component) {
|
||||||
|
|||||||
@@ -51,9 +51,11 @@ dependencyVerification {
|
|||||||
'androidx.test.espresso:espresso-idling-resource:3.3.0:espresso-idling-resource-3.3.0.aar:29519b112731f289cc6e2f9b2eccc5ea72c754b04272bb93370f45d7e170a7c6',
|
'androidx.test.espresso:espresso-idling-resource:3.3.0:espresso-idling-resource-3.3.0.aar:29519b112731f289cc6e2f9b2eccc5ea72c754b04272bb93370f45d7e170a7c6',
|
||||||
'androidx.test.espresso:espresso-intents:3.3.0:espresso-intents-3.3.0.aar:5b6cd6aadce78edc705d93c1e81ace3b59be97128aca0e88fd9c5c176aa9bf10',
|
'androidx.test.espresso:espresso-intents:3.3.0:espresso-intents-3.3.0.aar:5b6cd6aadce78edc705d93c1e81ace3b59be97128aca0e88fd9c5c176aa9bf10',
|
||||||
'androidx.test.ext:junit:1.1.2:junit-1.1.2.aar:6c6ab120c640bf16fcaae69cb83c144d0ed6b6298562be0ac35e37ed969c0409',
|
'androidx.test.ext:junit:1.1.2:junit-1.1.2.aar:6c6ab120c640bf16fcaae69cb83c144d0ed6b6298562be0ac35e37ed969c0409',
|
||||||
|
'androidx.test.services:test-services:1.3.0:test-services-1.3.0.apk:1b88faab6864baf25c5d0b92a610c283c159a566e7a56c03307117fa1b542993',
|
||||||
'androidx.test.uiautomator:uiautomator:2.2.0:uiautomator-2.2.0.aar:2838e9d961dbffefbbd229a2bd4f6f82ac4fb2462975862a9e75e9ed325a3197',
|
'androidx.test.uiautomator:uiautomator:2.2.0:uiautomator-2.2.0.aar:2838e9d961dbffefbbd229a2bd4f6f82ac4fb2462975862a9e75e9ed325a3197',
|
||||||
'androidx.test:core:1.3.0:core-1.3.0.aar:86549cae8c5b848f817e2c716e174c7dab61caf0b4df9848680eeb753089a337',
|
'androidx.test:core:1.3.0:core-1.3.0.aar:86549cae8c5b848f817e2c716e174c7dab61caf0b4df9848680eeb753089a337',
|
||||||
'androidx.test:monitor:1.3.0:monitor-1.3.0.aar:f73a31306a783e63150c60c49e140dc38da39a1b7947690f4b73387b5ebad77e',
|
'androidx.test:monitor:1.3.0:monitor-1.3.0.aar:f73a31306a783e63150c60c49e140dc38da39a1b7947690f4b73387b5ebad77e',
|
||||||
|
'androidx.test:orchestrator:1.3.0:orchestrator-1.3.0.apk:676f808d08a3d05050eae30c3b7d92ce5cef1e00a54d68355bb7e7d4b72366fe',
|
||||||
'androidx.test:rules:1.3.0:rules-1.3.0.aar:c1753946c498b0d5d7cf341cfed661f66915c4c9deb4ed10462a08ae33b2429a',
|
'androidx.test:rules:1.3.0:rules-1.3.0.aar:c1753946c498b0d5d7cf341cfed661f66915c4c9deb4ed10462a08ae33b2429a',
|
||||||
'androidx.test:runner:1.3.0:runner-1.3.0.aar:61d13f5a9fcbbd73ba18fa84e1d6a0111c6e1c665a89b418126966e61fffd93b',
|
'androidx.test:runner:1.3.0:runner-1.3.0.aar:61d13f5a9fcbbd73ba18fa84e1d6a0111c6e1c665a89b418126966e61fffd93b',
|
||||||
'androidx.tracing:tracing:1.0.0:tracing-1.0.0.aar:07b8b6139665b884a162eccf97891ca50f7f56831233bf25168ae04f7b568612',
|
'androidx.tracing:tracing:1.0.0:tracing-1.0.0.aar:07b8b6139665b884a162eccf97891ca50f7f56831233bf25168ae04f7b568612',
|
||||||
|
|||||||
Reference in New Issue
Block a user