http://www.c-sharpcorner.com/UploadFile/84c85b/nunit-with-C-Sharp/
获取NUnit
1.下载安装包
从github上下载安装包 NUnit.3.4.1.msi
https://github.com/nunit/nunit/releases
在项目中添加引用
C:Program Files (x86)NUnit.orgframework3.4.1.0 et-4.5 unit.framework.dll
2.直接通过NuGet获取
使用方法
TestFixture Attribute
在类上面使用
https://github.com/nunit/docs/wiki/TestFixture-Attribute
SetUp Attribute
在上面的类的方法上使用
https://github.com/nunit/docs/wiki/SetUp-Attribute
SetUpFixture Attribute
和多个TestFixture平级,比如类A和类B标记为TestFixture。然后类C添加SetUpFixture
https://github.com/nunit/docs/wiki/SetUpFixture-Attribute
This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace.
The class may contain at most one method marked with the OneTimeSetUpAttribute and one method marked with the OneTimeTearDownAttribute.
using NUnit.Framework; namespace ConsoleApp { [TestFixture] public class KataTests { [Test] public void BasicTests() { Assert.AreEqual("01011110001100111", Kata.FakeBin("45385593107843568")); Assert.AreEqual("101000111101101", Kata.FakeBin("509321967506747")); Assert.AreEqual("011011110000101010000011011", Kata.FakeBin("366058562030849490134388085")); } } }
考虑全局执行一次的函数
比如整个项目加载日志模块,只需要加载一次