如果您从引用的 url 复制了代码段,则必须具有以下内容:
[TestFixture]
public class TestClass
{
[TestCase]
public void AddTest()
{
MathsHelper helper = new MathsHelper();
int result = helper.Add(20, 10);
Assert.AreEqual(30, result);
}
[TestCase]
public void SubtractTest()
{
MathsHelper helper = new MathsHelper();
int result = helper.Subtract(20, 10);
Assert.AreEqual(10, result);
}
}
但是,如果您查看 NUnit 版本 2.4 的文档(此处),您可以看到指示测试的 Property 方法不是[TestCase]
。改为使用[Test]
。
[TestFixture]
public class TestClass
{
[Test]
public void AddTest()
{
MathsHelper helper = new MathsHelper();
int result = helper.Add(20, 10);
Assert.AreEqual(30, result);
}
[Test]
public void SubtractTest()
{
MathsHelper helper = new MathsHelper();
int result = helper.Subtract(20, 10);
Assert.AreEqual(10, result);
}
}