robolectric

Android - Jacoco code coverage ignores Robolectric tests

你。 提交于 2019-11-30 04:47:52
问题 Trying to get Code coverage on my Robolectric tests in Android utilising Jacoco but it simply refuses to acknowledge my Robolectric tests when creating the reports. My jacoco.gradle file is as follows: apply plugin: 'jacoco' jacoco { toolVersion = "0.7.6.201602180812" } project.afterEvaluate { android.applicationVariants.all { variant -> def name = variant.name def testTaskName = "test${name.capitalize()}UnitTest" tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "

Android: Robolectric does not support API level 1

♀尐吖头ヾ 提交于 2019-11-30 03:43:58
This is my basic test class: @RunWith(RobolectricTestRunner.class) public class MainActivityTest { @Before public void setup() { //do whatever is necessary before every test } @Test public void testActivityFound() { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); Assert.assertNotNull(activity); } } When I execute my test under Android Studio, with the Terminal window, I have this error: java.lang.UnsupportedOperationException: Robolectric does not support API level 1, sorry! at org.robolectric.SdkConfig.<init>(SdkConfig.java:24) at org.robolectric

Robolectric says “AndroidManifest.xml not found”

*爱你&永不变心* 提交于 2019-11-30 03:07:31
While trying to get Robolectric RC3 to work in Android Studio, I get Caused by: java.lang.RuntimeException: build/intermediates/bundles/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml at org.robolectric.manifest.AndroidManifest.validate(AndroidManifest.java:120) at org.robolectric.manifest.AndroidManifest.getResourcePath(AndroidManifest.java:469) at org.robolectric.manifest.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:475) at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:479) at

Android Studio + Robolectric + Gradle Class Not Found Exception

。_饼干妹妹 提交于 2019-11-30 02:46:14
问题 I downloaded Robolectric deckard-gradle project from https://github.com/robolectric/deckard-gradle and imported to Android Studio. On my first run i got !!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5) at junit.textui.TestRunner.<init>(TestRunner.java:54) at junit.textui.TestRunner.<init>(TestRunner.java:48) at junit.textui.TestRunner.<init>(TestRunner.java:41) Error and i fixed this from .iml. Then i got:

robolectric 2 - create activity with intent

我怕爱的太早我们不能终老 提交于 2019-11-30 02:40:28
问题 Does creating an activity using the .withIntent() not work in Robolectric 2? I'm doing the following activity = Robolectric.buildActivity(MyActivity.class) .create() .withIntent(intent) .get(); And i'm getting a NullPointerException when doing the following in the onCreate() of my activity. Bundle bundle = getIntent().getExtras(); I can code a null check in my onCreate() and set the intent by doing the following but it seems redundant to set the intent and call the onCreate() method again

Robolectric vs Android Test Framework

那年仲夏 提交于 2019-11-30 00:19:34
Does Robolectric provide any clear benefits compared to Android Test Framework ? I've read the docs regarding both the frameworks but as far as i can see the only clear cut benefit regarding Robolectric is that it runs on JVM rather than the DalvikVM, making it faster than Android framework. Are there any other major benefits that stand out ? 来源: https://stackoverflow.com/questions/18271474/robolectric-vs-android-test-framework

junit testing with gradle for an android project

给你一囗甜甜゛ 提交于 2019-11-30 00:02:18
I am trying to get tests ( junit and robolectric ) working in an Android project but am totally stuck. My main problem is that all testing I found with gradle somehow pull in the java plugin and then I get this error: The 'java' plugin has been applied, but it is not compatible with the Android plugins. The only way out I see at the moment is to split into test and app project - but I would like to avoid that. Any examples/hints would be highly appreciated! In the official documentation there is no mention of unit-testing - only Instrumentation-Tests - but I want unit-tests to get results fast

Providing test data for SharedPreferences for Robolectric

核能气质少年 提交于 2019-11-29 22:06:29
Just started to use Robolectric and it seems to be pretty much what I need. However, I've hit a bit of a roadblock with regards to the use of SharedPreferences. I have two tests cases Activity expects a new/empty sharedPreferences Activity expects sharedPreferences with some data in it already For Test Case 1, the tests are passing as expected, so all good :) However, for Test Case 2 I can't seem to figure out a nice way to provide Robolectric with some fake data, so the Activity is able to access this fake data. It feels like a very common use case, but I can't seem to figure out how to do it

ClassCastException exception when running Robolectric test with Power Mock on multiple files

僤鯓⒐⒋嵵緔 提交于 2019-11-29 17:59:05
问题 So I set up the power mock based on the reference guide here. It all seems to run perfectly fine with a single test class. But when executing multiple JUnit tests I am getting the following error on the second test class. As you can see from the stacktrace below I am trying to mock a otto Bus instance. It seemed to mock properly on the first test class but on the the second class I am getting this class cast exception. On the stacktrace I am getting suggestion to disable Objenisis cache but I

Testing async tasks with robolectric

主宰稳场 提交于 2019-11-29 16:20:17
问题 Do you know how to implement unit testing for AsyncTasks using Robolectric ? Any pointers will be appreciated. 回答1: Call execute(...) on the task, then to wait for the result call Robolectric.runBackgroundTasks() / Robolectric.flushBackgroundThreadScheduler() then you can assert. @Test public void test() { //create task MyAsyncTask asyncTask = new MyAsyncTask(); //start task asyncTask.execute(...); //wait for task code // Robolectric.runBackgroundTasks(); (pre 3.0) Robolectric