Gradle equivalent for Maven Surefire surefire.forkNumber

怎甘沉沦 提交于 2019-12-14 03:04:22

问题


I'm migrating a codebase from Maven to Gradle.
In our integration test we use FailSafe ability to run the tests in parallel in multiple threads.
FailSafe is setting a system property name surefire.forkNumber with the number of the specific fork the current thread runs.

Is there equivalent parameter when running JUnit with Gradle?


回答1:


The test task in Gradle has the property maxParallelForks to instruct the tests to run in parallel. To pass a property from the command-line to set the value we can define the following test configuration in our build file:

// File: build.gradle
...
// Set maxParallelForks using project property
// testMaxParallelForks if set otherwise use 1.
test.maxParallelForks = project.findProperty('testMaxParallelForks') ?: 1
...

Then from the command-line we can run the test task: $ gradle test -PtestMaxParallelForks=8

Gradle sets the Java System property org.gradle.test.worker with the index number of the thread running the test. This property can be read and used within the tests that run on the parallel thread.



来源:https://stackoverflow.com/questions/48784061/gradle-equivalent-for-maven-surefire-surefire-forknumber

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!