Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/251186
Change subject: Hygiene: upgrade libraries and try to fix tests ...................................................................... Hygiene: upgrade libraries and try to fix tests * Upgrade build tools to v23.0.2. * Upgrade Gson to v2.4. * Upgrade OkHttp and MockWebServer to v2.5.0[0]. * Add Espresso and recommend Android instrumentation test dependencies[1]: * Upgrade Android JUnit Runner to v0.4.1. * Add JUnit Rules v0.4.1. * Add Espresso-core, Espresso-contrib[2], Espresso-idling-resource, and Espresso-web v2.2.1. * Upgrade Robolectric to v3.0. * Rename SyntaxHighlightTests to SyntaxHighlighterTest since it tests SyntaxHighlighter. * Change PageLoadPerformanceTests and SyntaxHighlightTests to @ActivityTestRule instead of ActivityInstrumentationTestCase2. [0] https://github.com/square/okhttp/blob/master/CHANGELOG.md#version-250 [1] https://google.github.io/android-testing-support-library/downloads/ [2] The Google testing libraries often have dependency issues. I used the workarounds mentioned here: http://stackoverflow.com/questions/30578243/why-would-adding-espresso-contrib-cause-an-inflateexception Change-Id: I6ce48b785097f0436208f14af67a54beee672bbd --- M app/build.gradle D app/src/androidTest/java/org/wikipedia/test/SyntaxHighlightTests.java A app/src/androidTest/java/org/wikipedia/test/SyntaxHighlighterTest.java M app/src/androidTest/java/org/wikipedia/test/perf/PageLoadPerformanceTests.java 4 files changed, 101 insertions(+), 75 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/86/251186/1 diff --git a/app/build.gradle b/app/build.gradle index 476b82a..2787907 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ android { compileSdkVersion 23 - buildToolsVersion '23.0.1' + buildToolsVersion '23.0.2' compileOptions { sourceCompatibility = JAVA_VERSION targetCompatibility = JAVA_VERSION @@ -155,9 +155,9 @@ compile 'com.android.support:design:23.1.0' compile 'com.android.support:recyclerview-v7:23.1.0' compile 'com.android.support:percent:23.1.0' - compile 'com.google.code.gson:gson:2.3.1' + compile 'com.google.code.gson:gson:2.4' compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' - compile 'com.squareup.okhttp:okhttp:2.4.0' + compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.squareup:otto:1.3.6' compile 'com.squareup.picasso:picasso:2.5.0' compile 'com.squareup.retrofit:retrofit:1.9.0' @@ -171,14 +171,32 @@ } compile 'net.hockeyapp.android:HockeySDK:3.6.2' - androidTestCompile('com.android.support.test:runner:0.4') - // Required by com.android.support.test:runner. - androidTestCompile 'com.android.support:support-annotations:23.1.0' - testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.9.5' - testCompile 'org.robolectric:robolectric:3.0-rc3' - testCompile 'com.squareup.okhttp:mockwebserver:2.4.0' + testCompile 'org.robolectric:robolectric:3.0' + testCompile 'com.squareup.okhttp:mockwebserver:2.5.0' + + // Required by Android JUnit Runner. + androidTestCompile 'com.android.support:support-annotations:23.1.0' + + androidTestCompile 'com.android.support.test:rules:0.4.1' // JUnit Rules + androidTestCompile 'com.android.support.test:runner:0.4.1' // Android JUnit Runner + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' + + // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, + // CountingIdlingResource + androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') { + // http://stackoverflow.com/questions/30578243/why-would-adding-espresso-contrib-cause-an-inflateexception + exclude group: 'com.android.support', module: 'appcompat' + exclude group: 'com.android.support', module: 'support-v4' + exclude module: 'recyclerview-v7' + } + + // Espresso-web for WebView support + androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1' + + // Espresso-idling-resource for synchronization with background jobs. + androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.1' } private setSigningConfigKey(config, Properties props) { diff --git a/app/src/androidTest/java/org/wikipedia/test/SyntaxHighlightTests.java b/app/src/androidTest/java/org/wikipedia/test/SyntaxHighlightTests.java deleted file mode 100644 index 694e7f4..0000000 --- a/app/src/androidTest/java/org/wikipedia/test/SyntaxHighlightTests.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.wikipedia.test; - -import android.test.ActivityInstrumentationTestCase2; -import android.widget.EditText; - -import org.wikipedia.editing.richtext.ColorSpanEx; -import org.wikipedia.editing.richtext.SpanExtents; -import org.wikipedia.editing.richtext.SyntaxHighlighter; -import org.wikipedia.page.PageActivity; - -import java.util.List; - -public class SyntaxHighlightTests extends ActivityInstrumentationTestCase2<PageActivity> { - private PageActivity activity; - - public SyntaxHighlightTests() { - super(PageActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - activity = getActivity(); - } - - public void testSyntaxHighlight() throws Exception { - - final String testStr = "foo {{template1}} bar {{template2}} baz"; - final int span1Start = 4; - final int span1End = 17; - final int span2Start = 22; - final int span2End = 35; - - EditText editText = new EditText(activity); - new SyntaxHighlighter(activity, editText, - new SyntaxHighlighter.OnSyntaxHighlightListener() { - @Override - public void syntaxHighlightResults(List<SpanExtents> spanExtents) { - assertEquals(spanExtents.size(), 2); - assertEquals(spanExtents.get(0).getClass(), ColorSpanEx.class); - assertEquals(spanExtents.get(0).getStart(), span1Start); - assertEquals(spanExtents.get(0).getEnd(), span1End); - assertEquals(spanExtents.get(1).getClass(), ColorSpanEx.class); - assertEquals(spanExtents.get(1).getStart(), span2Start); - assertEquals(spanExtents.get(1).getEnd(), span2End); - } - }); - - editText.setText(testStr); - } -} diff --git a/app/src/androidTest/java/org/wikipedia/test/SyntaxHighlighterTest.java b/app/src/androidTest/java/org/wikipedia/test/SyntaxHighlighterTest.java new file mode 100644 index 0000000..260a192 --- /dev/null +++ b/app/src/androidTest/java/org/wikipedia/test/SyntaxHighlighterTest.java @@ -0,0 +1,56 @@ +package org.wikipedia.test; + +import android.app.Activity; +import android.support.annotation.NonNull; +import android.support.test.rule.ActivityTestRule; +import android.widget.EditText; + +import org.junit.Rule; +import org.junit.Test; +import org.wikipedia.editing.richtext.ColorSpanEx; +import org.wikipedia.editing.richtext.SpanExtents; +import org.wikipedia.editing.richtext.SyntaxHighlighter; +import org.wikipedia.page.PageActivity; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; + +public class SyntaxHighlighterTest { + @Rule + @NonNull + public final ActivityTestRule<PageActivity> activityRule = new ActivityTestRule<>(PageActivity.class); + + @Test + public void testSyntaxHighlight() throws Exception { + + final String testStr = "foo {{template1}} bar {{template2}} baz"; + final int span1Start = 4; + final int span1End = 17; + final int span2Start = 22; + final int span2End = 35; + + EditText editText = new EditText(getActivity()); + new SyntaxHighlighter(getActivity(), editText, + new SyntaxHighlighter.OnSyntaxHighlightListener() { + @Override + public void syntaxHighlightResults(List<SpanExtents> spanExtents) { + assertThat(spanExtents.size(), is(2)); + assertThat(spanExtents.get(0).getClass(), instanceOf(ColorSpanEx.class)); + assertThat(spanExtents.get(0).getStart(), is(span1Start)); + assertThat(spanExtents.get(0).getEnd(), is(span1End)); + assertThat(spanExtents.get(1).getClass(), instanceOf(ColorSpanEx.class)); + assertThat(spanExtents.get(1).getStart(), is(span2Start)); + assertThat(spanExtents.get(1).getEnd(), is(span2End)); + } + }); + + editText.setText(testStr); + } + + private Activity getActivity() { + return activityRule.getActivity(); + } +} diff --git a/app/src/androidTest/java/org/wikipedia/test/perf/PageLoadPerformanceTests.java b/app/src/androidTest/java/org/wikipedia/test/perf/PageLoadPerformanceTests.java index b68bdc8..1266250 100644 --- a/app/src/androidTest/java/org/wikipedia/test/perf/PageLoadPerformanceTests.java +++ b/app/src/androidTest/java/org/wikipedia/test/perf/PageLoadPerformanceTests.java @@ -1,14 +1,18 @@ package org.wikipedia.test.perf; +import org.junit.Rule; +import org.junit.Test; import org.wikipedia.page.PageActivity; import org.wikipedia.page.PageFragment; import org.wikipedia.page.PageLoadCallbacks; import org.wikipedia.page.PageLoadTests; import org.wikipedia.testlib.TestLatch; -import android.test.ActivityInstrumentationTestCase2; +import android.support.annotation.NonNull; +import android.support.test.rule.ActivityTestRule; import android.test.suitebuilder.annotation.LargeTest; +import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNull.notNullValue; @@ -16,22 +20,14 @@ * Test performance of page loading. Update the NUM_RUNS for better statistical significance. */ @LargeTest -public class PageLoadPerformanceTests extends ActivityInstrumentationTestCase2<PageActivity> { +public class PageLoadPerformanceTests { + @Rule @NonNull + public final ActivityTestRule<PageActivity> activityRule = new ActivityTestRule<>(PageActivity.class); + private static final int NUM_RUNS = 1; //50; private final MeasurementController measurement = new MeasurementController(); - public PageLoadPerformanceTests() { - super(PageActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // Launch Activity. - getActivity(); - } - + @Test public void testLoadPages() throws Throwable { loadPageMultipleTimes("Test_page_for_app_testing/Section1"); loadPageMultipleTimes("A_long_page"); @@ -48,7 +44,8 @@ private void loadPageUi(final String title) throws Throwable { final TestLatch latch = new TestLatch(); - getInstrumentation().runOnMainSync(new Runnable() { + + getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { assertThat(getFragment(), notNullValue()); @@ -56,6 +53,8 @@ measurement.start(title); PageLoadTests.loadPage(getFragment(), title); + + } }); latch.await(); @@ -74,4 +73,8 @@ private PageFragment getFragment() { return (PageFragment) getActivity().getTopFragment(); } + + private PageActivity getActivity() { + return activityRule.getActivity(); + } } -- To view, visit https://gerrit.wikimedia.org/r/251186 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6ce48b785097f0436208f14af67a54beee672bbd Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits