问题描述
我遇到了错误,当测试的apdater的getView。该测试code的(0)在测试案例调用View.setImageResource设置一个空的图像时,异常情况发生。
我跑测试robolectric-2.2-20130712.161723-17-JAR-与-dependencies.jar使用Eclipse。我试图取代ResouceLoader与ShadowResources.createFor(新的ResourceLoader(){...}。但亘古不变的工作。我取而代之ResouceLoader不叫。
有人知道如何解决呢?
android.content.res.Resources $ NotFoundException:未知的资源0
在org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)
在org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
在android.content.res.AssetManager.getResourceValue(AssetManager.java)
在android.content.res.Resources.getValue(Resources.java:1009)
在android.content.res.Resources.getDrawable(Resources.java:658)
在org.robolectric.shadows.ShadowView.buildDrawable(ShadowView.java:92)
在org.robolectric.shadows.ShadowImageView.setImageResource(ShadowImageView.java:38)
在android.widget.ImageView.setImageResource(ImageView.java)
在com.mobile.client.share.edentity.PhotostreamAdapter.getView(PhotostreamAdapter.java:54)
在com.mobile.client.share.edentity.PhotostreamAdapterTest.testGetView(PhotostreamAdapterTest.java:163)
在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:47)
在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
在org.robolectric.RobolectricTestRunner $ 2.evaluate(RobolectricTestRunner.java:241)
在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238)
在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)
在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)
在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)
在org.robolectric.RobolectricTestRunner $ 1.evaluate(RobolectricTestRunner.java:177)
在org.junit.runners.ParentRunner.run(ParentRunner.java:309)
在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
在我的Apdater ContentDetailsAdapter我roboletric的单元测试的另一个类似的问题是陈述mContext.getResources()的getString(R.string.delete_hint_title)。该mContext由Robolectric.getShadowApplication()创建的。getApplicationContext()。是不是有什么毛病我的配置有关Roboletric?我能够调用ProgressDialog.show(mContext,,)在我的单元测试。看来问题是始终与资源。下面是堆栈:
android.content.res.Resources $ NotFoundException:字符串资源ID#0x7f07004f
在android.content.res.Resources.getText(Resources.java:229)
在android.content.res.Resources.getString(Resources.java:313)
在com.mobile.client.share.edentity.ContentDetailsAdapter.checkDeletedSelection(ContentDetailsAdapter.java:220)
在com.mobile.client.share.edentity.ContentDetailsAdapter.getCheckedItems(ContentDetailsAdapter.java:178)
在com.mobile.client.share.edentity.SetsAdapterTest.testGetCheckedItems(SetsAdapterTest.java:361)
在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:47)
在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
在org.robolectric.RobolectricTestRunner $ 2.evaluate(RobolectricTestRunner.java:241)
在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238)
在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)
在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)
在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)
在org.robolectric.RobolectricTestRunner $ 1.evaluate(RobolectricTestRunner.java:177)
在org.junit.runners.ParentRunner.run(ParentRunner.java:309)
在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
我有一个类似的错误,以你的第二个问题。我的环境是建立按照 http://www.youtube.com/watch?v=3mjcg5gfDLE
提供的样品在我的Eclipse的作品,但是当我试图链接MyProjectTest我自己的应用程序,第二个错误您所描述出现了。
该视频描述了解决方案,在6:00。
MyProjectTest - >运行方式配置 - >的JUnit - > MyProjectTestConfiguration - >参数 - >点击其他单选按钮 - >工作空间 - >选择
该带回家的是:如果你运行你的robolectric测试不同的应用程序,你必须点'工作Direcotry'给它。此外,您需要从MyProjectTest链接测试文件夹到一个新的测试文件夹中。
I met the error when test getView of an apdater. The tested code was calling View.setImageResource(0) during the test case to set an empty image when the exception happen.
I ran test robolectric-2.2-20130712.161723-17-jar-with-dependencies.jar with Eclipse. I tried the replace the ResouceLoader with ShadowResources.createFor(new ResourceLoader() {...}. But it doesnot work. My replaced ResouceLoader was not called.
Anybody know how to solve it?
android.content.res.Resources$NotFoundException: unknown resource 0
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)
at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
at android.content.res.AssetManager.getResourceValue(AssetManager.java)
at android.content.res.Resources.getValue(Resources.java:1009)
at android.content.res.Resources.getDrawable(Resources.java:658)
at org.robolectric.shadows.ShadowView.buildDrawable(ShadowView.java:92)
at org.robolectric.shadows.ShadowImageView.setImageResource(ShadowImageView.java:38)
at android.widget.ImageView.setImageResource(ImageView.java)
at com.mobile.client.share.edentity.PhotostreamAdapter.getView(PhotostreamAdapter.java:54)
at com.mobile.client.share.edentity.PhotostreamAdapterTest.testGetView(PhotostreamAdapterTest.java:163)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
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.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)
Another similar problem in my roboletric unit test on my Apdater ContentDetailsAdapter is from statement mContext.getResources().getString(R.string.delete_hint_title). The mContext is created by Robolectric.getShadowApplication().getApplicationContext(). Is there something wrong with my config about Roboletric? I was able to call ProgressDialog.show(mContext, "", "") in my unit test. It seems the problem is always with resource. Here is the stack:
android.content.res.Resources$NotFoundException: String resource ID #0x7f07004f
at android.content.res.Resources.getText(Resources.java:229)
at android.content.res.Resources.getString(Resources.java:313)
at com.mobile.client.share.edentity.ContentDetailsAdapter.checkDeletedSelection(ContentDetailsAdapter.java:220)
at com.mobile.client.share.edentity.ContentDetailsAdapter.getCheckedItems(ContentDetailsAdapter.java:178)
at com.mobile.client.share.edentity.SetsAdapterTest.testGetCheckedItems(SetsAdapterTest.java:361)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
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.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)
I had a similar error to your 2nd issue. My environment was set up according to http://www.youtube.com/watch?v=3mjcg5gfDLE
The sample provided works on my Eclipse, but when I tried to link MyProjectTest to my own app, the second error you described appeared.
The video describes the solution at 6:00.
MyProjectTest -> Run As Configuration -> JUnit -> MyProjectTestConfiguration -> Arguments -> Click 'Other' radio button -> Workspace -> select
The take home is: if you run your robolectric tests for a different app, you must point the 'Working Direcotry' to it. Additionally, you need to link your test folder from MyProjectTest to a new test folder in .
这篇关于Robolectric:NotFoundException:未知的资源0在org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!