I have successfully create a Android project in IntelliJ 13 and I want to setup the Android Testing Framework. I used the new project wizard to create the android project using Gradle. When I go to add a new module I only have options for "Gradle: Android Module" and "Gradle: Java Library", the "Test Module" option is missing.
How do I generate an Android Test Module? I have read http://www.jetbrains.com/idea/webhelp/testing-android-applications.html but I can never find any "test" option.
If an Android Test Module can not be automatically generated, then how do I configure and use the Android Testing Framework with a Gradle Android Project? Links to examples or documentation is very much appreciated.
Details: IntelliJ 13.1.3
Create a new test class manuallyRight-click the test root folder or package in the test root folder in which you want to create a new test and select New | Java Class. Name the new class and press Enter . Press Alt+Insert and select Test Method to generate a new test method for this class.
Use the command ./gradlew test to run all tests.
Set up a module SDKFrom the main menu, select File | Project Structure | Project Settings | Modules. Select the module for which you want to set an SDK and click Dependencies. If the necessary SDK is already defined in IntelliJ IDEA, select it from the Module SDK list.
So currently your directory structure should look something like this:
ProjectDirectory/
res/
src/
main/
java/
your.package.name
MyClass.java
All you need to do is add a src directory for androidTest
:
ProjectDirectory/
res/
src/
main/
java/
your.package.name
MyClass.java
androidTest/
java/
your.package.name
MyClassTest.java
and then resync your Gradle file with your project, and it should be detected as a test directory. Then you can run the connectedCheck
or connectedAndroidTest
tasks (I'm unclear on the difference in the two) to run the tests.
If your directory structure differs from the above (if, for instance, you important an Eclipse-style project), you can specify the alternate src directory in your build.gradle script:
android {
sourceSets {
androidTest {
java.srcDirs = ['path/to/test/src']
}
}
}
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