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.


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

  • 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?

Comments have been disabled for this content.