Andrew Stopford's Weblog






Old Blogs

MbUnit, repeating tests.

MbUnit (2.3 onwards) has support for repeating tests either in the same thread or in concurrent threads.

  1. [Test]
  2. [Repeat(10)] // this will make the RepeatedTest executed 10 times
  3. public void OneThreadRepeatedTest()
  4. { ... }
  5. [Test]
  6. [ThreadedRepeat(10)] // this will make the RepeatedTest executed in 10 concurrent threads
  7. public void ConcurrentThreadRepeatedTest()
  8. { ... }

How this is used needs careful consideration when used with other method attributes e.g.

  1. [Test]
  2. [Repeat(10)]
  3. [ExpectedException(typeof(Exception))]
  4. public void RepeatAndThrow()
  5. { ... }
  6. [Test]
  7. [ExpectedException(typeof(Exception))]
  8. [Repeat(10)]
  9. public void ThrowWhileRepeating()
  10. { ... }

Here RepeatAndThrow will run the test 10 times and expect each test to throw an exception. However ThrowWhileRepeating will also run 10 times and expect at least 1 of the tests to throw an exception.

Posted: Dec 28 2006, 02:11 PM by andrewstopford | with 2 comment(s)
Filed under: ,


Stuart Ballard said:

How does this work? Last time I looked - because I wanted to implement attributes that were order-dependent just like this - the order in which attributes are retrieved by Reflection is explicitly undefined and you cannot get at the order they were specified in the source code.

There was a pattern in practice, as I recall, but I was able to confirm that I was relying on undefined behavior, and had to change my APIs accordingly...

# December 28, 2006 10:23 AM

Ramanjaneya sharma said:

what's the use of repeating the execution of the test many times?plz let me know in what scenarios of the real time,this will be necessary?

# February 11, 2009 3:00 AM