When I am testing my DAL I need to create some database entities before others because of dependencies, is there a way via method attributes or something I can make NUnit execute my tests in the order I specify ?
+7
A:
Use Setup and Teardown methods in your tests. Create all the things you need for your test in a method marked with the [Setup] attribute. Use a method marked with a [Teardown] attribute to close your connections etc...
Jason Punyon
2009-01-29 18:35:16
Agreed. Furthermore, your tests should ALWAYS be order independent. Your code will be cleaner because of it.
Kevin
2009-01-29 18:37:16
And further to this.. an upgrade to a future version on Nunit might not guarantee the order it runs them in.
Fortyrunner
2009-01-29 19:32:42
A:
Ideally, executing tests in a specific order is against the philosophy of unit tests, where each test should be self contained and independent of the others.The reason why they are executed alphabetically is because reflection returns the methods in this order. Having said that, using Setup and Teardown methods will in a way help you. Having said all that, take a look at this links, it could be a bit of a read but the guy writing the article series has a point
Perpetualcoder
2009-01-29 18:46:11