使用Robolectric进行Android单元测试会导致错误AndroidManifest.xml未找到或不是文件

时间:2012-09-12 23:31:03

标签: android junit robolectric

我正在尝试使用Robolectric在Eclipse中的App上运行测试用例,如this blog中所述,但是当我运行JUnit测试时,我收到以下错误

java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\abc\workspace\SumTestCases\AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
    at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:269)
    at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:229)
    at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:177)
    at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:157)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    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)
Caused by: java.io.FileNotFoundException: C:\Users\abc\workspace\SumTestCases\AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
    at com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:256)
    ... 17 more

我哪里错了?

1 个答案:

答案 0 :(得分:2)

您有两种选择:

  1. 您应该在放置AndroidManifest.xml的文件夹中运行JUnit
  2. You could extend RobolectricTestRunner and call parent constructor with path to the AndroidManifest.xml