Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

android - Robolectric 2.1 and Eclipse

Robolectric seems to be a very interessting alternative android application testing, but I can't properly integrate it with my Eclipse enviroment.

Using the latest robolectric version 2.1 and android sdk 8, I follow the Eclipse setup steps described on the robolectric website but with no luck. When I run my newly created run configuration, the test is stopped the following error.

I don't know exactly why my pakpak .R class cant be found and what is the ro.build.date.utc? a symptom or the problem?

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I kinda solved my issue, where I can at least run my tests to a point which makes some sense to me. In Robolectric 2.0 they allow you to specify the path to your AndroidManifest file by creating a Config.properties file in your test project.

Try these two steps and see if they work for you:

  1. Create a nodescript file (File > New > File) called 'org.robolectric.Config.properties' at your test's src directory.
  2. In the org.robolectric.Config.properties file add the line

    manifest:[relative path your AndroidManifest.xml]

I had to mess with the relative path a bit (kept adding/removing ../'s), but this got it to correctly find my AndroidManifest file.

You can find more info at this github issue or their configuring robolectric blog post. Both of which I found to not be straight forward enough.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...