Instrumentation works with multidex and testdroid

This commit is contained in:
mhutti1 2017-04-24 12:11:39 +02:00
parent 0eae1b022a
commit 96222e0b4a
7 changed files with 38 additions and 34 deletions

View File

@ -10,7 +10,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'com.testdroid:gradle:1.4.0'
classpath 'com.testdroid:gradle:1.5.0'
classpath 'org.apache.httpcomponents:httpclient-android:4.3.3'
}
}
@ -29,13 +29,13 @@ repositories {
}
dependencies {
compile 'com.android.support:appcompat-v7:24.1.0'
compile 'com.android.support:support-v13:24.1.0'
compile 'com.android.support:support-v4:24.1.0'
compile 'com.android.support:design:24.1.0'
compile 'com.android.support:cardview-v7:24.1.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
androidTestCompile 'com.android.support:support-annotations:24.1.0'
androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
@ -71,7 +71,8 @@ dependencies {
compile 'eu.mhutti1.utils.storage:android-storage-devices:0.5.0'
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile group: 'com.google.guava', name: 'guava', version: '20.0'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'junit:junit:4.12'
@ -141,6 +142,8 @@ android {
debug {
// True breaks local variables being shown in breakpoints
testCoverageEnabled false
// Needed for instrumentation tests on Pre 5.0
multiDexKeepProguard file('multidex-instrumentation-config.pro')
}
coverage {
@ -152,7 +155,7 @@ android {
}
}
productFlavors {
// Vanilla Kiwix app
@ -254,6 +257,9 @@ testdroid {
username System.getenv('TESTDROID_USERNAME')
password System.getenv('TESTDROID_PASSWORD')
deviceGroup 'Kiwix'
mode "FULL_RUN"
projectName "Kiwix"
fullRunConfig {
instrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
}

View File

@ -0,0 +1,5 @@
# Pre android 5.0 test dependencies must be in the primary dex
-keep class org.hamcrest.Matchers
-keep class org.kiwix.kiwixmobile.tests.** { *; }
-keep class org.mockito.** { *; }

View File

@ -44,20 +44,6 @@ public class BasicTest {
@Test
public void basicTest() {
ViewInteraction imageButton = onView(
allOf(withClassName(is("android.widget.ImageButton")),
withParent(allOf(withId(R.id.toolbar),
withParent(withId(R.id.toolbar_layout)))),
isDisplayed()));
imageButton.perform(click());
ViewInteraction imageButton2 = onView(
allOf(withClassName(is("android.widget.ImageButton")),
withParent(allOf(withId(R.id.toolbar),
withParent(withId(R.id.toolbar_layout)))),
isDisplayed()));
imageButton2.perform(click());
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
@ -91,12 +77,7 @@ public class BasicTest {
isDisplayed()));
imageView2.check(matches(isDisplayed()));
ViewInteraction imageButton4 = onView(
allOf(withClassName(is("android.widget.ImageButton")),
withParent(allOf(withId(R.id.toolbar),
withParent(withId(R.id.toolbar_layout)))),
isDisplayed()));
imageButton4.perform(click());
onView(withId(R.id.drawer_layout)).perform(DrawerActions.close());
}
@Test

View File

@ -15,6 +15,7 @@ import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingPolicies;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.view.View;
@ -22,6 +23,7 @@ import android.view.ViewGroup;
import android.view.ViewParent;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
@ -33,6 +35,7 @@ import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.kiwix.kiwixmobile.KiwixApplication;
@ -59,6 +62,12 @@ public class NetworkTest {
public ActivityTestRule<KiwixMobileActivity> mActivityTestRule = new ActivityTestRule<>(
KiwixMobileActivity.class, false, false);
@BeforeClass
public static void beforeClass() {
IdlingPolicies.setMasterPolicyTimeout(15, TimeUnit.SECONDS);
IdlingPolicies.setIdlingResourceTimeout(15, TimeUnit.SECONDS);
}
@Before
public void setUp() {
Espresso.registerIdlingResources(KiwixIdlingResource.getInstance());
@ -73,14 +82,15 @@ public class NetworkTest {
component.inject(this);
InputStream library = NetworkTest.class.getClassLoader().getResourceAsStream("library.xml");
InputStream metalinks = NetworkTest.class.getClassLoader().getResourceAsStream("test.zim.meta4");
InputStream testzim = NetworkTest.class.getClassLoader().getResourceAsStream("testzim.zim");
try {
byte[] libraryBytes = IOUtils.toByteArray(library);
mockWebServer.enqueue(new MockResponse().setBody(new String(libraryBytes)));
byte[] metalinkBytes = IOUtils.toByteArray(metalinks);
mockWebServer.enqueue(new MockResponse().setBody(new String(metalinkBytes)));
mockWebServer.enqueue(new MockResponse().setHeader("Content-Length", 63973123));
mockWebServer.enqueue(new MockResponse().setHeader("Content-Length", 357269));
Buffer buffer = new Buffer();
buffer.write(new byte[63973123]);
buffer.write(IOUtils.toByteArray(testzim));
buffer.close();
mockWebServer.enqueue(new MockResponse().setBody(buffer));
} catch (IOException e) {

View File

@ -9,7 +9,7 @@
</publisher>
<file name="wikipedia_ab_all_2017-03.zim">
<size>63973123</size>
<size>357269</size>
<!-- <mtime>1462622396</mtime> -->

Binary file not shown.

View File

@ -3,12 +3,14 @@ package org.kiwix.kiwixmobile;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;
import org.kiwix.kiwixmobile.di.components.DaggerApplicationComponent;
import org.kiwix.kiwixmobile.di.modules.ApplicationModule;
public class KiwixApplication extends Application {
public class KiwixApplication extends MultiDexApplication {
private static KiwixApplication application;
private ApplicationComponent applicationComponent;