NUnit test under mono

允我心安 提交于 2020-01-06 04:21:07

问题


I have a mut.cs as follows.

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;
        }
    }
}

I came up with a Unit test for this - 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;
        }
    }
}

I ran the following command.

gmcs -debug -t:library -r:System -r:$NUNITLIB -out:mut.dll mut_test.cs mut.cs 

But I get the following error. $NUNITLIB is aliased as $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?

What might be wrong?


回答1:


The attribute you're looking for is called SetUp, not Setup.

See here: NUnit documentation - Setup




回答2:


SetUp in NUnit has a capital U.

I hate that it's spelled that way (even though it seems to be correctly spelled due to being a verb), but that's the source of your problem.



来源:https://stackoverflow.com/questions/2967726/nunit-test-under-mono

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!