开发者

How to do plain vanilla junit tests in android? Getting error when doing

I want to run plain junit test on java classes that do not use any android os related resources. However; when I try to run a junit test in eclipse I get the following error.

guarantee(_name_index != 0 && _signature_开发者_如何学运维index != 0) 
    failed: bad constant pool index for fieldDescriptor

Im using junit-4.8.2.jar as a library resource.

What am I doning wrong. I will eventually setup a separate test project to test the android resources.

Thanks


I resolved this issue by removing the existing JUnit run configuration, and using an Android JUnit run configuration instead.

Eclipse should ask you whether you want to use an Eclipse runner or Android runner when you try to run as a JUnit test. Choose the latter.


You cannot mix JUnit 4 and JUnit 3 (included in android) in the same project. For your tests to be meaningful you should test on Dalvik, otherwise incompatibilities with JavaSE may affect the accuracy. As a workaround you can create a separate project to test you independent classes.


I agree, when you just want to test methods outside of the android application as a whole (Which is very desirable) its foolish to use dalvik. Maybe just creating a seperate java project is the best options and importing the classes you want to test. That seems to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜