Visual Studio: How to create NUnit Test
By Tan Lee Published on Jun 25, 2017 3.37K
How to create NUnit Test in C#
To play demo, you need to create a MyMath class as below
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NUnitTestDemo { public class MyMath { public int Add(int a,int b) { return a + b*2; } public int Sub(int a,int b) { return a - b; } } }
To work with extensions and updates, click on the Tool->Extension and Updates and then select NUnit Test Adapter. A test class can be created as shown in the listing below:
using NUnit.Framework; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NUnitTestDemo { [TestFixture] class MyTestCase { [TestCase] public void Add() { MyMath math = new MyMath(); Assert.AreEqual(31, math.Add(20, 11)); } [TestCase] public void Sub() { MyMath math = new MyMath(); Assert.AreEqual(10, math.Sub(20, 10)); } } }
VIDEO TUTORIALS
Categories
Popular Posts
HTML Bootstrap 4 Login, Register & Reset Template
Nov 11, 2024
10 Common Mistakes ASP.NET Developers Should Avoid
Dec 16, 2024
RuangAdmin Template
Nov 13, 2024
Material Lite Admin Template
Nov 14, 2024