C# NUnit单元测试
1编写代码
namespace ConsoleApplication1 { class NUnitSample { public int Add(int a, int b) { return a + b; } static void Main(string[] args) { NUnitSample sp = new NUnitSample(); Console.WriteLine("writeLine:"+ sp.Add(1, 2)); Console.Read(); } } }
2添加测试代码
using NUnit.Framework; namespace ConsoleApplication1 { [TestFixture] public class NUnitSampleTest { [Test] public void addTest() { NUnitSample sp=new NUnitSample(); int a= sp.Add(1,2); Assert.AreEqual(3, a); } [Test] public void addTest2() { NUnitSample sp = new NUnitSample(); int a = sp.Add(3, 3); Assert.AreEqual(4, a); } } }
3打开 NUnit
3.1
3.2 新建测试 new
3.3 导入测试类 打开bin->DeBug->NUnitSampleTest
4添加测试
5完成
注意:本文归作者所有,未经作者允许,不得转载