使用 Gradle Spoon 插件在特定位置启动测试

Using Gradle Spoon Plugin to launch tests in specific location

我在查找文档时遇到问题我该如何解决这个问题。

我有能力启动 small/medium/large 测试:

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

或使用此设置启动特定测试:

spoon {
    (...)

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

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

我可以启动特定文件:

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

我感兴趣的是启动位于以下位置的所有测试的可能性:

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

包。两种方法都可以。 bash 控制台的一些参数,或者创建我自己的注释并通过类似 ./gradlew spoonMyTests 启动的方法。

感谢suggestions/help。

来自官方文档:

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

当直接从命令行(而不是从 gradle 任务)执行 Spoon 时,以下命令应该有效

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

您需要找到一种方法将此额外参数传递给 Spoon gradle 插件。

更新

来自 Spoon Gradle 插件的 official doc:

Custom instrumentation arguments

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

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

在您的情况下,这应该如下所示:

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