Software Design Blog

Journey of Rinat Abdullin

NUnit Introduces the Concept of Row Tests

Latest version of NUnit unit-testing framework for .NET has finally got support for the row tests. They are implemented by Andreas Schlapsi as an extension that now comes bundled with the NUnit 2.4.7.

Basically, row test is a test that could be run multiple times with different parameters (in other words, it is a simple data-driven test, where the data is provided by the attributes). Consider the following C# code snippet:

[TestFixture]
public sealed class Test_InterceptorCompiler : DslTests
{
  [RowTest]
  [Row("Chained Interceptions.boo")]
  [Row("ConsoleWriter.boo")]
  [Row("IWriter.boo")]
  [Row("Multiple Classes.boo")]
  [Row("Complex Writer.boo")]
  public void Interception_Dsl_Compiles(string name)
  {
    var step = new InterceptorCompilerStep()
      .Intercept<ComplexWriter>()
      .Intercept<ConsoleWriter>()
      .Intercept<IWriter>();

    CompileDslToMemory(step, name);
  }
}

Upon the execution in the NUnit GUI it will produce the following output:

Row tests in NUnit

Note, how every Row is treated as a separate unit test, and you can see which parameters have caused the failure.

Disadvantage of this new feature of NUnit is - JetBrains test runner (it comes with the R#) does not recognize them, yet. You would need to fire up NUnit GUI or use some other VS integration like TestDriven.NET in order to “run this test from the code”.

PS: there is an interesting podcast on the topic - The Past, Present and Future of .NET Unit Testing Frameworks.