-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truely random test order with posibility for externaly given seed #1194
Comments
Might I suggest knuth shuffle for determining run order? source code- |
From Test execution order
|
The problem here is that there are actually two test smells that are interconnected with each other:
Putting tests into a really random order would help with the first. As no test can predict what happened before he can not depend on any other test to have been executed before. By changing the order with each run you would also find tests accidentally depending on the execution order. But if you change the execution order to random your tests might also become non repeatable. So if you run the tests on the same machine two times they may yield different results. This will most likely be because your tests are somehow coupled in some way. They should not be but they are. There is no easy way to deal with these results. What do you do if you try to deploy some software because everything was green all the time but than in the final test you by accident find the one execution order that brakes one test? Tests must ether pass or fail and they must do this repeatedly. (Or else someone will start ignoring failing tests and just rerun them to get them passing.) This is most likely part of what let to the implementation as mentioned by @ffbit: It is a compromise to face both problems. By making the order unpredictable they made it hard for anyone to implement there tests to use it. By making it deterministic they ensured that test execution always comes to the same result. |
Hey @Endron. Your point is good but please look closer in Rspec Cite:
This is an example execution (you can see the seed is displayed in command line): https://travis-ci.org/coi-gov-pl/puppet-jboss/jobs/81936397#L556 |
I just submitted a pull request adding this feature. P.S. Sorry about the multiple commit notices. Being relatively new to GitHub, I didn't realize that merely pushing to my own repo would make it do that. |
I think that this also can be done with PR #1130. The seed can be set externally by Maven and Gradle plugins |
We truly need a simple way as a new |
I would like to say that if you are using Maven to run your tests you might be interested in this PR apache/maven-surefire#112 to Surefire/Failsafe plugin to introduce class level test randomization with seed. |
By default junit executes test in default order that is based on method name hash code. In java hashcodes of string doesn't change between executions, so the order is random, but constant for given computer. That could lead to unpredictable errors.
Ref: https://github.com/junit-team/junit/blob/master/src/main/java/org/junit/internal/MethodSorter.java#L13
To fix this enchantment, there should be truly random order option to explicitly specify in test case using
@FixMethodOrder
.I propose to follow Rspec
--order
random option implementation. It actually makes random order for execution but seed used for this is displayed and logged into reports. This gives developers a chance to execute the same execution with--order rand:3455
. It guarantees that tests will be executed in the same order, therefore it's possible to hunt for execution order bugs.Cite:
Example execution:
Rspec random refenrence: http://blog.davidchelimsky.net/blog/2012/01/04/rspec-28-is-released/
The text was updated successfully, but these errors were encountered: