The task of a separate integration test on gradle using android

I want to run tests that have the word "integration" in a way that should be excluded in a standard test run, but I want to combine them all together in a separate task. I currently have a basic test configuration:

sourceSets { androidTest.setRoot('src/test') integrationTest.setRoot('src/test') } ... androidTestCompile 'junit:junit:4.11' androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1' androidTestCompile files('libs/android-junit-report-1.5.8.jar') androidTestCompile 'com.squareup:fest-android:1.0.8' androidTestCompile 'org.robolectric:robolectric:2.3' integrationTestCompile 'junit:junit:4.11' integrationTestCompile 'com.jayway.android.robotium:robotium-solo:5.1' integrationTestCompile files('libs/android-junit-report-1.5.8.jar') integrationTestCompile 'com.squareup:fest-android:1.0.8' integrationTestCompile 'org.robolectric:robolectric:2.3' ... androidTest { include '**/*Test.class' exclude '**/espresso/**/*.class' exclude '**/integration/**' } task integrationTest(type: Test) { include '**/integration/**' } 

This causes an error while synchronizing gradle in AS:

 Warning: project ':ProjectName': Unable to resolve all content root directories Details: java.lang.NullPointerException: null 

but if I remove the integrationTest task, this will not happen. Also with this task I can run the "integrationTest" task, but this causes another error:

 Error:Could not determine the dependencies of task ':ProjectName:integrationTest'. A base directory must be specified in the task or via a method argument! 
+5
source share
1 answer

This is not entirely obvious, but this error is caused by the fact that you do not define testClassesDir in your task definition.

 task integrationTest(type: Test) { include '**/integration/**' testClassesDir = file('build/intermediates/classes') } 

Something similar is described in the Gradle Java Plugin User Guide , but it is not fully translated into the Android plugin. I have not developed all the details yet, but I will update this answer when I find out.

+1
source

Source: https://habr.com/ru/post/1205678/