Java 多次运行同一个Gradle任务
所以我有一个gradle测试任务,它运行我所有的测试。如何设置gradle以运行此任务100次?它工作并运行我所有的测试,我只需要一个选项来选择运行多少次 build.gradle中的任务:Java 多次运行同一个Gradle任务,java,testing,gradle,junit,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 '
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次)。一个选项可能是--重新运行任务标志。gradle测试--重新运行任务
从 类似问题中的另一个选项是创建测试类的子类,该类返回一个包含所有测试的多个副本的任务,代码如下:
在不同的级别上确实有很多方法可以做到这一点,可以使用链接中的Gradle代码,也可以使用.Gradle文件,将参数传递到测试代码中,或者在命令行上。可能会指出更多关于您的用例的信息,或者您是否希望在某个特定级别进行更改。用例是什么?更新的问题使用适当的微基准标记工具,例如,而不是运行Gradle task 100多次。或者使用。@madhead谢谢:)@重复测试是我所需要的,我认为重复测试的缺点是,在执行时,您只能使用单个配置。如果您希望在不改变项目架构(单例、缓存等)的情况下使用不同的测试配置,则需要从外部重新运行测试。感谢您的回答,我用我的用例更新了问题。您知道如何做到这一点吗?
--重新运行任务
不会多次运行测试,但是,即使不需要,也要重新运行它的任务依赖项。是的,因为@AlikElzin kilaka comments——重新运行任务
支持多次运行测试,而无需进行清理。它不会多次运行测试,因此仍然需要多次调用,例如:gradletest#initial build
date+%s#为{1..100}中的i打印开始时间
;进行梯度测试——重新运行任务;完成
日期+%s#打印结束时间