Unit tests in Android Studio 0.8

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

At first I know that there are very, very, very similar questions (even here on SO). Most of them are terribly outdated, so I ask a new new question, which should be relevant for Android Studio 0.8.x.

I know that there are some libraries that work somehow, but in almost every case I had no evidence that the information was up to date. I know that there is, for example, roboelectric , there are also some obsolete Jake Wharton, such as gradle-android-test-plugin or double-espresso , I also found RoboSpock and Deckard library . But none of them seem to have integration with Android Studio.

After a long repeated search, I found these two errors in all implementations:

  • The class path is broken and must be hacked to run junit
  • Junit tests cannot be 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.
  • I need integration in Android Studio so I can go to code from stacktrace
  • I want to execute test code

I also found a good hack that ran tests in gradle as an external task and pushed the results in AS so that the results could be displayed, but unfortunately I can not find this link again (and if I remember correctly this also did not work for me )

Do you guys have any fresh links? Does it work for you?

+7
android android-studio unit-testing
source share
4 answers

You need to edit the .iml file that Android Studio generates to point to your catalog of test classes, as well as fix the Junit Stub error. There is currently no work for this.

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

+2
source share

Here you will skip one sample project setup https://github.com/nenick/android-gradle-template

But none of them seem to have integration with Android Studio.

This project is supported for Android studio.

The class path is broken and must be hacked to run junit

gradle scripts will fix the class path

Junit tests cannot be debugged

checks operation inside AS, therefore it is easy to debug them

+1
source share

This my project does not cover all your requests, but there are quite a few of them. It covers the default Java test case, and some tests interact with views.

The root project uses Travis CI, which uses gradle connectedCheck to run tests. To be able to debug tests, you can simply create a test run configuration in AS and run it in debug mode.

Please note that this does not use any special Android frameworks such as robolectric.

0
source share

Here you can find the Jake Wharton gradle -android-test-plugin plug here . It is compatible with AS 0.6 and is regularly maintained by Robolectric. You can watch this project to configure Robolectric in Android Studio with this plugin. You can get a fair portion of the functionality you talked about with robolectric gradle-plugin. You can also successfully debug your test code with AS.

0
source share

All Articles