Visual Studio 2010 C#单元测试

3

我试图为我的方法创建单元测试,但似乎无法正确配置。

我按照以下步骤操作:新建测试 -> 单元测试向导 -> 选择我的方法 -> 填写测试方法的值,但我总是得到Assert.Inconclusive失败的提示。请验证此测试方法的正确性。

这里有一个示例方法:

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.");
        }

似乎很简单,但我有没有错过什么微不足道的东西?
2个回答

3

Assert.Inconclusive主要是一个标记,告诉你需要为测试方法编写自己的验证步骤。换句话说,对于你正在做的事情,它可以被移除,因为你已经添加了自己的断言。

如果你的测试中有一些逻辑阻止了测试的完全运行,也可以使用它。例如,如果由于某种原因无法创建要测试的对象。


1

当然可以:

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

你的测试结果显示不确定,因此测试结果是不确定的。你应该只在你真正了解边缘情况时使用这个语法 "Assert.Inconclusive"。

就我而言,我从来不使用它。


当那行代码被注释掉时,它可以正确执行,这正是我所想的。谢谢。 - sd_dracula

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接