Getting started with NUnit’s RowTest

03 Nov
by mjeaton, posted in Uncategorized   |  11 Comments

Maybe I’ve been living under a rock, but I just found out that the latest versions of NUnit support [RowTest]!  Over the weekend, I was about to replace NUnit with mbUnit because I need [RowTest], but thankfully, after a bit of surfing, I found this post by David Hayden (dated December 2007).  David’s post described an add-in for NUnit that has since been rolled into NUnit proper.

Step 1: Download / install NUnit version 2.4.7 or newer.

Step 2: Add a reference to NUnit.framework.dll and NUnit.framework.extensions.dll.

nunit.references

Step 3: Add using NUnit.Framework and using NUnit.Framework.Extensions to your test class.  I include SyntaxHelpers because I like using the .That(condition, Is.) syntax.

nunit.using

Step 4: Decorate your tests with [RowTest], add individual cases and add parameters to your test that match the data from the test cases.

[RowTest]
[Row("foo", false, true)]
[Row("", false, false)]
[Row(null, false, false)]
[Row("___-__-____", false, true)]
[Row("___-__-____", true, false)]
public void testRequiredFieldValidator(string data, bool ignoreChars, bool result)
{
    var rule = new RequiredFieldValidationRule("test field");
    rule.IgnoreMaskCharacters = ignoreChars;
    ValidationResult temp = rule.Validate(data, CultureInfo.CurrentCulture);
    Assert.That(temp.IsValid, Is.EqualTo(result));
}

Step 5: Run :-)

nunit.results.1

nunit.results.2

Notes: I did have to download the a new version of TestDriven.net, but other than that, it was a pretty simple process.

Technorati Tags: ,,

11 Responses to Getting started with NUnit’s RowTest

  1. Travis Laborde

    I’ve been living under the same rock :) Thanks for the info!

  2. Rusli Zainal Sang Visioner

    this is very interesting. thanks for that. we need more sites like this. i commend you on your great content and excellent topic choices. i’m spreading the good word about this site to all

  3. Rusli Zainal

    this is very interesting. thanks for that. we need more sites like this. i commend you on your great content and excellent topic choices. i’m spreading the good word about this site to all..

  4. Mel Grubb

    Personally, I don’t see the need for RowTest. If you want to perform a test with multiple sets of input, I presume those different sets are intended to acheive different results. Just create a non-test method that takes those parameters, and then multiple test methods to call it, with each test providing different input parameters. Not only does it acheive the same result, but you can now name the individual “rows” for the effect they are trying to provoke.

  5. poker tournaments online

    Thanks for the update of your journewy.I ‘ll bookmark this site as well

  6. Web developer

    Interesting,

    this info is great, have been stuck with a similar problem, keep up the good work.

    Thanks

  7. nikol

    The information about cost matters is really useful. Thanks for sharing this article.

  8. Stefan Barthel

    In the current release of NUnit (2.5.3.9345) there is no NUnit.framework.extensions.dll, and I didn’t find RowTest in any of the other assemblies shipped with it. So what happened to RowTest?

  9. Stefan Barthel

    They disappeared in 2.5, the release notes just state, that they were removed, but not why. Did they move into a separate download, or is there any reasons not to use them anymore?

  10. meilleurs casinos

    It’s a great article explaining NunitASP. One request is that, please post a new blog that explains how to use NUnitASP. Thanks for your effort.