I had some time last week and therefore I played around with the new extensibility features of NUnit 2.4. I wanted to know, how difficult it is to implement the RowTest feature of MbUnit as NUnit Addin. Two hours later the RowTest Extension for NUnit was ready. I released the extension under the MIT license.
The following code snippet shows you how to use the extension:
[TestFixture]
public class RowTestSample
{
[RowTest]
[Row( 1000, 10, 100.0000)]
[Row(-1000, 10, -100.0000)]
[Row( 1000, 7, 142.85715)]
[Row( 1000, 0.00001, 100000000)]
[Row(4195835, 3145729, 1.3338196)]
public void DivisionTest(double num, double den, double res)
{
Assert.AreEqual(res, num / den, 0.00001);
}
}The current release does not support all features of MbUnit RowTests, e.g. Exceptions cannot be tested.

26 Comments
Andreas,
Nice job on the extension! This proved to be a very useful sample for me. My team is deprecating the use of MbUnit in favor of NUnit and I have an existing UT code base (on the order of 2000 UT cases) that use the RowTest functionality extensively.
One optimization I have made to the RowTestNameBuilder.cs. I added a null check on _arguments[i] (in case null is passed in as a parameter to a [Row] attribute).
One odd thing I’ve observed involves UT fixture class fields being accessed from RowTests. I commonly perform one-time only initialization in a method decorated with a [TestFixtureSetup] attribute. I noticed that when RowTests are executed the class fields are always uninitialized even though I se the TestFixtureSetUp method execute prior to the RowTest.
I theorize that this is due to the fact that the TestSuite does not receive an instance of the test fixture class in the RowTestAddIn.BuildFrom() method but I am not sure how to get around that (perhaps this is a limitation in the NUnit extensibility model due to the fact that only the MethodInfo is available on ITestCaseBuilder extensions).
I can post my code modifications (no matter how slight) if anyone is interested.
Thank you for your feedback. If you permit that I integrate your modifications into the extension I’ll be interested.
I could not reproduce the issue with UT fixture class fields. Which version of NUnit are you using?
I’m using 2.4.3…I can put together a sample that would demonstrate what I was seeing. I’ll get that together for you tomorrow.
Here’s the modification I made to RowTestNameBuilder.cs:
///
/// Method to create a comma separated list of [RowTest] arguments.
///
private void CreateArgumentList()
{
StringBuilder argumentListBuilder = new StringBuilder();
argumentListBuilder.Append(”(”);
for (int i = 0; i 0)
argumentListBuilder.Append(”, “);
if (_arguments[i] == null)
{
argumentListBuilder.Append(”NULL”);
}
else
{
argumentListBuilder.Append(_arguments[i].ToString());
}
argumentListBuilder.Append(”)”);
_argumentList = argumentListBuilder.ToString();
}
argumentListBuilder = null;
}
I’ll be on a trip for about a week. Once I’m back I’ll get the sample with the odd behavior I mentioned in the previous post.
Hi
I’ve placed the files in the ‘addins’ directory, but RowTest are NOT shown when I chose, the Addins… from the Tools menu. Only the RepeatedTestDecorator is there???
Kenneth
Which version of NUnit are you using?
I’m using the latest and newest v2.4.4
Kenneth
I released a new version which was built using NUnit 2.4.4. Please try the new version.
Works now. Thanks
Kenneth
I took your add-in recompiled it for Nunit 2.4.5. All unit tests pass, but it does not work. In your DivisionTest() sample, the test is called only once - and the parameters are all zero…
Any ideas?
I could not reproduce this behavior. I have just uploaded a version built for NUnit 2.4.5. Do you still have problems if you use this build?
Turns out this appears to be a problem if using TestDriven.Net’s release.
How can I write a row test using a datetime?
I tried the following, but it was unsuccessful:
System.ArgumentException : Object of type ‘System.String’ cannot be converted to type ‘System.DateTime’.
We are not able to create categories while using Rowtest Extension.Can you suggest some method to do that please?? We are using verison 2.4 of nunit.
GAURAV
HARSHA
Nice bits, thanks.
Has anyone tried this using NUnitASP?
I’m using the WebFormTestCase : CompatibilityAdapter so my test classes inherit from WebFormTestCase
Something odd happens with the SetUp/MasterSetUp
When my test runs, I can debug and see that MasterSetUp gets called, but the test fails with error that happen when the setup doesn’t run.
If I add a call to MasterSetUp() as the first line of the rowtest, it works as expected but there are lots of extra calls to setup :S
Of note is that if I debug and I have two Rows to test, I can skip over the call to MasterSetUp in the second row
Great stuff. Really makes my life easier, thanks for creating it. I will look into the source code to learn how to make this kind of stuff myself (NUnit documentation doesn’t shine in clarity).
Andreas, I’m missing a small bit of functionality: the Category-attribute is not honored. I use this to filter out tests that have database-access (you do not always want to mock your db…) and are long-running.
It does not help to add a [Test, nycategory] attribute or a [Category] attribute to my test.
Any plans for supporting this in the [RowTest] attribute?
Hi Richard,
support for the Category attribute is planned for the next release.
Does this work with nunit version 2.4.6? Im trying to use it and it does not show up in the gui runner addons also it TestDriven.NET doesn’t run the RowTests as well.
It should work with NUnit 2.4.6. Did you compile the extension yourself or did you use the pre-built binary?
Note, that TestDriven.NET has supported NUnit addins since version 2.11 only.
Can Resharper support this RowTest extension?
RowTest does not load. I have tried with NUnit 2.4.5 and 2.4.6. Neither work. Any advice?
Confirmed that this does not work in NUnit 2.4.6 with compiled binary. If I compile it myself and add the attribute:
Type=ExtensionType.Client
it will at least show up in the GUI, but it will not recognize or run any tests that start with [RowTest]. Without the above attribute set, NUnit fails to cast the extension as IAddin for some reason. If a add the additional attribute of [Test] for the test, then NUnit just ignores it since it has input parameters I guess.
Also tested with Test Driven.NET 2.12. No inputs are given values. I.E.
[RowTest]
[Row(1,2)]
public void test (int one, int two)
{
Assert.AreEqual (1, one);
}
one will always be 0
Which .NET framework version do you use?
Have you already tried the version of the RowTest extension which is included in NUnit 2.4.7?
3 Trackbacks
[...] (historically NUnit has only supported parameterless test methods). However Andreas Schlapsi has recently written an implementation of MbUnit’s RowTest using NUnit 2.4’s Addin extensibility [...]
[...] (historically NUnit has only supported parameterless test methods). However Andreas Schlapsi has recently written an implementation of MbUnit’s RowTest using NUnit 2.4’s Addin extensibility [...]
[...] (historically NUnit has only supported parameterless test methods). However Andreas Schlapsi has recently written an implementation of MbUnit’s RowTest using NUnit 2.4’s Addin extensibility [...]