robolectric

Android: How to run PIT Mutation Testing with Robolectric?

瘦欲@ 提交于 2019-12-10 20:22:24
问题 How to use Robolectric and PIT for testing an Android Application? With Robolectric, you can run Android Tests in the JVM. With PIT you can show line coverage and do mutation testing. For me, it's ok use Eclipse+Plugins, but no requirement. This is what I have tried so far: I have an Android Project, let's call it MyProject . I now want to test MyProject in the JVM using Robolectric and PIT. Therefore, I created another Project called MyTest and managed to run Robolectric tests successfully,

Robolectric fails to run tests with google play services (maps)

允我心安 提交于 2019-12-10 19:26:25
问题 I have a project that uses google play services, maps in particular. The project is working fine. The dependency in build.gradle uses the google repository and in declared like this compile 'com.google.android.gms:play-services:3.2.25' I wanted to use the gradle-android-test-plugin, so I configured it, added the test runner, created a simple test with only assertTrue(true) and run it with ./gradlew test The test fails with a java.lang.NoClassDefFoundError: com/google/android/gms/maps/model

Robolectric - Could not load class: org.robolectric.shadows.ShadowMultiDex

こ雲淡風輕ζ 提交于 2019-12-10 17:29:32
问题 I am configuring Robolectric for a project that uses multi dex. I am using Robolectric 3.0 RC3 which should support Multidex without throwing that "Multi dex installation failed" exception. testCompile('org.robolectric:robolectric:3.0-rc3') My sample test is in src/test/java/SandwichTest: @RunWith(RobolectricGradleTestRunner.class) public class SandwichTest { @Test public void firstTest() { } } I have a global configuration file to load ShadowMultiDex in src/test/resources called robolectric

Android Unit testing with Robolectric throws error AndroidManifest.xml not found or not a file

隐身守侯 提交于 2019-12-10 17:24:41
问题 I am trying to use Robolectric to run a test case on a App in Eclipse as described in this blog, but when I run the JUnit Test, I get the following error java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\abc\workspace\SumTestCases\AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:269) at com.xtremelabs.robolectric

How to parse hex color String to Integer

可紊 提交于 2019-12-10 17:14:32
问题 I'm working on some code in Robolectric, namely IntegerResourceLoader . The following method is throwing a RuntimeException when rawValue is something such as 0xFFFF0000 : @Override public Object convertRawValue( String rawValue ) { try { return Integer.parseInt( rawValue ); } catch ( NumberFormatException nfe ) { throw new RuntimeException( rawValue + " is not an integer." ); } } I tried using Integer.decode(String) but that throws a NumberFormatException even though the grammar appears to

Robolectric 3.0 not working with AppCompat 21+

試著忘記壹切 提交于 2019-12-10 15:13:53
问题 After upgrading to AppCompat 21, a lot of our Robolectric tests fail. It looks like there is an issue with the Toolbar and AppCompatDelegate I tried both with support-v4/appcompat 22.2.1 and the versions used in the official sample for appcompat: https://github.com/robolectric/robolectric-samples/tree/master/android-appcompat-v7 Android Studio 1.3 RC4, Android Gradle Plugin 1.2.3 compileSdkVersion 21 buildToolsVersion "21.1.2" minSdkVersion 10 targetSdkVersion 21 compile 'com.android.support

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

How to test an Options Menu Item's visibility in Robolectric?

让人想犯罪 __ 提交于 2019-12-10 14:24:29
问题 I would like to assert the visibility of menu items. However, my menu items always returns true. I am using the following code to inflate my menu. SherlockMenuInflater inflater = new SherlockMenuInflater(activity); MenuBuilder menu = new MenuBuilder(activity); fragment.onCreateOptionsMenu(menu, inflater); System.out.println(menu.findItem(R.id.submit).isVisible() + " " + menu.findItem(R.id.next).isVisible() + " " + menu.findItem(R.id.done).isVisible()); assertEquals(3, menu.size());

AndroidViewModel and Unit Tests

旧城冷巷雨未停 提交于 2019-12-10 13:31:21
问题 I am using AndroidViewModel with LiveData to send Intents to a IntentService and receiving events from an EventBus. I need the Application Context for the Intents and the EventBus. What is the best way to test AndroidViewModel classes with local tests? I can get it to start with Robolectrics RuntimeEnvironment.application but there doesnt seem to be a shadowOf() for AndroidViewModel to check if the right Intents were sent to the correct receiver. Perhaps it is somehow possible to do this with

Resources$NotFoundException when calling Robolectric.buildActivity()

风格不统一 提交于 2019-12-10 04:04:50
问题 I am using Robolectric 3.0 RC3 for unit testing in Android Studio. And I am getting a ResourceNotFoundException every time I run the test. Please help me resolve the issue. build.gradle dependencies { testCompile 'junit:junit:4.12' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.0' testCompile 'org.mockito:mockito-core:1.9.5' testCompile 'org.robolectric:robolectric:3.0-rc3' compile 'com.ibm.icu:icu4j:53.1' } Test Class @Before public void