I've seen a lot of tutorials and helper projects for doing testing on an Android Studio / Gradle project. I'm curious about the naming convention of the the test folder. I've seen two similar namings : test
and androidTest
. Is there any real difference? Is the IDE / Gradle framework treating these differently?
versus
EDIT:
@jonalmeida So if I read that documentation correctly, my build.gradle
file dependencies need to match the sourceSet, right?
dependencies {
// dependency injection
compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
// networking
compile 'com.squareup.retrofit:retrofit:1.6.1'
// testing
androidTestCompile 'org.easytesting:fest:1.0.16'
androidTestCompile 'junit:junit:4.+'
androidTestCompile 'org.robolectric:robolectric:2.3'
testCompile 'com.squareup:fest-android:1.0.8' // <---- this guy won't work
}
For more fine-grained control, you can also choose to run your tests through an Android Debug Bridge (adb) shell. The Android Gradle plugin lets you run tests from your Gradle project using the command line. The table below summarizes how to run your tests with Gradle: Table 1. Different ways to run your tests with Gradle.
The Android plugin for Gradle lets you run unit tests from your Gradle project via the command-line. For more information on how to build unit tests for your app, see Building Effective Unit Tests. The Android Plugin for Gradle lets you run unit tests from your Gradle project via the command-line.
These tasks run your local or instrumented tests, respectively, but additionally include other checks added by other Gradle plugins. The test and connectedAndroidTest tasks run tests on each module in your project.
When you create an application in Android Studio, you find that the project is divided into an App folder and Gradle scripts. The App folder contains three subfolders ( manifests, java and res) that make up your application.
Since Android Studio 1.1 you should put your Unit tests in /src/test
and Android Instrumentation Tests in /src/androidTest
See: http://tools.android.com/tech-docs/unit-testing-support#TOC-Setting-up-Android-Studio
For Android Studio 2.0 and beyond see: https://youtu.be/kL3MCQV2M2s?t=114
In Android Studio the convention to follow for tests is to use androidTest
. You can find more details documented on the Android Tools site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With