2013-05-20 30 views
5

Robolectric có vẻ là một thử nghiệm ứng dụng android thay thế rất interststing, nhưng tôi không thể tích hợp nó một cách hợp lý với môi trường Eclipse của tôi.Robolectric 2.1 và Eclipse

Sử dụng phiên bản robolectric mới nhất 2.1 và android sdk 8, tôi làm theo các bước thiết lập Eclipse được mô tả trên trang web robolectric nhưng không có may mắn. Khi tôi chạy cấu hình chạy mới được tạo của tôi, kiểm tra được dừng lại sau lỗi.

Tôi không biết chính xác lý do tại sao lớp pakpak .R của tôi không thể tìm thấy và ro.build.date.utc là gì? một triệu chứng hay vấn đề?

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 
+1

Tại sao bạn không thử dùng Robotium? –

+1

Tôi đã xem xét Robotium và dường như tôi vẫn yêu cầu thiết bị hoặc trình giả lập để chạy thử nghiệm. Trái với điều này, cách tiếp cận của Robolectric chạy các thử nghiệm của bạn trên JVM với tốc độ nhanh hơn nhiều. –

+0

Tôi gặp sự cố chính xác này. Tôi sẽ đăng nếu tôi tìm thấy bất cứ điều gì. – Gowiem

Trả lời

6

Tôi đã giải quyết được vấn đề của mình, ở đó ít nhất tôi có thể chạy thử nghiệm ở một điểm có ý nghĩa với tôi. Trong Robolectric 2.0, chúng cho phép bạn chỉ định đường dẫn đến tệp AndroidManifest của bạn bằng cách tạo tệp Config.properties trong dự án thử nghiệm của bạn.

Hãy thử hai bước và xem họ làm việc cho bạn:

  1. Tạo một file nodescript (File> New> File) được gọi là 'org.robolectric.Config.properties' tại thư mục src của thử nghiệm.
  2. Trong org.robolectric.Config.properties nộp thêm dòng

    manifest: [đường dẫn tương đối của bạn AndroidManifest.xml]

tôi phải gây rối với đường dẫn tương đối một chút (giữ thêm/gỡ bỏ ../'s), nhưng điều này đã nhận được nó để tìm tập tin AndroidManifest của tôi một cách chính xác.

Bạn có thể tìm thêm thông tin tại this github issue hoặc bài đăng trên blog configuring robolectric của họ. Cả hai thứ mà tôi thấy không đủ thẳng về phía trước.

Các vấn đề liên quan