0
爲什麼在嘗試運行帶代碼覆蓋率的測試項目時遇到IllegalAccessError?使用EMMA for Android應用程序運行單元測試時發生IllegalAccessError
運行ant時出現以下錯誤。
host:MyAppTest mach$ ant clean emma instrument install test
[...]
[echo] Running tests ...
[exec]
[exec] com.example.myapp.test.MyClassTest:.
[exec] Error in testMyMethod:
[exec] java.lang.ExceptionInInitializerError
[exec] at com.example.myapp.test.MyClassTest.testMyMethod(MyClassTest.java:10)
[exec] at java.lang.reflect.Method.invokeNative(Native Method)
[exec] at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
[exec] at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
[exec] at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
[exec] at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
[exec] Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
[exec] at com.example.myapp.MyClass.$VRi(MyClass.java)
[exec] at com.example.myapp.MyClass.<clinit>(MyClass.java)
[exec] ... 13 more
我有一個類在我的應用程序
public class MyClass {
public boolean myMethod(int i) {
return true;
}
}
而且在測試類我的測試應用程序
public class MyClassTest extends AndroidTestCase {
public void testMyMethod() {
MyClass a = new MyClass(); // <--- THIS MAKES THE TEST FAIL
// If I remove this line it runs
// successfully but does not test anything...
}
}
我已經創建了我的兩個螞蟻的build.xml以下參數
host:MyApp mach$ android update project --path $PWD --name MyApp --target android-16 --subprojects
host:MyAppTest mach$ android update test-project --main ../MyApp --path ./