重载将自动为您完成此操作。作为测试我在此测试方法来看到的输出将是什么:
[TestMethod]
public void Test()
{
Assert.AreEqual(true, false, "Failed on the following test case: AB");
}
以及错误消息输出是:Assert.AreEqual failed. Expected:<True>. Actual:<False>. Failed on the following test case: AB
该消息参数已经被附加/组合以缺省消息。
对于你的情况,如果你只是想测试项的测试可能看起来像:
foreach (var testCase in testCases)
{
Assert.AreEqual(testCase.Value, myObj.myMethod(testCase.Key),
"Failed on the following test case: " + testCase.Key.ToString());
}
而且如果测试用例应该每个人都有自己的自定义消息,它会接着是有意义的移动自定义错误消息给testCase类。作为创建每个对象的一部分可以接着指定这些三个属性:
testCase.Value = true;
testCase.Key = "AB";
testCase.FailureMessage = "Failed on the following test case: AB";
这种类型的结构将允许具有要追加用于测试用例的每个实例指定消息。这样做将使单元测试看起来像这样:
foreach (var testCase in testCases)
{
Assert.AreEqual(testCase.Value, myObj.myMethod(testCase.Key),
testCase.FailureMessage));
}
,并在您的示例输出显示为:Assert.AreEqual failed. Expected:<True>. Actual:<False>. Failed on the following test case: AB
广东话您连接2个字符串? – Blachshma 2013-03-05 17:07:37
Assert.AreEqual失败不是静态的。我想使用框架中出现的任何内容。 – 2013-03-05 17:11:24