In android studio in the new sub-project has, as I understand this integration tests that run on the device or emulator, checks the functionality of the application depends on the SDK android. But I do have methods do not depend on android. Their testing, I would like to spend on the JVM, avoiding run the emulator.
3 Answers
As of version 1.1.0 RC1 of Android Studio and the gradle plugin, you can run JUnit 4 unit tests on a JVM without the need of a device.
Take a look at this post
If you have the latest version of Android Studio (1.1 and above) you do not need to worry about using the correct gradle plugin; it is already done. You still need to set that you want to use the experimental unit testing feature in Settings > Gradle > Experimental.

- 13,083
- 4
- 39
- 53
-
Thanks. And how to run these tests from the command line (gradle)? – georgeci Mar 08 '15 at 18:32
-
1you would do `./gradlew test` – Emmanuel Mar 08 '15 at 19:01
I'm actually trying to change my projects with MVP and unit test everything instead of using Espresso for testing the project.
I have a project with 160 tests with espresso and some idling resources and it takes like 20-30 minutes to run, and it turns to be expensive to run tests on aws farm or test droid ($5/run/device), so maybe there´s a hope with MVP and unit tests.
Take a look here: http://tools.android.com/tech-docs/unit-testing-support
You can define a
app/src/test/java/<apk_package>/
folder and put all your JUnit 4 tests there and they will run without an emulatorAdd the dependency:
testCompile 'junit:junit:4.12'
Run tests :D

- 15,026
- 20
- 92
- 162
Just to add, it is important to put the junit test files in the app/src/test/java/[apk_package]/ folder, not the app/src/androidTest/java/[apk_package]/ folder! Putting it in the androidTest folder will force run the android emulator or device runner.

- 397
- 3
- 11