Visual Studio: How to create NUnit Test
By Tan Lee Published on Jun 25, 2017 3.29K
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
11 Things You Didn't Know About Cloudflare
Dec 19, 2024
Toolbox Admin Responsive Tailwind CSS Admin Template
Nov 20, 2024
Portal HTML Bootstrap
Nov 13, 2024