Skip to content Skip to sidebar Skip to footer

How To Use Espresso + Jmockit

I want to use Espresso and JMockito. But I don't run test. If you have resolve way, help me. I wrote some file(build.gradle(app, project), Test java) as follows. build.gradle(app)

Solution 1:

Short answer:

you cannot easily fix this, because JMockit has a faulty JUnit dependency. To fix it, you need to fix JMockit first.

Long answer:

Your app contains org.junit.runner.Runner twice:

  • through JMockit because it includes the Runner class file in the library (which is bad because it only includes the Runner class and not the whole library).
  • through com.android.support.test:runner because one of its dependencies is the junit library (which is the proper way to add JUnit support.

A normal fix would be to exclude one of the following:

  • exclude the JUnit dependency for JMockit: This doesn't work, because JUnit is not defined as a proper dependency. JUnit merely pasted in the class file in its own project. This is a bad thing to do.
  • exclude the JUnit dependency for com.android.support.test:runner: We can do this, but this will cut out all the other classes from the junit library that JMockit did not put in their project. This will effectively break any other junit code you use.

If you really NEED to use JMockit then you could consider to edit the project so it includes the junit dependency properly and then recompile it and add it to your project this way.

This shows the faulty dependency:

Android Studio screenshot

You can see how the Runner class is just pasted into the project.

After fixing the JMockit dependencies you need to add JMockit as follows:

androidTestCompile ('org.jmockit:jmockit:1.18') {
    exclude group: 'junit'
}

Post a Comment for "How To Use Espresso + Jmockit"