问题描述
我有一些测试,我想与Robolectric跑,我用的是2.3快照作为我的应用程序使用ActionbarCompat我需要使用2.3快照版本为Robolectric找不到AppCompat主题之前。所以,我安装了Eclipse中的类路径和我结束了这一点:
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 could not find the AppCompat Themes before. So I setup the Classpath in Eclipse and I end up with this:
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 like this:
<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>
我总是抱怨对API级别,不管我用什么。
I complains always about the API Level, no matter what i use.
任何人有这方面的工作?
Anyone got this working ?
推荐答案
您可以使用 @Config
标注有Robolectric模拟一个SDK版本。你可以把这样的:
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)
@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.
这篇关于是否Robolectric支持API级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!