【问题标题】:visual studio 2010 c# unit testsVisual Studio 2010 C#单元测试
【发布时间】:2012-11-07 13:34:08
【问题描述】:

尝试为我的方法创建单元测试,但似乎无法正确配置。 我去新测试->单元测试向导->选择我的方法->填写测试方法值,但我总是得到 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.");
        }

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

【问题讨论】:

    标签: c# visual-studio-2010 unit-testing


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      你确定:

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

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

      AFAIC,我从不使用它。

      【讨论】:

      • 这就是我的想法,因为当该行被取出时它会正确执行。谢谢。
      猜你喜欢
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      相关资源
      最近更新 更多