robolectric-gradle-plugin

Using multiple res folders with Robolectric

独自空忆成欢 提交于 2019-12-17 17:17:16
问题 My current Gradle configuration has multiple (Merged) res folders: sourceSets { androidTest { setRoot('src/test') } main { res.srcDirs = [ 'src/main/res/features/registration', 'src/main/res/features/login', 'src/main/res' ] } } But Robolectric allows me to configure a single directory using AndroidManifest: public class RobolectricGradleTestRunner extends RobolectricTestRunner { private static final int MAX_SDK_SUPPORTED_BY_ROBOLECTRIC = 18; public RobolectricGradleTestRunner(Class<?>

Using multiple res folders with Robolectric

旧巷老猫 提交于 2019-12-17 17:13:42
问题 My current Gradle configuration has multiple (Merged) res folders: sourceSets { androidTest { setRoot('src/test') } main { res.srcDirs = [ 'src/main/res/features/registration', 'src/main/res/features/login', 'src/main/res' ] } } But Robolectric allows me to configure a single directory using AndroidManifest: public class RobolectricGradleTestRunner extends RobolectricTestRunner { private static final int MAX_SDK_SUPPORTED_BY_ROBOLECTRIC = 18; public RobolectricGradleTestRunner(Class<?>

Android robolectric tests manifest merge issue (android beacon library)

允我心安 提交于 2019-12-12 05:38:50
问题 I have the simple Test Case @Config(constants = BuildConfig.class) @RunWith(RobolectricGradleTestRunner.class) public class BaseTest { @Test public void startEverTestSugarAppAsFirst() { BeaconManager.setsManifestCheckingDisabled(true); } } Unfortunately the runner hits manifestmerger issue java.lang.RuntimeException: org.altbeacon.beacon.BeaconManager$ServiceNotDeclaredException: The BeaconService is not properly declared in AndroidManifest.xml. If using Eclipse, please verify that your

Robolectric 3 with Fabric Crashlytics

☆樱花仙子☆ 提交于 2019-12-11 14:24:22
问题 I am trying to ShadowClass Crashlytics/Fabric so that Robotlectric 3 tests do not fail. What I have so far is this: The custom test runner that adds the Shadow class for Fabric: public class TestRunner extends RobolectricGradleTestRunner { public TestRunner(Class<?> klass) throws InitializationError { super(klass); } @Override protected ShadowMap createShadowMap() { return super.createShadowMap() .newBuilder().addShadowClass(ShadowFabric.class).build(); } @Override public

Robolectric 2.4 NoSuchMethodError cannot be cast to RuntimeException when creating activity

懵懂的女人 提交于 2019-12-10 14:44:13
问题 I am starting to use Robolectric in Android Studio. At first I wanted to create a simple test using hamcrest, which is shown below: @RunWith(CustomTestRunner.class) @Config(emulateSdk = 18) public class MainActivityTest { private MainActivity mainActivity; @Test public void testMainActivity() { mainActivity = buildActivity(MainActivity.class).create().get(); assertThat(mainActivity, notNullValue()); } } When executing the test throws the following exception: java.lang.ClassCastException: java

Robolectric unit tests fail after Multidex

对着背影说爱祢 提交于 2019-12-03 08:08:24
问题 So I recently merged my robolectric 3.0 upgrade with our mainline, which had added multidex support to our application. Unfortunately, this had the unfortunate side effect of causing our tests to fail/not run - they'd simply stop after the first failed attempt to install MultiDex, with this stack trace: java.lang.RuntimeException: java.lang.RuntimeException: Multi dex installation failed (/Users/me/Data/Projects/my-android/myapp/. (Is a directory)). at org.robolectric.RobolectricTestRunner$2

ClassCastException: NoClassDefFoundError cannot be cast to RuntimeException

独自空忆成欢 提交于 2019-12-03 05:52:04
I am working on upgrading my codebase to Gradle 2.2 and Android Studio 1.0. I am currently trying to get Robolectric 2.4 working, but I am experiencing a strange issue when I try and run Unit Tests. The issue occurs only after a gradle clean ; running the test suite multiple times will produce passing tests (as expected). When I run the tests after a clean, I get the following error: java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.RuntimeException I have traced the error back to this call: Activity activity = Robolectric.setupActivity(MainActivity.class

Robolectric unit tests fail after Multidex

橙三吉。 提交于 2019-12-02 21:41:12
So I recently merged my robolectric 3.0 upgrade with our mainline, which had added multidex support to our application. Unfortunately, this had the unfortunate side effect of causing our tests to fail/not run - they'd simply stop after the first failed attempt to install MultiDex, with this stack trace: java.lang.RuntimeException: java.lang.RuntimeException: Multi dex installation failed (/Users/me/Data/Projects/my-android/myapp/. (Is a directory)). at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:257) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java

Cannot add a configuration with name 'testCompile' as a configuration with that name already exists

假如想象 提交于 2019-12-01 17:38:23
问题 When updating to gradle plugin 1.1.0 I kept getting the following error Cannot add a configuration with name 'testCompile' as a configuration with that name already exists I am also using the Robolectric gradle plugin from here, v0.14.0. The new gradle 1.1.0 plugin adds additional unit test support, so I suspect the gradle and Robolectric plugins are battling for use of 'testCompile,' though I'm not sure how to resolve this. 回答1: To fix that issue i did the following: Added the following to

Manifest and setup issues getting Robolectric working with Android Studio 1.1.0

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 17:11:41
I am trying to get Robolectric tests up and working in our current project, and not having a lot of luck. My preference would be to get these to run within Android Studio 1.1.0+. This is my project structure: and here is my test: import android.widget.Button; import com.mycompany.android.app.R; 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 static org.junit.Assert.assertNotNull; @Config(manifest = "AndroidManifest.xml") @RunWith