visual studio 2010 c#单元测试
试图为我的方法创建单元测试,但似乎无法正确配置。 我进入新测试->单元测试向导->选择我的方法->填写测试方法值,但我总是得到断言。非决定性失败。验证此测试方法的正确性 以下是一个示例方法:visual studio 2010 c#单元测试,c#,visual-studio-2010,unit-testing,C#,Visual Studio 2010,Unit Testing,试图为我的方法创建单元测试,但似乎无法正确配置。 我进入新测试->单元测试向导->选择我的方法->填写测试方法值,但我总是得到断言。非决定性失败。验证此测试方法的正确性 以下是一个示例方法: namespace ConsoleApplication { class Program { static void Main(string[] args) { } public int Mult(int a, int b)
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.");
}
似乎很直截了当,但我遗漏了一些琐碎的东西吗?断言。非结论性主要是一个标记,告诉您需要为测试方法纠正自己的验证步骤。换句话说,对于您正在做的事情,可以在添加自己的断言时删除它 如果您的测试中有一些逻辑阻止了测试的完全运行,也可以使用它。例如,如果由于某种原因无法创建要测试的对象。确定:
Assert.Inconclusive("Verify the correctness of this test method.");
你的测试结果是不确定的,所以测试结果是不确定的。。您应该使用这种语法“Assert.Inconclusive”只覆盖您真正了解的边缘情况
AFAIC,我从来没有使用过它。这就是我的想法,因为当那行被取出时,它会正确执行。谢谢