Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit tests in Android Studio 0.8

BREAKING NEWS: Android Studio 1.1.0 now has built-in support for unit testing. See more here: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support

At first I know that there are very, very, very much similar questions (even here on SO). Most of them are terribly outdated so I'm asking a fresh new question which should be up to date for Android Studio 0.8.x.

I know there are some libraries which work somehow, but in almost each case I had no evidence that the information were up to date. I know there is e.g. roboelectric, there are also some deprecated Jake Wharton like gradle-android-test-plugin or double-espresso, I also found the library RoboSpock and Deckard. But none of them seems to have any Android Studio integration.

After long reseach I found this two bugs in all implementations:

  • The classpath is broken and needs to been hacked to get junit running
  • The junit tests cannot been debugged

What I'm looking for:

  • I want to automatically test an algorithm (which is plain java)
  • I want to check the integration in my Android app works
  • I want an integration in Android Studio so that I can jump into the code out of a stacktrace
  • I want to step thrue the test code

I found also somewhere a nice hack which run the tests in gradle as an external task and pushed the results into AS so that the results could been displayed, but unfortunately I cannot find that link again (and if I remember correctly it did also not work for me).

Do you guys have some fresh references? Does it work for you?

like image 476
rekire Avatar asked Jun 24 '14 07:06

rekire


2 Answers

You have to edit the .iml file that Android Studio generates to point to your test-classes directory and also to fix the Stub error from Junit. There is currently no work around for this.

Gradlectric is a sample that uses the Robolectric Gradle Plugin to run unit tests in Android Studio.

like image 66
Marco RS Avatar answered Sep 18 '22 12:09

Marco RS


Here you miss one example project setup https://github.com/nenick/android-gradle-template

But none of them seems to have any Android Studio integration.

This project is maintained for android studio

The classpath is broken and needs to been hacked to get junit running

gradle scripts will fix the classpath

The junit tests cannot been debugged

tests a running inside AS so they are easy to debug

like image 44
nenick Avatar answered Sep 16 '22 12:09

nenick