java - 多次运行同一个 Gradle 任务

标签 java testing gradle junit

所以我有一个运行我所有测试的 gradle 测试任务。我如何设置 gradle 来运行这个任务 100 次?它可以运行并运行我所有的测试,我只需要一个选项来选择运行多少次。

build.gradle中的任务:

test {
    // enable JUnit Platform (a.k.a. JUnit 5) support
    useJUnitPlatform()

    // set a system property for the test JVM(s)
    systemProperty 'some.prop', 'value'

    // explicitly include or exclude tests
    include 'com/company/calculator/**'

    // show standard out and standard error of the test JVM(s) on the console
    testLogging.showStandardStreams = true

    // set heap size for the test JVM(s)
    minHeapSize = "128m"
    maxHeapSize = "512m"

    // set JVM arguments for the test JVM(s)
    jvmArgs '-XX:MaxPermSize=256m'

    // listen to events in the test execution lifecycle
    beforeTest { descriptor ->
        logger.lifecycle("Running test: " + descriptor)
    }

    // Fail the 'test' task on the first test failure
    failFast = true

    // listen to standard out and standard error of the test JVM(s)
    onOutput { descriptor, event ->
        logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
    }

用例是我想测试不同断言和模拟库的性能(我有多个分支,测试使用不同的库编写),为此我需要多次运行测试套件。

为了测试性能,我需要测量在每个库集上运行这些测试所花费的时间,例如 100 次(也许 1000 次)。

最佳答案

一个选项可能是这个 --rerun-tasks 标志。
gradle test --rerun-tasks
来自 the Gradle user guide .

另一个选项,来自类似的问题,是创建 Test 类的子类,它返回一个任务,其中包含所有测试的多个副本,代码在这里:https://stackoverflow.com/a/41650455/1686615 .

确实有很多方法可以在不同级别执行此操作,例如在该链接中使用 Gradle 代码,或者在 .gradle 文件中,将参数传递到测试代码中,或者在命令行中。也许可以详细说明您的用例,或者您是否希望在特定级别进行更改。

关于java - 多次运行同一个 Gradle 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53906138/

相关文章:

java - 如何将组合框对象转换为颜色对象

Java蛇眼程序错误

java - JAXB 2.0 - 如何跳过节点处理并将它们作为字符串返回

linux - 是否有任何工具可以检查交叉编译的 .so 文件中的符号?

Java Gradle 在一个任务中复制 2 个不同的文件夹

java - Freeswitch channel 异常

testing - 测试第一次失败是什么时候?

java - 为什么我的函数总是无法通过我的 JUnit 测试?

Gradle 作为非 root

gradle - 对gradle关闭的怀疑