Having just spent a few hours looking for something on how to do this (because the data had some formatting embedded in it so I couldn't use a CSV file) I managed to work out how to use XML with MSTest.
This is a small sample. Hope it helps.
Suppose you have a simple class library:
public class GetStrings
{
public string RichardIII(string lookup)
{
string results;
switch(lookup)
{
case "winter":
{
results =
"Now is the winter of our discontent\nMade glorious summer by this sun of York;\nAnd all the clouds that lour'd upon our house\nIn the deep bosom of the ocean buried. ";
break;
}
case "horse":
{
results =
"KING RICHARD III \nA horse! a horse! my kingdom for a horse!\n\nCATESBY \n\"Withdraw, my lord; I'll help you to a horse.\"";
break;
}
default:
results = null;
break;
}
return results;
}
}
So a unit test that will check out part of this method will look like this:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestStrings.xml", "Test", DataAccessMethod.Sequential), DeploymentItem("GetStringsTest\\TestStrings.xml"), TestMethod]
public void RichardIIITest()
{
GetStrings target = new GetStrings();
string lookup = TestContext.DataRow["find"].ToString();
string expected = TestContext.DataRow["expect"].ToString();
if (expected == "(null)")
expected = null;
string actual = target.RichardIII(lookup);
Assert.AreEqual(expected, actual);
}
The xml file TestStrings.xml looks like this:
<TestStrings>