Andrian Durlestean
Andrian Durlestean

Reputation: 1730

How can i sort tests by my liking?

For example i got 3 test and their name are

[Test]
public void ATest()
{}

[Test]
public void BTest()
{}

[Test]
public void DTest()
{}

Any better idea?

Upvotes: 0

Views: 711

Answers (3)

djangofan
djangofan

Reputation: 29689

If you use JUnit 4.11 (the latest version) , I do believe there is a "alphebetical order' scheme that you can use to execute in alphabetical order. I'm not sure if NUnit has the same capability.

But, personally I will usually configure my build system , either Gradle or Maven, to execute certain test classes in atomic operations. That way I can combine them in the order I need.

Upvotes: 0

Serberuss
Serberuss

Reputation: 2387

The idea with Unit Testing is that it's irrelevant which order they are ran in because tests are supposed to run independently of each other. If all the tests you have run have passed then you shouldn't care about the order. If a test fails your focus will be on fixing that test.

If the order of the tests really is important to you then like Alex said the only way to do it is by alphabetizing your tests. I've seen cases where people have put A, B, C etc at the start of similar naming tests, but this is a bad idea.

Upvotes: 4

so cal cheesehead
so cal cheesehead

Reputation: 2573

Unfortunately that's the way to do it, by alphabetizing your test cases. Take a look at this

https://bugs.launchpad.net/nunit-3.0/+bug/740539

Quote from Charlie Pool, on of the main devs for nunit:

"Relying on alphabetical order is a workaround that you can use but it is not documented and supported beyond the visual order of the display. In theory it could change at any time. In practice it won't change until NUnit 3.0, so you're pretty safe using it as a workaround."

Alternatively you could try testng which has a nice "preserve-order" flag which you could use to ensure test case order execution.

Upvotes: 1

Related Questions