What's the difference between src/androidtest and src/test folders?

src/androidTest is for unit tests that involves android instrumentation.

src/test is for pure unit test that do not involve android framework. You can run tests here without running on a real device or on emulator.

You can use both folders. Use the first one to test code that use Android framework. Use the second one to test code that are pure java classes. The methods to write tests are almost the same.

More info here : http://developer.android.com/tools/testing/testing_android.html


Great source of information relating to android testing in general is developers page Best Practices for Testing:

  • Local unit tests (/src/test/java/)

Unit tests that run locally on the Java Virtual Machine (JVM). Use these tests to minimize execution time when your tests have no Android framework dependencies or when you can mock the Android framework dependencies.

  • Instrumented tests (/src/androidTest/java/)

Unit tests that run on an Android device or emulator. These tests have access to Instrumentation information, such as the Context of the app you are testing. Use these tests when your tests have Android dependencies that mock objects cannot satisfy.

https://developer.android.com/training/testing/start/index.html