0

I currently have various AndroidTestCases which use Mockito and the module dexmaker-mockito. I am now trying to add Robolectric test cases using the robolectric plugin. I have everything running fine except that when I try to mock methods with no arguements I get an IllegalArgumentException from Dexmaker. Removing the dexmaker-mockito dependency and using mockito version 1.9.0 instead of 1.9.5 causes the error to go away but causes all of my AndroidTestCases to fail. Is there anyway in gradle to have dexmaker-mockito exclude from my robolectric test cases? Or does anyone know of any other way to run both android unit test and robolectric unit test from android studio?

Error: java.lang.IllegalArgumentException at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke

Update

I tried gradle-android-test-plugin and robolectric-gradle-plugin but was unable to to get rid of the IllegalArguementException without changing the version of mockitio to 1.9.0 and removing dexmaker, dexmaker-mockito from my dependencies.

I tried the guide but was unable to get Android Studio to recognize my source directories without adding them to main or test source sets which break my build because robolectric is not compiled for those gradle tasks and I do not want it to be.

I ended up following the guide here this time the error disappeared when I ran the tests from command line but persisted when running from android studio which I found odd. Again changing the version of mockitio to 1.9.0 and removing dexmaker, dexmaker-mockito from my dependencies in my Android App removed the error. For now I will settle for not being able to run the unit tests from android studio until I find a better answer.

madlymad
  • 6,367
  • 6
  • 37
  • 68
TravisW
  • 25
  • 5
  • 1
    where is the code??????? – Pragnesh Ghoda シ Sep 23 '14 at 05:36
  • My code is a bit complicated given the example I will try write up a simple app sometime and post it. – TravisW Sep 25 '14 at 05:14
  • did you find a solution? I have the exact same problem right now. – Christoph Feb 15 '15 at 20:51
  • Well I tried again a few weeks ago and had more success with the https://github.com/JCAndKSolutions/android-unit-test plugin. There is also the android unit test plugin for android studio which resolved alot of my other problems. However, it still ended up being unusable for me. Another option is to try the built in unit test in the beta version of android studio listed here http://tools.android.com/tech-docs/unit-testing-support. I haven't had the time try it out. – TravisW Feb 17 '15 at 22:39

1 Answers1

0

If I understand correctly what dexmaker-mockito is supposed to do, it's meant to be used with Android Unit Tests that run on device, so it's good for your Android Test Cases.

Robolectric tests run on the JVM and should be run as JUnit test, not Android tests. They should not be using dexmaker-mockito as they never get deployed to device, they can just use the normal Mockito libraries, with scope set to test.

I think you may not be able to mix the two, you may have two keep your robo tests separate from your Android unit tests.

Alex Florescu
  • 5,096
  • 1
  • 28
  • 49
  • So the only solution would be to have the test cases in separate modules? This causes the Robolectric plugin to fail. – TravisW Sep 23 '14 at 18:06
  • It will be a lot easier for people to help you out if you update the question describing exactly what it is you have tried and what errors you have encountered, as you try out different solutions. – Alex Florescu Sep 24 '14 at 12:01
  • Sorry I went ahead and added what I tried and changed the question to more accurately reflect my issue. – TravisW Sep 25 '14 at 05:18