views:

783

answers:

2

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
Agreed. Furthermore, your tests should ALWAYS be order independent. Your code will be cleaner because of it.
Kevin
And further to this.. an upgrade to a future version on Nunit might not guarantee the order it runs them in.
Fortyrunner
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

LINK Pt1

LINK Pt2

LINK Pt3

LINK Pt4

LINK Pt5

Perpetualcoder