Visual Studio 2010 C#单元测试



尝试为我的方法创建单元测试,似乎无法正确配置。我去新测试 ->单元测试向导 ->选择我的方法 ->填写测试方法值,但我总是会得到assert.conconlusive失败。验证此测试方法的正确性。

这是一种示例方法:

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
        }
        public int Mult(int a, int b)
        {
            return a * b;
        }
    }
}

和测试方法:

[TestMethod()]
        public void MultTest()
        {
            Program target = new Program(); // TODO: Initialize to an appropriate value
            int a = 4; // TODO: Initialize to an appropriate value
            int b = 5; // TODO: Initialize to an appropriate value
            int expected = 20; // TODO: Initialize to an appropriate value
            int actual;
            actual = target.Mult(a, b);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

似乎很简单,但是我缺少一些微不足道的东西吗?

sustert.conconclusive主要是一个标记,告诉您您需要对测试方法进行正确的验证步骤。换句话说,对于您正在做的事情,可以将其删除,因为您添加了自己的断言。

如果您的测试中有一些逻辑可以防止测试的完整运行,则也可以使用它。因此,例如,如果您无法创建因某种原因试图测试的对象。

确保您做:

Assert.Inconclusive("Verify the correctness of this test method.");

您的测试表明测试结果尚无定论。.您应该使用此语法" assert.conconcontusive"来涵盖您真正意识到的边缘案例。

afaic,我从不使用它。

最新更新