How to run forked JUnit tests in optimal order? - maven

I have some long running JUnit tests which I want to run first to avoid them being queued and executed last and thus delaying the whole test execution process.
I currently use maven surefire to run my tests using:
forkCount: 5
reuseForks: false
Is there a way to specify which tests should be run first? Or a way to optimize the order in which the tests are run?
The runOrder=balanced parameter does not seem to work in combination with forkCount > 0 and reuseForks false.

Unfortunately, you can’t determine the test execution order. Here is a clumsy workaround for this problem. For integration tests, I use a JUnit extension to run tests in specific order.

Related

How to run Junit5 and TestNG togather in Maven pom

I have some set of test cases configured with TestNG. I developed preconditions in junit5 and this has to be run before the test starts. So I wanted to run in sequence Line Precondition(junit5) and then Testcases.
I am using dependency for Junit5 and TestNG7 in PM.XML. Below is a snapshot of POM.xml htmlunitTest.java is for junit5 and testng.xml for TestNGTest cases. while running build is terminating successfully without execution of any test.
You probably do not want to hear my answer. It is the best I have anyway: Don’t take that route! Don’t couple two frameworks that are not made to work together.
Although there might be a convoluted and hacky way to achieve what you describe, you’re setting yourself up for unnecessary technical complexity. Stick with one framework and use its own means for preconditions or fixing a test order.

How to order unit test execution from Gradle?

Is there any way to specify the order of the unit tests classes run by a Gradle Test task?
I'd like to get some known longer-running tests at either the front or the back of the list, but don't know if it's possible without splitting my tests' execution between multiple tasks.
Running JUnit 4.12 and Gradle 4.5.
Gradle simply delegates execution to the JUnit runner.
So if you want specific test class ordering, you will need to create a Suite and specify the test classes in the order you want, see the JUnit documentation for this.
Now, given the flexibility of Gradle in terms of having different source roots, I would strongly recommend doing the separation at the Gradle level, by create extra test source roots, test task and the like. This will allow you to effectively control when these long running tests are run in a standard build execution, but also to skip them or run these only when desired. The ordering at the JUnit level will not give that flexibility without much more tweaking. See the Gradle documentation on adding source sets.

Control the running order of the Spock specs

I'm trying to run Spock tests in a specific order, I'm using gradle to run the tests.
I want to be able to control the test order.
I've found I can use the suit, but it doesn't scale for my tests.
is there any other way to run spock tests in a specific order?

Spock - Do not run Specs simultaneously

I'm running functional tests using Spock where the tests manipulate the database, and the Specs can conflict with each other if run simultaneously. From my web debugger, it appears that when I run gradle test that the calls to the web service from different Specs are being called simultaneously. The Specs themselves are being called with the #Stepwise annotation, and the tests are run in the correct order. How can I have Specs run separately in some order? They do not need to run in any specific order.

Maven: Conditional Execution upon IT Success / Failure

Here is something I''ve tried to come up with an idea, but I'm not sure.
We do have a module which should be built, deployed and then integration test begins (via failsafe, but others might be fine). We'd like to selectvely invoke mojos based on its results.
I think verify from failsafe should do the trick (with probably some gmaven trickery), but how to validate the results of failsafe? Perhaps some Test Listener Magic with JUnit could help?
Any ideas how could we achieve that, considering a Maven (and Probably Hudson) scenario?
Thank you
Let do the first part of that do Hudson (run integration tests) and do a failsafe:check in your integration test cycle and based on the result you can start a dependenant job in Hudson to run an other job whatever this job will do. But you can't execute selective mojos based on results (afak).

Resources