我正在学习 VS 单元测试并试过这个:
[TestMethod()]
public void calcTest()
{
double expected = 1.234F; // TODO: Initialize to an appropriate value
double actual;
actual = 1.234F;
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
当运行这个测试方法时,它说 inconclusive ???为什么?
更新:好吧,不要比较 float ,但业务需求就是 float 。那么如果我需要比较它们该怎么办呢?
你的意思是要考浮点计算不头疼是不可能的?那么,如果测试在财务计算中如此令人头疼,那么根本不进行测试不是更好吗?
似乎是 vs 测试框架中的一个巨大错误或设计缺陷,而不是 :) 正如这里所说 http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.inconclusive%28VS.80%29.aspx
表示无法证明断言是真还是假。
因为我比较了 2 个相同的文字,所以确定它是真的。
最佳答案
呃,因为你告诉它是?
Assert.Inconclusive("Verify the correctness of this test method.");
现在您有了AreEqual
,您应该能够删除这个Inconclusive
任何测试期间的失败(不包括您有意处理的异常)通常是终结性的,但任何通过的断言(如AreEqual
此处)继续运行。所以第一个测试通过,然后最后一行将其标记为不确定。
关于c# - Visual Studio 单元测试 : why test run inconclusive whereas testing same float values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3777970/