单声道下的NUnit测试 [英] NUnit test under mono

查看:68
本文介绍了单声道下的NUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mut.cs,如下.

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

为此我想出了一个单元测试-mut_test.cs

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

我运行了以下命令.


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

但是出现以下错误. $ NUNITLIB的别名为$ NUNITLIB = $ NUNITBIN/framework/nunit.framework.dll

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?

怎么了?

推荐答案

您要查找的属性称为SetUp,而不是Setup.

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

请参阅此处: NUnit文档-设置

这篇关于单声道下的NUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆