1

Say I have a large amount of input and excepted output. Can I instruct visual studio to run test methods on all elements of the collection as separate unit tests?

[TestClass]
public class CalcTests
{
    private static IDictionary<string,string> data = new Dictionary<string,string>()
    {
        {"1+1","2"},
        {"sin(9^180)!7", "pi"}
    }

    // This will run all cases, but provides little insight as cases might vary wildly in complexity
    [TestMethod]
    public void TestCalc()
    {
        foreach(var entry in data) {
            Assert.AreEqual(Calc(entry.Key), entry.val);
        }
    }
}
dtech
  • 13,741
  • 11
  • 48
  • 73
  • 2
    You might want to consider using NUnit or xUnit instead, they have this feature. I dont think MSTest supports this, though I hardly use MSTest anymore so I could be wrong. Still, try NUnit/xUnit instead and this will be really easy. – wasatz Mar 02 '15 at 12:42
  • No, it doesn't, but there are alternatives. See [duplicate](http://stackoverflow.com/questions/347535/how-to-rowtest-with-mstest). – CodeCaster Mar 02 '15 at 12:43

0 Answers0