【问题标题】:Robolectric 2.1 and EclipseRobolectric 2.1 和 Eclipse
【发布时间】:2013-05-20 08:57:32
【问题描述】:

Robolectric 似乎是一个非常有趣的替代 android 应用程序测试,但我无法将它与我的 Eclipse 环境正确集成。

使用最新的 robolectric 版本 2.1 和 android sdk 8,我按照 robolectric 网站上描述的 Eclipse 设置步骤进行操作,但没有成功。当我运行我新创建的运行配置时,测试因以下错误而停止。

我不知道为什么找不到我的 pakpak .R 类以及 ro.build.date.utc 是什么?是症状还是问题?

WARNING: no system properties value for ro.build.date.utc
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.googlecode.pakpak.android.R
    at org.robolectric.AndroidManifest.getRClass(AndroidManifest.java:102)
    at org.robolectric.AndroidManifest.getResourcePath(AndroidManifest.java:275)
    at org.robolectric.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:280)
    at org.robolectric.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:282)
    at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:590)
    at org.robolectric.RobolectricTestRunner.getAppResourceLoader(RobolectricTestRunner.java:582)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:66)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:392)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:232)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    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.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:181)
    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.lang.ClassNotFoundException: com.googlecode.pakpak.android.R
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:188)
    at org.robolectric.AndroidManifest.getRClass(AndroidManifest.java:100)
    ... 24 more

【问题讨论】:

  • 你为什么不试试 Robotium?
  • 我看过 Robotium,在我看来它仍然需要设备或模拟器来运行测试。与此相反,Robolectric 的方法以更快的速度在 JVM 上运行您的测试。
  • 我遇到了这个确切的问题。如果我发现任何东西,我会发布。

标签: android testing robolectric


【解决方案1】:

我有点解决了我的问题,我至少可以将我的测试运行到对我有意义的程度。在 Robolectric 2.0 中,它们允许您通过在测试项目中创建 Config.properties 文件来指定 AndroidManifest 文件的路径。

试试这两个步骤,看看它们是否适合你:

  1. 在测试的 src 目录中创建一个名为“org.robolectric.Config.properties”的节点脚本文件(文件 > 新建 > 文件)。
  2. 在 org.robolectric.Config.properties 文件中添加一行

    manifest:[你的AndroidManifest.xml的相对路径]

我不得不稍微弄乱相对路径(不断添加/删除 ../'s),但这让它正确地找到了我的 AndroidManifest 文件。

您可以在this github issue 或他们的configuring robolectric 博客文章中找到更多信息。我发现这两者都不够直截了当。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多