Checking Spock Order by Package

He is everything! My tests are run by jenkins from a common package. Can I install a test package in spock, which will be launched first, and if no test passes in this package, other tests should be skipped. I saw such examples:

import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({TestJunit1.class, TestJunit2.class}) public class JunitTestSuite { } 

But maybe spock has a solution where I can use packages instead of enum for each class, because I have many test classes in other packages. Also after i used the runner

 import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; public class TestRunner { public static void main(String[] args) { Result result = JUnitCore.runClasses(JunitTestSuite.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } System.out.println(result.wasSuccessful()); } } 

The main thread does not stop. I do not know why. I want to do something like this:

 import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({com.example.test.*.class}) public class JunitTestSuiteFirst { } 

 import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({com.example.otherTest.*.class, com.example.otherTests2.*.class}) public class JunitTestSuiteFirst { } 

 import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; public class TestRunner { public static void main(String[] args) { Result result = JUnitCore.runClasses(JunitTestSuite.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } if(result.wasSuccessful()){ JUnitCore.runClasses(JunitTestSuite.class); }else { System.out.println("Build failed"); } } } 

Or maybe there is a simpler solution to this problem. Thanks.

+5
source share
1 answer

Everything that you can work out as part of unit testing will not be beautiful. This is due to the fact that unit tests must be independent of each other, while thinking will not have strong support for setting the order of tests. Therefore, it is best to look for your solution in your build tools (Ant, Maven, Gradle, etc.).

The following gradle snippet sets up two different unit test suites / directories. Using the gradle test integrationTest build tests running src / integration will only run if all tests in src / test pass.

 sourceSets { integrationTest { java { srcDirs = ['src/integration'] } groovy { srcDirs = ['src/integration'] } resources.srcDir file('src/integration/resources') } test { java { srcDirs = ['src/test'] } groovy { srcDirs = ['src/test'] } } } 
0
source

Source: https://habr.com/ru/post/1265616/


All Articles