我正在使用Visual Studio 2015附带的单元测试框架编写测试。我保留一个单独的记录器来记录值,并将计算值与测试用例中的预期值进行比较。问题是我有几个测试失败了。当它们失败时,我调用Assert.Fail(),但Visual Studio中的Test Explorer仍然将测试显示为传递。
有没有人看过这种行为,你能建议怎么做吗?这是一个例子:
if (InitialFlatSocialCostFactorFromDB == CalculatedInitialFlatSocialCostFactor)
{
logger.WriteLine("InitialFlatSocialCostFactor (database): " + InitialFlatSocialCostFactorFromDB.ToString("F2"));
logger.WriteLine("FlatSocialCostFactor (calculated): " + FlatSocialCostDeductionCalculated.ToString("F2"));
logger.FinishTest(true);
Assert.IsTrue(InitialFlatSocialCostFactorFromDB == CalculatedInitialFlatSocialCostFactor);
}
else
{
logger.WriteLine("InitialFlatSocialCostFactor (database): " + InitialFlatSocialCostFactorFromDB.ToString("F2"));
logger.WriteLine("FlatSocialCostFactor (calculated): " + FlatSocialCostDeductionCalculated.ToString("F2"));
logger.FinishTest(false);
Assert.Fail("Expected Initial Flat Social Cost Factor does not match Initial Flat Social Cost Factor in database.");
}