Visual Studio: How to create NUnit Test
By Tan Lee Published on Jun 25, 2017 3.43K
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
Structured Data using FoxLearn.JsonLd
Jun 20, 2025
Implement security headers for an ASP.NET Core
Jun 24, 2025
10 Common Mistakes ASP.NET Developers Should Avoid
Dec 16, 2024
HTML Bootstrap 4 Login, Register & Reset Template
Nov 11, 2024