Android Studio / Gradle test folder naming convent

2019-04-28 13:33发布

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 
}

2条回答
孤傲高冷的网名
2楼-- · 2019-04-28 14:17

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

查看更多
相关推荐>>
3楼-- · 2019-04-28 14:21

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

查看更多
登录 后发表回答