至于@Sprintstar在为香格里拉@迈克尔Vo1E时的回答评论中指出,断言类不能因为它是静态的伸展自然,我解决这个问题的方式通常是通过创建一个包含我的定制方法的测试库,其中包含多个断言和其他验证方法。For ex-
public static class MyTestRepository
{
public static void ArePropsEquivalent(
Dictionary<string, int> propsExpected,
Dictionary<string, int> propsActual)
{
//Multiple Asserts and validation logic
//required for Equivalence goes here
}
public static void ArePropsSimilar(
Dictionary<string, int> propsExpected,
Dictionary<string, int> propsActual)
{
//Multiple Asserts and validation logic
//required for similarity goes here
}
}
然后我从单元测试方法中调用这些方法。
[TestMethod]
public void TestMthod1()
{
//Props declaration goes here
MyTestRepository.ArePropsEquivalent(propsExpected, propsActual);
}
[TestMethod]
public void TestMthod2()
{
//Props declaration goes here
MyTestRepository.ArePropsSimilar(propsExpected, propsActual);
}
这样我可以少写,并在实际的单元测试用例的方法做多,并保持它的模块化(不同型号的情况下)。
这里的问题是,如果在两个词典中的元素不具有相同的顺序,断言将失败,即使元素是等于 – 2009-05-31 01:04:35