我有一个mut.cs如下。
using System; namespace ns { public class Arith { public int Add(int x, int y) { return x + y; } public int Mul(int x, int y) { return x * y; } } }
我想出了一个单元测试 - mut_test.cs
using NUnit.Framework; using System; using ns; namespace Unit.Tests { [TestFixture] public class ArithTests { private Arith m_arith = null; [Setup] public void Setup() { m_arith = new Arith(); } [Test] public void ValidateAdd() { int res = m_arith.Add(10,10); Assert.AreEqual(20, res); } [TearDown] public void TearDown() { m_arith = null; } } }
我运行了以下命令。
gmcs -debug -t:library -r:System -r:$NUNITLIB -out:mut.dll mut_test.cs mut.cs
但是我收到以下错误。 $ NUNITLIB别名为$ NUNITLIB = $ NUNITBIN / framework / nunit.framework.dll
mut_test.cs(9,10): error CS0118: `Unit.Tests.ArithTests.Setup()' is a `method' but a `type' was expected mut_test.cs(9,10): error CS0246: The type or namespace name `SetupAttribute' could not be found. Are you missing a using directive or an assembly reference?
可能出现什么问题?
答案 0 :(得分:3)
您正在寻找的属性称为SetUp,而不是Setup。
答案 1 :(得分:1)
SetUp
in NUnit has a capital U
我讨厌这样拼写(即使它是动词似乎是correctly spelled),但这是你问题的根源。