Okay, I'm done searching for good information on this. I have a series of Unit Tests that call a static class which, once initialized, sets properties that cannot (or I don't wish to) change.
My problem is I cannot enforce a set order for the tests to run. If I could, I could run them in such a way as the static properties would be set in a reliable way, and I could Assert on them, but unfortunately the Microsoft.VisualStudio.TestTools.UnitTesting framework just runs them in a seemingly random order.
So, I found this http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.priorityattribute.aspx which says in the Remarks section "This attribute is not used by the test system. It is provided to the user for custom purposes." Huh? What good is it then? Do they expect me to write my own testing wrapper to take advantage of this fabulous attribute (of which I could easily write myself if I wanted to go to that level of effort...)
So, enough of the rant; Bottom line, is there a way to control the order my unit tests run?
[TestMethod] [Priority(0)]
etc. does NOT seem to work, which makes sense, since Microsoft says it won't.
Also, please no comments about "violating isolation". The TestClass isolates what I am testing, not the individual TestMethods. Regardless, each test can be run independently just fine, they just can't be run together in a random order as there is no way to tear down the static class.
Oh, I also know about "Ordered Test".
Occasionally, you may want to have unit tests run in a specific order. Ideally, the order in which unit tests run should not matter, and it is best practice to avoid ordering unit tests. Regardless, there may be a need to do so. In that case, this article demonstrates how to order test runs.
So in JUnit 5 (from the 5.4 version) you have all the same the possibility to set the execution order by annotating the test class with @TestMethodOrder(OrderAnnotation. class) and by specifying the order with @Order(numericOrderValue) for the methods which the order matters.
A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.
You can Use Playlist
Right click on the test method -> Add to playlist -> New playlist
the execution order will be as you add them to the playlist but if you want to change it you have the file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With