Search code examples
androidintegration-testingandroid-espressospoon

Using Gradle Spoon Plugin to launch tests in specific location


I am having problem to find documentation how could I solve that case.

I am capable of launching small/medium/large tests with:

./gradlew spoonSmall
./gradlew spoonMedium
./gradlew spoonLarge

Or launching specific tests with usage of this setup:

spoon {
    (...)

    if (project.hasProperty('spoonClassName')) {
        className = project.spoonClassName

        if (project.hasProperty('spoonMethodName')) {
            methodName = project.spoonMethodName
        }
    }
}

I can launch specific file:

./gradlew spoon -PspoonClassName=com.package.tests.MyTest;

What I am interested in is a possibility to launch all tests located in:

./gradlew spoon -PspoonClassName=com.package.tests

package. Either method is fine. Some parameter to bash console or maybe way to create my own annotation and launch by something like ./gradlew spoonMyTests.

I am grateful for suggestions/help.


Solution

  • From the official docs:

    There are numerous ways to run a specific test, or set of tests. You can use the Spoon --size, --class-name or --method-name options, or you can use the --e option to pass arguments to the instrumentation runner, e.g.

    --e package=com.mypackage.unit_tests

    The following command should work when executing Spoon directly from command line (not from the gradle task)

    java -jar spoon-runner-1.1.9-jar-with-dependencies.jar \
        --apk ExampleApp-debug.apk \
        --test-apk ExampleApp-debug-androidTest-unaligned.apk \
        --e package=com.package.tests
    

    You need to find a way to pass this extra param to the Spoon gradle plugin.

    UPDATE

    From the official doc of Spoon Gradle plugin:

    Custom instrumentation arguments

    Use the instrumentationArgs property on spoon extension to pass custom parameters to your tests:

    spoon { instrumentationArgs = ["foo=bar", "name=value"] }

    In your case, this should look like the following:

    spoon {   
        instrumentationArgs = ["package=com.package.tests"] 
    }