c# - Visual Studio 单元测试 : why test run inconclusive whereas testing same float values?

标签 c# visual-studio unit-testing

我正在学习 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/

相关文章:

c# - 两个 IEnumerable<IEnumerable<int>> 对象之间的相等性

c# - 将 DLL 嵌入已编译的可执行文件中

scala - 在 Intellij 中运行 Spark MLLib 单元测试时出现 UnsatisfiedLinkError : no snappyjava in java. library.path

unit-testing - 运行 SpecFlow 报告 - 错误 - 元素 <Target> 中的属性 "Label"无法识别

c# - SilverLight 套接字问题

c# - 以编程方式使用 C# 登录网站

angular - translate.get 有时返回键而不是翻译

visual-studio - NuGet.exe 包提供对路径的访问被拒绝

visual-studio - Visual Studio 2017 HRESULT:0x80070005/项目创建时E_ACCESSDENIED

python - Python的模拟库,在模拟函数中只返回一次值?