INSTRUMENTATION_RESULT: shortMsg=java.lang.NoClassDefFoundError running Android Instrumentation tests

穿精又带淫゛_ 提交于 2020-01-01 06:30:23

问题


This error happens when I try and run my Android Instrumentation tests on a new 4.4 device, when they have always worked in the past

[echo] Running tests...
[echo] Running tests ...
[exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.NoClassDefFoundError
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.NoClassDefFoundError: org.mockito.internal.runners.RunnerImpl
[exec] INSTRUMENTATION_CODE: 0

回答1:


I posted that question to help others avoid wasting time stupidly like I have done!

The problem was that when I upgraded my Nexus 4 to Android 4.4 Kitkat, I decided to play around by activating the new Android RunTime (ART) in the Developer's Options settings menu.

That is the result!

To run your instrumentation tests, switch back to Dalvik!

I'm using Mockito, Dexmaker and Dexmaker-Mockito all to run Instrumentation tests with Mockito and use Emma to get coverage data.

No doubt some updating or change of approach will be needed in the future to test on Dalvik and/or ART.




回答2:


Using "*" like @tmuget suggested, doesn't work from the command line, but as suggested but the Japanese blog post, it looks like setting any specification on tests to run works around the NoClassDefFound issue. If you package is com.$somthing you can use:

adb shell am instrument -w -r  -e debug false -e package com

Some related issues to watch:

Mockito Github

L preview tracker

Dexmaker issue

Use article ( in Japanese )




回答3:


I found a workaround when running ART: use the option -e package * of the testrunner.

This will correctly run all your tests, and it works with Mockito, Dexmaker and Dexmaker-Mockito.

Here's an example when running via Ant:

<run-tests-helper emma.enabled="true">
    <extra-instrument-args>
        <arg value="-e" />
            <arg value="coverageFile" />
            <arg value="${emma.dump.file}" />
        <arg value="-e" />
            <arg value="package" />
            <arg value="*" />
    </extra-instrument-args>
</run-tests-helper>


来源:https://stackoverflow.com/questions/20514588/instrumentation-result-shortmsg-java-lang-noclassdeffounderror-running-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!