Reputation: 962
When I execute a command similar to this:
go test \
github.com/mycompany/projectX/packageA \
github.com/mycompany/projectX/packageB \
github.com/mycompany/projectX/packageC
Then go will test packageA, then packageB, and then packageC. Is there an option so that the order of package testing is shuffled? For instance, packageC is tested first before package A then package B. There is a -shuffle on
option but this option only shuffles the tests within a package. I want to shuffle the order of the packages.
Upvotes: 1
Views: 1025
Reputation: 7948
Packages are always tested in alphabetical order, no way to disable it. I wasn't there so I have to guess at the reason.
In general unit tests should not be dependent on the execution order since at that point you are testing more than just the functionality of your unit. If for some reason your unit tests are dependent on execution order, and this order is always fixed, you will still get consistent results. But if this order was somehow random or dependent on naming or order in which you specify them, than it means that a test may pass on your machine but fail in the CI or visa versa.
Such bugs are extremely frustrating since it might not be obvious that the order of tests influences its result.
Having said all that, if you wish you can still randomize testing using the T.Run method in a random order. But this only works within the same package not across packages.
Upvotes: 3