Separating integration tests from unit tests in Android Studio

后端 未结 2 1011
陌清茗
陌清茗 2021-02-13 23:16

I\'m trying to separate out integration tests in Android Studio 0.9.

I have added the following to the build file:

sourceSets {
    integrationTest {
            


        
2条回答
  •  半阙折子戏
    2021-02-13 23:37

    @sm4's answer works indeed for a Java module (with apply plugin: 'java'), but unfortunately not for Android application (apply plugin: 'com.android.application') nor Android library modules (apply plugin: com.android.library).

    But I have found a workaround:
    Create the folders for your integration tests:

    src/integrationTest/java
    src/integrationTest/res
    

    Add the sourceSets for your new folders:

    sourceSets {
        integrationTest {
            java {
                srcDir file('src/integrationTest/java')
            }
            res {
                srcDir file('src/integrationTest/res')
            }
        }
    }
    

    In a pure Java module the java folder would now turn green and the res folder icon would change. In an Android application/library module it does not.

    Now create a product flavor identically named as the folder configured in the sourceSet, and it works!

    productFlavors {
        integrationTest {
        }
    }
    

    And to put a cherry on top:

    configurations {
        integrationTestCompile.extendsFrom testCompile
    }
    

提交回复
热议问题