Search code examples
asp.net-mvcunit-testingtddnunitmbunit

MbUnit's row attribute in NUnit?


While reading an Asp.Net MVC code sample that used MbUnit as it's testing framework, I saw that it was possible to run a single test against multiple input possibilities by using a Row attribute, like so:

[Test]
[Row("test@test_test.com")]
[Row("sdfdf dsfsdf")]
[Row("sdfdf@.com")]
public void Invalid_Emails_Should_Return_False(string invalidEmail)
{
    ...
}

Please I'd like to know if there is an NUnit equivalent of MbUnit's Row attribute , or otherwise an elegant way to achieve this in NUnit. Thanks.


Solution

  • I think you're after the TestCase attribute

    [TestCase(12,3,4)]
    [TestCase(12,2,6)]
    [TestCase(12,4,3)]
    public void DivideTest(int n, int d, int q)
    {
      Assert.AreEqual( q, n / d );
    }
    

    http://www.nunit.com/index.php?p=testCase&r=2.5.7