From 76fdd5317e1585968877327b60f43d64eef45981 Mon Sep 17 00:00:00 2001 From: Nikola Trubitsyn Date: Tue, 9 May 2017 18:26:05 +0300 Subject: [PATCH] Make Robolectric tests run Update Robolectric to 3.3.2 Remove MyTestRunner.class and use RobolectricTestRunner.class instead --- app/build.gradle | 2 +- .../calculator/MainActivityTest.java | 7 ++++-- .../calculator/MyTestRunner.java | 22 ------------------- 3 files changed, 6 insertions(+), 25 deletions(-) delete mode 100644 app/src/test/java/com/simplemobiletools/calculator/MyTestRunner.java diff --git a/app/build.gradle b/app/build.gradle index 2a771439..f8457334 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,7 +38,7 @@ dependencies { apt 'com.jakewharton:butterknife-compiler:8.0.1' testCompile 'junit:junit:4.12' - testCompile 'org.robolectric:robolectric:3.0' + testCompile 'org.robolectric:robolectric:3.3.2' androidTestCompile 'com.android.support:support-annotations:25.3.1' androidTestCompile 'com.android.support.test:runner:0.5' diff --git a/app/src/test/java/com/simplemobiletools/calculator/MainActivityTest.java b/app/src/test/java/com/simplemobiletools/calculator/MainActivityTest.java index c0cf4fb7..315762ab 100644 --- a/app/src/test/java/com/simplemobiletools/calculator/MainActivityTest.java +++ b/app/src/test/java/com/simplemobiletools/calculator/MainActivityTest.java @@ -1,17 +1,20 @@ package com.simplemobiletools.calculator; +import com.simplemobiletools.calculator.activities.MainActivity; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import butterknife.ButterKnife; import static junit.framework.Assert.assertEquals; -@RunWith(MyTestRunner.class) -@Config(constants = BuildConfig.class, manifest = "app/src/main/AndroidManifest.xml", sdk = 21) +@RunWith(RobolectricTestRunner.class) +@Config(constants = BuildConfig.class, sdk = 21) public class MainActivityTest { MainActivity activity; diff --git a/app/src/test/java/com/simplemobiletools/calculator/MyTestRunner.java b/app/src/test/java/com/simplemobiletools/calculator/MyTestRunner.java deleted file mode 100644 index e19ba4ff..00000000 --- a/app/src/test/java/com/simplemobiletools/calculator/MyTestRunner.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.simplemobiletools.calculator; - -import org.junit.runners.model.InitializationError; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; -import org.robolectric.manifest.AndroidManifest; -import org.robolectric.res.Fs; - -public class MyTestRunner extends RobolectricTestRunner { - - public MyTestRunner(Class testClass) throws InitializationError { - super(testClass); - } - - @Override - protected AndroidManifest getAppManifest(Config config) { - return new AndroidManifest( - Fs.fileFromPath("../app/src/main/AndroidManifest.xml"), - Fs.fileFromPath("../app/src/main/res"), - Fs.fileFromPath("../app/src/main/assets")); - } -}