Does Robolectric support API level?

I have some kind of test that I would like to run with Robolectric, I use 2.3-SNAPSHOT since my APP uses ActionbarCompat, which I need to use version 2.3-SNAPSHOT, since Robolectric could not find AppCompat themes before. So I set up Classpath in Eclipse, and I end up with the following:

java.lang.UnsupportedOperationException: Robolectric does not support API level 9, sorry! at org.robolectric.SdkConfig.<init>(SdkConfig.java:24) at org.robolectric.RobolectricTestRunner.pickSdkVersion(RobolectricTestRunner.java:288) at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:264) at org.robolectric.RobolectricTestRunner.access$100(RobolectricTestRunner.java:57) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:186) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:172) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

The manifest of my test project is as follows:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.vendor.test" android:versionCode="1" android:versionName="1.0"> <application> <uses-library android:name="android.test.runner" /> </application> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.vendor" /> </manifest> 

I always complain about the API level, no matter what I use.

Has anyone got this job?

+64
android robolectric
Dec 12 '13 at 10:59
source share
3 answers

Update: Annotation is now @Config(sdk = 18) (or @Config(sdk = Build.VERSION_CODES.JELLY_BEAN_MR2) ), and the properties file mentioned in the link is now robolectric.properties .

Original answer: You can use the @Config annotation so that Robolectric emulates the SDK version. You can put this:

 import org.robolectric.annotation.Config; @Config(emulateSdk = 18) // now @Config(sdk = 18) as of Robolectric 3.0 @RunWith(RobolectricTestRunner.class) public class SomeTest ... 

It is also possible using the file mentioned here.

Not sure what this means for your specific KitKat tests, but at least others should work.

+80
Dec 30 '14 at 21:43
source share

In the case of people like me, while still visiting the link to a similar error,

@Config(emulateSdk = ) now does not work. Its change to sdk

@Config(constants = BuildConfig.class, sdk=21)

For me, I was getting an error with target version 22,

 java.lang.UnsupportedOperationException: Robolectric does not support API level 22 

and so I imitated him until 21.

+27
Aug 05 '15 at 6:19 06:19
source share

According to SdkConfig.java , Roboelectric only supports the following API versions / levels:

 SUPPORTED_APIS.put(Build.VERSION_CODES.JELLY_BEAN, new SdkVersion("4.1.2_r1", "0")); SUPPORTED_APIS.put(Build.VERSION_CODES.JELLY_BEAN_MR1, new SdkVersion("4.2.2_r1.2", "0")); SUPPORTED_APIS.put(Build.VERSION_CODES.JELLY_BEAN_MR2, new SdkVersion("4.3_r2", "0")); SUPPORTED_APIS.put(Build.VERSION_CODES.KITKAT, new SdkVersion("4.4_r1", "0")); SUPPORTED_APIS.put(Build.VERSION_CODES.LOLLIPOP, new SdkVersion("5.0.0_r2", "0")); 

Are you sure you tried it?

+9
Dec 22 '13 at 9:13
source share



All Articles