Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio / Gradle test folder naming convention

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?

  • app
    • src
      • androidTest
        • java
      • main
        • java
        • res

versus

  • app
    • src
      • test
        • java
      • main
        • java
        • res

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 
}
like image 638
tir38 Avatar asked Aug 18 '14 15:08

tir38


People also ask

How do I run my tests with Android Gradle?

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.

What is the Android plugin for 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.

What are the test and connectedandroidtest tasks in Gradle?

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.

What is the Android Studio app folder?

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.


2 Answers

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

like image 125
Ryan R Avatar answered Nov 15 '22 11:11

Ryan R


In Android Studio the convention to follow for tests is to use androidTest. You can find more details documented on the Android Tools site.

like image 37
jonalmeida Avatar answered Nov 15 '22 10:11

jonalmeida