3

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

3 Answers 3

10

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 )

Comments

0

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>

1 Comment

Not sure if Ant is expanding "*" before it passes this to the instrument command, but -e package * on the command line will give you "TestGrouping﹕ Invalid Package: '*' could not be found or has no tests"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.