Visual studio参数化单元测试

时间:2015-03-02 12:35:52

标签: c# visual-studio unit-testing

假设我有大量输入和例外输出。我是否可以指示visual studio在集合的所有元素上运行测试方法作为单独的单元测试?

[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);
        }
    }
}

0 个答案:

没有答案