Vadim’s Weblog

Never stop learning.

Duration in MbUnit

Posted by Vadim on April 12, 2007

Playing with MbUnit I just discovered DurationAttribute for the first time. This attribute sets the maximum time allowed for test to finish execution.

The test below will fail because in Duration attribute we set duration for one second but inside the test we sleep for 2 seconds.


[Test]
[Duration(1)]
public void DurationFailTest()
{
  Thread.Sleep(2000);
}


Next test will succeed because we don’t sleep at all.


[Test]
[Duration(1)]
public void DurationSuccessTest()
{
  Thread.Sleep(0);
}


You can use it with RowTest attribute. Row(0) will succeed and Row(2000) will obviously fail.


[RowTest, Duration(1)]
[Row(0)]
[Row(2000)]
public void DurationRowTest(int sleepTime)
{
  Thread.Sleep(sleepTime);
}

One Response to “Duration in MbUnit”

  1. Julian said

    Hi Vadim

    I posted a little more about this topic, you can see it here:
    http://www.hpoffice.cl/julian/archive/2007/04/19/More-about-test-duration-in-MbUnit.aspx

    Best regards,
    Julián

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>