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

看起来很简单,但我错过了一些微不足道的东西吗?

4

2 回答 2

3

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

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

于 2012-11-07T13:37:11.730 回答
1

确定你这样做:

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

您的测试说不确定,因此测试结果不确定。您应该使用此语法“Assert.Inconclusive”仅涵盖您真正了解的边缘情况。

AFAIC,我从不使用它。

于 2012-11-07T13:38:36.600 回答