I have some Test which I would like to run with Robolectric, I use the 2.3-SNAPSHOT as my APP uses the ActionbarCompat i needed to use 2.3-SNAPSHOT Version as Robolectric co
Update: The annotation is now @Config(sdk = 18)
(or @Config(sdk = Build.VERSION_CODES.JELLY_BEAN_MR2)
) and the properties file mentioned in link is now robolectric.properties
.
Original Answer:
You can use the @Config
annotation to have Robolectric emulate an 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 ...
This is also possible using a file as mentioned here
Not sure what it means for your KitKat specific tests but at least the others should work.
In case people like me, still visiting the link for the similar error,
@Config(emulateSdk = )
is not working now.
Its changed to sdk--
@Config(constants = BuildConfig.class, sdk=21)
For me, I was getting error with target version 22,
java.lang.UnsupportedOperationException: Robolectric does not support API level 22
and so I emulated it to 21.
According to SdkConfig.java, Roboelectric only supports the following versions / API 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 have tried those?