多次运行同一Gradle任务

时间:2018-12-23 18:31:17

标签: 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次)。

1 个答案:

答案 0 :(得分:1)

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

另一个类似问题的选择是,创建Test类的子类,该子类返回包含所有测试的多个副本的任务,其代码为https://stackoverflow.com/a/41650455/1686615

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