1

I am trying to run unit test on a separate task from the UI tests that I have within the integration tests in Android Studio, unfortunately I have to use

apply plugin: 'com.android.application'

in the build.gradle file so I cannot add the custom test tasks as far as I can tell. Since the UI tests are tagged as "@Test" and extend InstrumentationTestCase they get run whenever

gradle connectedCheck

is called which is not needed, instead I want one gradle command to run UI tests and one to run unit tests. I figured that I would be able to leverage tagging the UI tests as LargeTests but have not been able to complete a gradle task that can do this. I am not able to use the "test" task in the build.gradle since we are using the com.android.application plugin, and advice?

Thanks

  • I believe this will help. http://stackoverflow.com/questions/23046259/is-there-a-way-to-only-run-a-specific-set-of-tests-in-an-android-gradle-project – DeeV Jul 25 '16 at 16:36
  • even usingtestInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArgument 'notAnnotation', 'android.test.suitebuilder.annotation.LargeTest' when calling gradle cAT it attempts to run the classes tag with @LargeTest and fail with the exception "No runnable methods" and I can never call the large tests either – CroatianBlackhawk Jul 25 '16 at 17:27

2 Answers2

3

What ended up working for me is adding the

@LargeTest

using

import android.support.test.filters.LargeTest;

annotation to the tests I needed and then adding the following lines to the build.gradle

if(!project.hasProperty('android.testInstrumentationRunnerArguments.annotation')) {
        testInstrumentationRunnerArgument 'notAnnotation', 'android.support.test.filters.LargeTest'
    }

this way unless I specify in the command line to run the large tests they will,be ignored. To run the large tests use:

gradle cAT -Pandroid.testInstrumentationRunnerArguments.annotation=android.support.test.filters.LargeTest
3

You can do this from command-line without modifying the build.gradle file:

./gradlew cAT -Pandroid.testInstrumentationRunnerArguments.notAnnotation=android.test.suitebuilder.annotation.LargeTest
Kevin Brotcke
  • 3,765
  • 26
  • 34