Home

Awesome

#[Deprecated] Google has finally released a proper solution for unit testing. Therefore this plugin will no longer be activlty maintained.

android-studio-unit-test-plugin

Android Studio (and Intellij 14) IDE support for Android gradle unit tests.

This plugin will mark test directories and resolve testCompile dependencies. It also sets up the correct system properties so that Robolectric will work if you are using it.

alt tag

Requirements

Install IDE the plugin

In Android Studio go to Settings -> Plugins -> Browse Repositories... and search for 'Android Studio Unit Test'.

If you feel like living on the edge, can download the zip then go to Settings -> Plugins -> Install plugin from disk.. to install.

Install the gradle plugin

To add unit testing support to your gradle project, you need JCAndKSolutions' android-unit-test gradle plugin. You need to set it up as described in the README. Make sure you have at least version 1.5.0.

Troubleshooting

If you are running Android Stuido 0.8.9+. The latest version of this plugin will compile your test classes before running the test. However, the very first time you run them after they have been cleaned, you will still get this error. Simply attempting to run again will fix it and any subsiquent runs will work correctly.

If you are running intellij or and older version of Android Studio. If your app includes a library project compile project(":myLib") then the JUnit test runner will attempt to run testClasses on that project. Since it doesn't have that task it will fail and your test classes will not be generated. To fix, add the needed task to your library project.

task testClasses {}