Skip to content

Instantly share code, notes, and snippets.

@benvium
Created February 20, 2015 13:25
Show Gist options
  • Select an option

  • Save benvium/70b52809b87231052e7a to your computer and use it in GitHub Desktop.

Select an option

Save benvium/70b52809b87231052e7a to your computer and use it in GitHub Desktop.
How to set up Android Studio for Unit Testing. Works in version 1.0 and up.
In Android Studio 1.0 the scheme has changed a little bit.
The path to a unit test source file should be (app)/src/androidTest/java/com/mycompany/myapp/HelloWorldTest.java
Here's how I set up Unit Tests in a new Android Studio project:
- Open app in Android Studio.
- Set the Project explorer (left hand window) to display 'Project' mode. Tap the little drop-down at the top left and select 'Project'.
- Right click the 'src' directory, 'New -> Directory'.
- Call new directory androidTest
- Right click androidTest and add a 'java' directory. It will appear in green (indicating it's a test src directory).
- Now right-click again and add a package, e.g. com.mycompany.myapp.tests
- Add a new class that extends AndroidTestCase.
Now add a new configuration for testing:
- Edit Configurations
- Click + at top left
- Select Android Tests
- In General Tab select your main module.
- Hit OK
Now you can run the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment