获取NUnit
1.下载安装包
从github上下载安装包 NUnit.3.4.1.msi
在项目中添加引用
C:\Program Files (x86)\NUnit.org\framework\3.4.1.0\net-4.5\nunit.framework.dll
2.直接通过NuGet获取
使用方法
TestFixture Attribute
在类上面使用
SetUp Attribute
在上面的类的方法上使用
SetUpFixture Attribute
和多个TestFixture平级,比如类A和类B标记为TestFixture。然后类C添加SetUpFixture
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")); } }}
考虑全局执行一次的函数
比如整个项目加载日志模块,只需要加载一次