mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
[android] fix instrumentation tests after AndroidX migration
This commit is contained in:
@@ -104,12 +104,12 @@ dependencies {
|
||||
implementation 'uk.co.samuelwall:material-tap-target-prompt:3.0.0'
|
||||
implementation 'com.vanniktech:emoji-google:0.6.0'
|
||||
implementation 'com.github.kobakei:MaterialFabSpeedDial:1.2.1'
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||
def glideVersion = '4.10.0'
|
||||
implementation("com.github.bumptech.glide:glide:$glideVersion") {
|
||||
exclude group: 'com.android.support'
|
||||
exclude module: 'disklrucache' // when there's no disk cache, we can't accidentally use it
|
||||
}
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
|
||||
@@ -131,13 +131,17 @@ dependencies {
|
||||
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
||||
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
||||
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
|
||||
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
||||
androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
|
||||
androidTestImplementation 'junit:junit:4.12'
|
||||
androidTestScreenshotImplementation "tools.fastlane:screengrab:1.2.0"
|
||||
androidTestScreenshotImplementation('tools.fastlane:screengrab:1.2.0') {
|
||||
// workaround for jetifier issue https://issuetracker.google.com/issues/123060356
|
||||
exclude group: 'com.android.support.test.uiautomator'
|
||||
}
|
||||
androidTestScreenshotImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.briar.android;
|
||||
|
||||
import org.briarproject.bramble.BrambleAndroidModule;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
|
||||
public class BriarTestComponentApplication extends BriarApplicationImpl {
|
||||
@@ -12,7 +11,7 @@ public class BriarTestComponentApplication extends BriarApplicationImpl {
|
||||
.appModule(new AppModule(this)).build();
|
||||
// We need to load the eager singletons directly after making the
|
||||
// dependency graphs
|
||||
BrambleCoreModule.initEagerSingletons(component);
|
||||
// BrambleCoreModule.initEagerSingletons(component); // FIXME AbstractMethodError
|
||||
BrambleAndroidModule.initEagerSingletons(component);
|
||||
BriarCoreModule.initEagerSingletons(component);
|
||||
AndroidEagerSingletons.initEagerSingletons(component);
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
import org.briarproject.bramble.api.account.AccountManager;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
@@ -12,13 +11,16 @@ import org.briarproject.briar.R;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public abstract class UiTest {
|
||||
|
||||
protected final String USERNAME =
|
||||
getTargetContext().getString(R.string.screenshot_alice);
|
||||
getApplicationContext().getString(R.string.screenshot_alice);
|
||||
protected static final String PASSWORD = "123456";
|
||||
|
||||
@Inject
|
||||
@@ -27,9 +29,7 @@ public abstract class UiTest {
|
||||
protected LifecycleManager lifecycleManager;
|
||||
|
||||
public UiTest() {
|
||||
BriarTestComponentApplication app =
|
||||
(BriarTestComponentApplication) getTargetContext()
|
||||
.getApplicationContext();
|
||||
BriarTestComponentApplication app = getApplicationContext();
|
||||
inject((BriarUiTestComponent) app.getApplicationComponent());
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ public abstract class UiTest {
|
||||
accountManager.createAccount(USERNAME, PASSWORD);
|
||||
if (runnable != null) {
|
||||
Intent serviceIntent =
|
||||
new Intent(getTargetContext(), BriarService.class);
|
||||
getTargetContext().startService(serviceIntent);
|
||||
new Intent(getApplicationContext(), BriarService.class);
|
||||
getApplicationContext().startService(serviceIntent);
|
||||
try {
|
||||
lifecycleManager.waitForStartup();
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.briarproject.briar.android.attachment;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
@@ -16,6 +14,9 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -264,7 +265,7 @@ public class AttachmentRetrieverIntegrationTest {
|
||||
}
|
||||
|
||||
private InputStream getAssetInputStream(String name) throws IOException {
|
||||
AssetManager assets = InstrumentationRegistry.getContext().getAssets();
|
||||
AssetManager assets = getApplicationContext().getAssets();
|
||||
return assets.open(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,19 @@ package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import android.view.Gravity;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
@@ -12,6 +10,9 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
|
||||
@@ -4,7 +4,8 @@ import org.briarproject.bramble.BrambleAndroidModule;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.bramble.account.BriarAccountModule;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
import org.briarproject.briar.android.contact.ConversationActivityScreenshotTest;
|
||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||
import org.briarproject.briar.android.conversation.ConversationActivityScreenshotTest;
|
||||
import org.briarproject.briar.android.settings.SettingsActivityScreenshotTest;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@@ -14,6 +15,7 @@ import dagger.Component;
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
AppModule.class,
|
||||
AttachmentModule.class,
|
||||
BriarCoreModule.class,
|
||||
BrambleAndroidModule.class,
|
||||
BriarAccountModule.class,
|
||||
|
||||
@@ -30,7 +30,8 @@ public abstract class ScreenshotTest extends UiTest {
|
||||
try {
|
||||
Screengrab.screenshot(name, new FalconScreenshotStrategy(activity));
|
||||
} catch (RuntimeException e) {
|
||||
if (!e.getMessage().equals("Unable to capture screenshot."))
|
||||
if (e.getMessage() == null ||
|
||||
!e.getMessage().equals("Unable to capture screenshot."))
|
||||
throw e;
|
||||
// The tests should still pass when run from AndroidStudio
|
||||
// without manually granting permissions like fastlane does.
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
package org.briarproject.briar.android;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.account.SetupActivity;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject;
|
||||
import androidx.test.uiautomator.UiSelector;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.login.OpenDatabaseActivity;
|
||||
import org.briarproject.briar.android.login.SetupActivity;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.action.ViewActions.typeText;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.intent.Intents.intended;
|
||||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static androidx.test.runner.lifecycle.Stage.PAUSED;
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||
import static org.briarproject.briar.android.ViewActions.waitForActivity;
|
||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -82,7 +77,7 @@ public class SetupDataTest extends ScreenshotTest {
|
||||
.perform(click());
|
||||
|
||||
// White-list Doze if needed
|
||||
if (needsDozeWhitelisting(getTargetContext())) {
|
||||
if (needsDozeWhitelisting(getApplicationContext())) {
|
||||
onView(withText(R.string.setup_doze_button))
|
||||
.check(matches(isDisplayed()))
|
||||
.perform(click());
|
||||
@@ -96,14 +91,8 @@ public class SetupDataTest extends ScreenshotTest {
|
||||
.perform(click());
|
||||
}
|
||||
|
||||
// wait for OpenDatabaseActivity to show up
|
||||
onView(isRoot())
|
||||
.perform(waitForActivity(testRule.getActivity(), PAUSED));
|
||||
intended(hasComponent(OpenDatabaseActivity.class.getName()));
|
||||
|
||||
assertTrue(accountManager.hasDatabaseKey());
|
||||
|
||||
lifecycleManager.waitForStartup();
|
||||
assertTrue(accountManager.hasDatabaseKey());
|
||||
createTestData();
|
||||
|
||||
// close expiry warning
|
||||
@@ -118,31 +107,18 @@ public class SetupDataTest extends ScreenshotTest {
|
||||
private void createTestData() {
|
||||
try {
|
||||
createTestDataExceptions();
|
||||
} catch (DbException | FormatException e) {
|
||||
} catch (DbException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void createTestDataExceptions()
|
||||
throws DbException, FormatException {
|
||||
String bobName =
|
||||
getTargetContext().getString(R.string.screenshot_bob);
|
||||
throws DbException {
|
||||
Context ctx = getApplicationContext();
|
||||
String bobName = ctx.getString(R.string.screenshot_bob);
|
||||
Contact bob = testDataCreator.addContact(bobName);
|
||||
|
||||
String bobHi = getTargetContext()
|
||||
.getString(R.string.screenshot_message_1);
|
||||
long bobTime = getMinutesAgo(2);
|
||||
testDataCreator.addPrivateMessage(bob, bobHi, bobTime, true);
|
||||
|
||||
String aliceHi = getTargetContext()
|
||||
.getString(R.string.screenshot_message_2);
|
||||
long aliceTime = getMinutesAgo(1);
|
||||
testDataCreator.addPrivateMessage(bob, aliceHi, aliceTime, false);
|
||||
|
||||
String bobHi2 = getTargetContext()
|
||||
.getString(R.string.screenshot_message_3);
|
||||
long bobTime2 = getMinutesAgo(0);
|
||||
testDataCreator.addPrivateMessage(bob, bobHi2, bobTime2, true);
|
||||
// TODO add messages
|
||||
|
||||
connectionRegistry.registerConnection(bob.getId(), ID, true);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
package org.briarproject.briar.android.contact;
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.BriarUiTestComponent;
|
||||
import org.briarproject.briar.android.ScreenshotTest;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||
import static org.briarproject.briar.android.contact.ConversationActivity.CONTACT_ID;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ConversationActivityScreenshotTest extends ScreenshotTest {
|
||||
@@ -34,17 +28,13 @@ public class ConversationActivityScreenshotTest extends ScreenshotTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messaging() throws Exception {
|
||||
Context targetContext = getInstrumentation().getTargetContext();
|
||||
public void messaging() {
|
||||
Context targetContext = getApplicationContext();
|
||||
Intent intent = new Intent(targetContext, ConversationActivity.class);
|
||||
intent.putExtra(CONTACT_ID, 1);
|
||||
testRule.launchActivity(intent);
|
||||
|
||||
onView(withId(R.id.conversationView))
|
||||
.perform(waitUntilMatches(allOf(
|
||||
withText(R.string.screenshot_message_3),
|
||||
isCompletelyDisplayed())
|
||||
));
|
||||
// TODO add test data and wait for it do appear
|
||||
|
||||
screenshot("manual_messaging", testRule.getActivity());
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package org.briarproject.briar.android.settings;
|
||||
|
||||
import android.content.Intent;
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.Gravity;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
@@ -15,6 +11,11 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
|
||||
@@ -62,7 +62,6 @@ dependencyVerification {
|
||||
'ch.acra:acra:4.11:acra-4.11.aar:21ca06be074749c9aaf3f7df67fcbe3695e633b92e691f025af55cabde22e551',
|
||||
'classworlds:classworlds:1.1-alpha-2:classworlds-1.1-alpha-2.jar:2bf4e59f3acd106fea6145a9a88fe8956509f8b9c0fdd11eb96fee757269e3f3',
|
||||
'com.almworks.sqlite4java:sqlite4java:0.282:sqlite4java-0.282.jar:9e1d8dd83ca6003f841e3af878ce2dc7c22497493a7bb6d1b62ec1b0d0a83c05',
|
||||
'com.android.support.test.uiautomator:uiautomator-v18:2.1.2:uiautomator-v18-2.1.2.aar:ebedea0ff22ad4a31bb59c58b3fc3f047f235c1e9650468df6da47e02487719d',
|
||||
'com.android.tools.analytics-library:protos:26.5.1:protos-26.5.1.jar:8dde1130725461fe827f2a343d353f2b51e8870661fc860d7d5ebddb097ead4e',
|
||||
'com.android.tools.analytics-library:shared:26.5.1:shared-26.5.1.jar:ccc2f3b00ec17b11401610ba68553544fc8fc517120e84439ac6eb86b875e18d',
|
||||
'com.android.tools.analytics-library:tracker:26.5.1:tracker-26.5.1.jar:3a76984c0fe2e847ca7a8b35b4780ef0447a9d1666946cb8e60466318e0ab5ae',
|
||||
|
||||
Reference in New Issue
Block a user