4 Shortcuts for running your tests in Android Studio

1. Add a run configuration for “All in directory”

If you want a quick and easy way to run all your unit tests you can add a JUnit run configuration in Android Studio for all tests in a directory. In this example we have selected the folder [PROJECT_ROOT]/app/src/test/java.

Another option is to choose “All in package” and specify the package name. This can lead to issues however if you have unit tests and Espresso tests in the same package.

2. Run all tests in a single class

Right click on a test class name in the editor (or a filename in the project explorer) to run all tests in a single class. The default keyboard shortcut for this is Ctrl+Shift+F10 on Linux. I suggest you map it to something easier to remember like Ctrl+Alt+R.

3. Run a single test method

You can also run a single test case by right clicking on the method or using the appropriate keyboard shortcut. This can save time when you are developing or debugging a new feature or test.

4. Rerun failed tests

Clicking the second icon from the top on the left side of the run panel will rerun only tests which failed in the previous run. This is by far my favorite and probably the shortcut I use most often (after run all in directory). I would recommend setting up a memorable keyboard shortcut for this one too. Maybe Alt+Shift+R?