我按照官方教程将 robolectric 添加到我现有的 Android 应用程序中。但是当我尝试运行一个简单的测试时,我收到了一个错误:
java.lang.RuntimeException: No shadows modules found containing a org.robolectric.ShadowsAdapter
at org.robolectric.Robolectric.instantiateShadowsAdapter(Robolectric.java:223)
at org.robolectric.Robolectric.getShadowsAdapter(Robolectric.java:48)
at org.robolectric.internal.ParallelUniverse.<init>(ParallelUniverse.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
......
这是我的测试:
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
public class ExampleUnitTest {
@Test
public void test() throws Exception {
}
}
build.gradle 文件:
dependencies {
....
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.1.3"
}
最佳答案
尝试更改:
testCompile“org.robolectric:robolectric:3.1.3”
到
testCompile“org.robolectric:robolectric:3.1.2”
关于java - Robolectric 未找到包含 org.robolectric.ShadowsAdapter 的阴影模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40280818/