I am using Spring Boot application with gradle. Currently there are 9 tests will be executed during build and test gradle task. One test is excluded as it will affect the other tests. So I have excluded the SampleTest as below in build.gradle
test {
useJUnitPlatform()
filter {
excludeTestsMatching "com.test.func.SampleTest"
}
}
Now I want to run all the tests in the following order. My SampleTest should be run at end of all tests. How should I achieve it? Any help would be appreciated.
- Other 9 tests
- com.test.func.SampleTest
CodePudding user response:
Need to review the tests why you need to do this.
Gradle simply delegates execution to the JUnit runner.
So if you want specific test class ordering, you will need to create a Suite (with @SelectClasses:) and specify the test classes in the order you want
You can fellow this doc to create test suite https://howtoprogram.xyz/2016/08/16/junit-5-test-suite/
If all the tests are in the same test file, you could use @Order with junit5 to give the order exécution for each test: https://www.baeldung.com/junit-5-test-order
CodePudding user response:
There is an option based on your question, so you can create additional task
for testing SampleTest
run.
task testLast(type: Test) {
include '**/SampleTest.*'
}
test {
exclude '**/SampleTest.*'
}
test.dependsOn testLast