C# NUnit单元测试

航仔 3月前 ⋅ 275 阅读

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

1.PNG

3.2 新建测试 new

3.3 导入测试类 打开bin->DeBug->NUnitSampleTest

4添加测试

2.PNG

5完成


全部评论: 0

    我有话说: