I'm trying to setup a test using Robolectric to click on a menu button in this repository. Basic Robolectric tests will run, but I'm not able to run any project-specific test using resources because it says it can't find my AndroidManifest.xml. After running ../gradlew clean check
, here's the standard output from the Robolectric html file:
我正在尝试使用Robolectric来设置一个测试,以单击此存储库中的菜单按钮。基本的Robolectric测试会运行,但我不能使用参考资料运行任何项目特定的测试,因为它说找不到我的AndroidManifest.xml。跑后. ./gradlew clean check,这是robectric html文件的标准输出:
WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE).
警告:在./AndroidManifest.xml文件中没有发现。回到Android OS资源。要删除此警告,请使用@Config(manifest=Config.NONE)注释您的测试类。
I found these instructions which indicate I should create an org.robolectric.Config.properties
file, but I'm not sure where to put it. I've tried everywhere, pretty much, and despite moving the file, the path in the error message is always the same as above (./AndroidManifest.xml). This makes me think the build process has never picked up the settings in the file org.robolectric.Config.properties
.
我找到了这些指示,指示我应该创建一个org.robolectric.Config。属性文件,但我不知道该放在哪里。我几乎到处都试过了,尽管移动了文件,错误消息中的路径始终与上面的一样(./AndroidManifest.xml)。这使我认为构建过程从来没有在文件org.robolectric.Config.properties中获得设置。
I also tried the @Config(manifest="") directive but this gave me a cannot find symbol
error. If I move the AndroidManifest.xml into my project directory, then I get an error about it not being able to find the path ./res/values
and I wasn't able to resolve that either. Any ideas?
我还尝试了@Config(manifest="")指令,但这给了我一个无法查找符号错误。如果我移动机器人清单。xml到我的项目目录中,然后我得到一个错误关于它不能找到路径。/res/值,我也不能解决这个问题。什么好主意吗?
Update 1
更新1
Thanks Eugen, I'm now using @RunWith(RobolectricGradleTestRunner.class)
instead of @RunWith(RobolectricTestRunner)
.
感谢Eugen,我现在使用@RunWith(robolectricgradletestr. class),而不是@RunWith(RobolectricTestRunner)。
Now I get a different error, still occurring on the same line of my BasicTest.java
现在我得到了一个不同的错误,仍然出现在BasicTest.java的同一行上
KeywordList keywordList = Robolectric.buildActivity(KeywordList.class).create().get();
Below are results from the standard error, standard output, and "failed tests" tab in the Robolectric test report:
下面是Robolectric测试报告中的标准错误、标准输出和“失败测试”选项卡的结果:
Note: I also tried substituting in a jar built from the latest Robolectric updates, robolectric-2.2-SNAPSHOT.jar, but still got an error.
注意:我还尝试在一个由最新的Robolectric更新(robolectric-2.2-SNAPSHOT)构建的jar中进行替换。jar,但是仍然有一个错误。
Standard Error
标准错误
WARNING: no system properties value for ro.build.date.utc
警告:ro.build.date.utc没有系统属性值
Standard Output
标准输出
DEBUG: Loading resources for net.frontlinesms.android from ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug...
DEBUG: Loading resources for android from jar:~/.m2/repository/org/robolectric/android-res/4.1.2_r1_rc/android-res-4.1.2_r1_rc-real.jar!/res...
INFO: no id mapping found for android:drawable/scrollbar_handle_horizontal; assigning ID #0x1140002
INFO: no id mapping found for android:drawable/scrollbar_handle_vertical; assigning ID #0x1140003
INFO: no id mapping found for android:color/highlighted_text_dark; assigning ID #0x1140004
INFO: no id mapping found for android:color/hint_foreground_dark; assigning ID #0x1140005
INFO: no id mapping found for android:color/link_text_dark; assigning ID #0x1140006
INFO: no id mapping found for android:color/dim_foreground_dark_disabled; assigning ID #0x1140007
INFO: no id mapping found for android:color/dim_foreground_dark; assigning ID #0x1140008
INFO: no id mapping found for android:color/dim_foreground_dark_inverse_disabled; assigning ID #0x1140009
INFO: no id mapping found for android:color/dim_foreground_dark_inverse; assigning ID #0x114000a
INFO: no id mapping found for android:color/bright_foreground_dark_inverse; assigning ID #0x114000b
INFO: no id mapping found for android:layout/text_edit_paste_window; assigning ID #0x114000c
INFO: no id mapping found for android:layout/text_edit_no_paste_window; assigning ID #0x114000d
INFO: no id mapping found for android:layout/text_edit_side_paste_window; assigning ID #0x114000e
INFO: no id mapping found for android:layout/text_edit_side_no_paste_window; assigning ID #0x114000f
INFO: no id mapping found for android:layout/text_edit_suggestion_item; assigning ID #0x1140010
Failed Tests
失败的测试
android.view.InflateException: XML file ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug/layout/rule_list.xml line #-1 (sorry, not yet implemented): Error inflating class net.frontlinesms.android.ui.view.ActionBar
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272)
at android.app.Activity.setContentView(Activity.java)
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70)
at android.app.Activity.performCreate(Activity.java:5008)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:114)
at org.robolectric.util.ActivityController.create(ActivityController.java:126)
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:352)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:455)
at android.app.Activity.setContentView(Activity.java)
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70)
at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008)
at android.app.Activity.performCreate(Activity.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:114)
at org.robolectric.util.ActivityController.create(ActivityController.java:126)
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
... 7 more
Caused by: android.view.InflateException: XML file ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug/layout/actionbar.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ProgressBar
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at net.frontlinesms.android.ui.view.ActionBar.<init>(ActionBar.java:65)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272)
at android.app.Activity.setContentView(Activity.java)
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70)
at android.app.Activity.performCreate(Activity.java:5008)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:114)
at org.robolectric.util.ActivityController.create(ActivityController.java:126)
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
... 7 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at net.frontlinesms.android.ui.view.ActionBar.<init>(ActionBar.java:65)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:352)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:272)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:455)
at android.app.Activity.setContentView(Activity.java)
at net.frontlinesms.android.activity.KeywordList.onCreate(KeywordList.java:70)
at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008)
at android.app.Activity.performCreate(Activity.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:114)
at org.robolectric.util.ActivityController.create(ActivityController.java:126)
at net.frontlinesms.android.BasicTest.setUp(BasicTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
... 7 more
Caused by: java.lang.ClassCastException: org.robolectric.res.AttrData cannot be cast to org.robolectric.res.StyleData
at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getParent(ShadowAssetManager.java:353)
at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getAttrValue(ShadowAssetManager.java:336)
at org.robolectric.shadows.ShadowResources.findAttributeValue(ShadowResources.java:259)
at org.robolectric.shadows.ShadowResources.attrsToTypedArray(ShadowResources.java:188)
at org.robolectric.shadows.ShadowResources.access$000(ShadowResources.java:51)
at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:460)
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java)
at android.content.Context.obtainStyledAttributes(Context.java:374)
at android.view.View.__constructor__(View.java:3297)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.shadows.ShadowView.__constructor__(ShadowView.java:68)
at android.view.View.<init>(View.java:3295)
at android.widget.ProgressBar.<init>(ProgressBar.java:253)
at android.widget.ProgressBar.<init>(ProgressBar.java:246)
at android.widget.ProgressBar.<init>(ProgressBar.java:242)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at net.frontlinesms.android.ui.view.ActionBar.<init>(ActionBar.java:65)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:82)
[truncated, hit stack overflow character limit...]
6 个解决方案
#1
6
I finally found the right place to put it. First, the structure of my application is shown as below:
我终于找到合适的地方放了。首先,我的申请结构如下:
my application is under
我的应用程序
app/src/main/
my test application is under
我的考试申请在下面
app/src/test/
You should name the property file as robolectric.properties and put it under
您应该将属性文件命名为robolectric。属性并放到下面
src/test/resources/
The content of robolectric.properties is
robolectric的内容。属性是
manifest: src/main/AndroidManifest.xml
Then, the test program can finally locate the property file!
然后,测试程序最终找到属性文件!
#2
3
The src/test/resources
path as mentioned on the Robolectric blog seems to work for the org.robolectric.Config.properties
file with the test plugin and Robolectric SNAPSHOTS. The RobolectricGradleTestRunner
is no longer required.
在Robolectric博客中提到的src/test/resources路径似乎可以用于org.robolectric.Config。带有测试插件和Robolectric快照的属性文件。不再需要robolectricletestrunner。
#3
1
I am using the robolectric gradle plugin and I faced (or am still facing ;) serious problems with junit testing in AS.
我正在使用robectric gradle插件,并且我在AS中遇到(或者还在面临;)junit测试的严重问题。
However, once thing that I just found out is the location of the org.robolectric.Config.properties
. I too tried many places in the source project, but AS only started picking it up after I put it into build/test-classes
.
但是,我刚刚发现的东西是org.robolectric.Config.properties的位置。我在源项目中也尝试了很多地方,但只是在我将它放入构建/测试类之后才开始使用它。
You can have a look at my gradle build script at: Debug gradle-based unit tests with IntelliJ / AndroidStudio
您可以查看我的gradle构建脚本:使用IntelliJ / AndroidStudio调试基于级别的单元测试
Other steps necessary to get it unit tests running in AS:
使it单元测试运行的其他步骤如下:
-
Reorder the
<orderEntry type="jdk" ... />
to the end of the list in your<app>.iml
file (this is to prevent the Stub!! exceptions, see: https://github.com/robolectric/deckard-gradle) - this step must be repeated, each time you sync with gradle.重新排序
到你的 中的列表末尾。iml文件(这是为了防止存根!!例外,参见:https://github.com/robolectric/deckard-gradle) -这个步骤必须重复,每次与gradle同步。 -
Add the compiled test files folder to your
<app>.iml
file. Add<output-test url="file://$MODULE_DIR$/build/test-classes" />
directly after<output url=... />
(see: Android Studio + Robolectric + Gradle Class Not Found Exception )将编译后的测试文件文件夹添加到您的
。安恩科技文件。将 直接添加到 -
Compile you app with gradle:
gradlew app:clean app:testDebug
or something like that. I noticed that AS does compile only the source files, but somehow does not compile the test classes, at least not anywhere into the/build
folder. Gradle on the other hand properly compiles your test classes to/build/test-classes
and with the configuration in step 2) AS will also pick them up, once compiled. Of course this step has to be repeated, each time you modify your test classes. (Note: I also found another solution from Eugen, see: https://*.com/a/24140796/1406325 - i haven't tried that one yet, but it seems doing so does not require the extra step to compile with gradle)用gradle: gradlew app:clean app:testDebug或者类似的软件来编译你的app。我注意到,AS只编译源文件,但不编译测试类,至少不会编译到/build文件夹中的任何地方。另一方面,Gradle可以将你的测试类正确地编译成/构建/测试类,并使用步骤2中的配置。当然,在每次修改测试类时,都必须重复这个步骤。(注意:我还从Eugen找到了另一个解决方案,参见:https://*.com/a/24140796/1406325——我还没有尝试过这个方案,但似乎这样做并不需要额外的步骤来编译gradle)
-
Put your
org.robolectric.Config.properties
into/build/test-classes
(since with step 2) AS will pick it up now.把你的org.robolectric.Config。属性进入/构建/测试类(从第2步开始)。
-
If you also have references to other libraries, you might be in a need of a
project.properties
file (that is if you are facingResources$NotFoundException
problems when running your tests). Again, where to put this file? It goes into<app>/src/main
(See: https://groups.google.com/forum/#!topic/robolectric/gjpwqRICT5U)如果您也有对其他库的引用,您可能需要一个项目。属性文件(即如果在运行测试时遇到了资源$NotFoundException)。再说一遍,把这个文件放在哪里?它进入
/src/main(参见:https://groups.google.com/forum/#!topic/robolectric/gjpwqRICT5U) android.library.reference.1=../../../library/src/main
Hope that helps!
希望会有帮助!
#4
1
I had luck putting org.robolectric.Config.properties
in src/test/res
, but not src/test/resources
.
我很幸运地输入了org.robolectric.Config。src/test/res中的属性,而不是src/test/resources中的属性。
#5
1
Best way is to override getConfigProperties() in a subclass of RobolectricTestRunner by putting the property file in a folder and specifying the path as follows:
最好的方法是在RobolectricTestRunner的子类中重写getConfigProperties(),方法是将属性文件放在文件夹中并指定如下路径:
@Override
protected Properties getConfigProperties() {
FsFile fs = Fs.currentDirectory();
InputStream resourceAsStream = null;
try {
File f = new File(fs.getPath() + <location-to-file-from-root-dir> + <file-name>);
resourceAsStream = new FileInputStream(f);
} catch (Exception e) {
resourceAsStream = null;
}
if (resourceAsStream == null) return null;
Properties properties = new Properties();
try {
properties.load(resourceAsStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
return properties;
}
#6
0
I see that you're following this: https://github.com/square/gradle-android-test-plugin
我看到您正在遵循以下内容:https://github.com/square/gradle android-test-plugin
I think you should modify your @RunWith(RobolectricTestRunner.class)
to the @RunWith(RobolectricGradleTestRunner.class)
我认为您应该将您的@RunWith(robolectrictestr. class)修改为@RunWith(robolectricletestr. class)
#1
6
I finally found the right place to put it. First, the structure of my application is shown as below:
我终于找到合适的地方放了。首先,我的申请结构如下:
my application is under
我的应用程序
app/src/main/
my test application is under
我的考试申请在下面
app/src/test/
You should name the property file as robolectric.properties and put it under
您应该将属性文件命名为robolectric。属性并放到下面
src/test/resources/
The content of robolectric.properties is
robolectric的内容。属性是
manifest: src/main/AndroidManifest.xml
Then, the test program can finally locate the property file!
然后,测试程序最终找到属性文件!
#2
3
The src/test/resources
path as mentioned on the Robolectric blog seems to work for the org.robolectric.Config.properties
file with the test plugin and Robolectric SNAPSHOTS. The RobolectricGradleTestRunner
is no longer required.
在Robolectric博客中提到的src/test/resources路径似乎可以用于org.robolectric.Config。带有测试插件和Robolectric快照的属性文件。不再需要robolectricletestrunner。
#3
1
I am using the robolectric gradle plugin and I faced (or am still facing ;) serious problems with junit testing in AS.
我正在使用robectric gradle插件,并且我在AS中遇到(或者还在面临;)junit测试的严重问题。
However, once thing that I just found out is the location of the org.robolectric.Config.properties
. I too tried many places in the source project, but AS only started picking it up after I put it into build/test-classes
.
但是,我刚刚发现的东西是org.robolectric.Config.properties的位置。我在源项目中也尝试了很多地方,但只是在我将它放入构建/测试类之后才开始使用它。
You can have a look at my gradle build script at: Debug gradle-based unit tests with IntelliJ / AndroidStudio
您可以查看我的gradle构建脚本:使用IntelliJ / AndroidStudio调试基于级别的单元测试
Other steps necessary to get it unit tests running in AS:
使it单元测试运行的其他步骤如下:
-
Reorder the
<orderEntry type="jdk" ... />
to the end of the list in your<app>.iml
file (this is to prevent the Stub!! exceptions, see: https://github.com/robolectric/deckard-gradle) - this step must be repeated, each time you sync with gradle.重新排序
到你的 中的列表末尾。iml文件(这是为了防止存根!!例外,参见:https://github.com/robolectric/deckard-gradle) -这个步骤必须重复,每次与gradle同步。 -
Add the compiled test files folder to your
<app>.iml
file. Add<output-test url="file://$MODULE_DIR$/build/test-classes" />
directly after<output url=... />
(see: Android Studio + Robolectric + Gradle Class Not Found Exception )将编译后的测试文件文件夹添加到您的
。安恩科技文件。将 直接添加到 -
Compile you app with gradle:
gradlew app:clean app:testDebug
or something like that. I noticed that AS does compile only the source files, but somehow does not compile the test classes, at least not anywhere into the/build
folder. Gradle on the other hand properly compiles your test classes to/build/test-classes
and with the configuration in step 2) AS will also pick them up, once compiled. Of course this step has to be repeated, each time you modify your test classes. (Note: I also found another solution from Eugen, see: https://*.com/a/24140796/1406325 - i haven't tried that one yet, but it seems doing so does not require the extra step to compile with gradle)用gradle: gradlew app:clean app:testDebug或者类似的软件来编译你的app。我注意到,AS只编译源文件,但不编译测试类,至少不会编译到/build文件夹中的任何地方。另一方面,Gradle可以将你的测试类正确地编译成/构建/测试类,并使用步骤2中的配置。当然,在每次修改测试类时,都必须重复这个步骤。(注意:我还从Eugen找到了另一个解决方案,参见:https://*.com/a/24140796/1406325——我还没有尝试过这个方案,但似乎这样做并不需要额外的步骤来编译gradle)
-
Put your
org.robolectric.Config.properties
into/build/test-classes
(since with step 2) AS will pick it up now.把你的org.robolectric.Config。属性进入/构建/测试类(从第2步开始)。
-
If you also have references to other libraries, you might be in a need of a
project.properties
file (that is if you are facingResources$NotFoundException
problems when running your tests). Again, where to put this file? It goes into<app>/src/main
(See: https://groups.google.com/forum/#!topic/robolectric/gjpwqRICT5U)如果您也有对其他库的引用,您可能需要一个项目。属性文件(即如果在运行测试时遇到了资源$NotFoundException)。再说一遍,把这个文件放在哪里?它进入
/src/main(参见:https://groups.google.com/forum/#!topic/robolectric/gjpwqRICT5U) android.library.reference.1=../../../library/src/main
Hope that helps!
希望会有帮助!
#4
1
I had luck putting org.robolectric.Config.properties
in src/test/res
, but not src/test/resources
.
我很幸运地输入了org.robolectric.Config。src/test/res中的属性,而不是src/test/resources中的属性。
#5
1
Best way is to override getConfigProperties() in a subclass of RobolectricTestRunner by putting the property file in a folder and specifying the path as follows:
最好的方法是在RobolectricTestRunner的子类中重写getConfigProperties(),方法是将属性文件放在文件夹中并指定如下路径:
@Override
protected Properties getConfigProperties() {
FsFile fs = Fs.currentDirectory();
InputStream resourceAsStream = null;
try {
File f = new File(fs.getPath() + <location-to-file-from-root-dir> + <file-name>);
resourceAsStream = new FileInputStream(f);
} catch (Exception e) {
resourceAsStream = null;
}
if (resourceAsStream == null) return null;
Properties properties = new Properties();
try {
properties.load(resourceAsStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
return properties;
}
#6
0
I see that you're following this: https://github.com/square/gradle-android-test-plugin
我看到您正在遵循以下内容:https://github.com/square/gradle android-test-plugin
I think you should modify your @RunWith(RobolectricTestRunner.class)
to the @RunWith(RobolectricGradleTestRunner.class)
我认为您应该将您的@RunWith(robolectrictestr. class)修改为@RunWith(robolectricletestr. class)