Again On randomizer

If you read last post you saw how to write a simple randomizer for the execution of NUnit test, but it has a problem, it mess up the nunit interface. The solution is not to ovveride the Tests property, but overriding the way the test are executed. To make it simple I simply take the TestSuite.cs file from original Nunit source code, then I simply change the order in witch the test are executed.

1
2
3
4
5
private void RunAllTests(
 TestSuiteResult suiteResult, EventListener listener, ITestFilter filter)
{
    Random rnd = new Random();
    foreach (Test test in ArrayList.Synchronized(Tests).Cast<Test>().OrderBy(ts => rnd.Next()))

All the rest of the methods are standard code from the 2.4.8 release of nunit, I simply added a randomization in the main execution cycle, now everything works as expected, because the interface does not mess up but each run it executes tests in random order.

image image

As you can see test execution is now completely random at each run.

alk.

Tags: Nunit Nunit Addin Randomize Tests