Okay, so data-driven tests are a bit of a sore point with many developers. One camp thinks that d-d tests should be done using tools like Fitnesse (hey, it probably is a little easier), others—including me—beleive that it’s perfectly okay to use unit testing frameworks such as NUnit or MbUnit.

I do data-driven tests for real, in-production product development. It works. Here’s some proof:

[Test]
[Row("<a></a>""new XElement(\"a\")"null)]
[Row("<a/>""new XElement(\"a\")"null)]
[Row("<a b=\"c\"/>""new XElement(\"a\", new XAttribute(\"b\", \"c\"))"null)]
[Row("<a>z</a>""new XElement(\"a\", new XText(\"z\"))"null)]
[Row("<a b=\"c\">z</a>""new XElement(\"a\", new XAttribute(\"b\", \"c\"), new XText(\"z\"))"null)]
[Row("<h{0}></h{0}>""new XElement(\"h\" + i)""i"null)]
[Row("<h{0}>{1}</h{0}>""new XElement(\"h\" + i, new XText(j))""i|j")]
[Row("<a><b></b></a>""new XElement(\"a\", new XElement(\"b\"))"null)]
[Row("<a><b></b><c></c></a>""new XElement(\"a\", new XElement(\"b\"), new XElement(\"c\"))"null)]
[Row("<a><b><c></c></b></a>""new XElement(\"a\", new XElement(\"b\", new XElement(\"c\")))"null)]
[Row("<a{0}{1}></a{0}{1}>""new XElement(\"a\" + i + j)""i|j")]
[Row("<{0}z{1}/>""new XElement(i + \"z\" + j)""i|j")]
public void ConversionTests(string input, string expectedOutput, string args)
{
  IList<string> arguments = null;
  if (args != null)
    arguments = new List<string>(args.Split(new[]{'|'}, StringSplitOptions.RemoveEmptyEntries));
  var a = StringToXmlLinqCA.ReplaceFormattingTagsWithSpecialSymbols(input);
  var b = XElement.Parse(a).ToAssemblyCode();
  var c = StringToXmlLinqCA.ReprocessExpression(b, arguments);
  Assert.AreEqual(expectedOutput, c);
}

By the way, the full version of R2P comes with a fully-fledged test row editor. It’s not Excel but it does simplify things a little bit – at least when it comes to encoding quotes and the like. Stay tuned :)