Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to Execute NUnit Tests in a Specific Order?

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 ?

like image 226
Element Avatar asked Jan 29 '09 18:01

Element


People also ask

What is the use of order attribute in NUnit?

To order tests explicitly, NUnit provides an OrderAttribute . Tests with this attribute are started before tests without. The order value is used to determine the order to run the unit tests.

How do you do multiple runs of the same test in NUnit?

To run the same test fixture twice, in parallel, you need to pass strings as parameters into the TestFixture constructor. For example, the following code runs the test fixture once against an iOS device on a certain version and with a certain device description and a second time against an Android device.


2 Answers

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...

like image 193
Jason Punyon Avatar answered Oct 04 '22 12:10

Jason Punyon


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

like image 23
Perpetualcoder Avatar answered Oct 04 '22 11:10

Perpetualcoder