nunit cheat sheet
TRANSCRIPT
![Page 1: NUnit Cheat Sheet](https://reader035.vdocuments.us/reader035/viewer/2022071700/552972ab550346a82e8b47a2/html5/thumbnails/1.jpg)
using System; using Kellerman.Business; //Reference to class to test using NUnit.Framework; //This must be included to do the asserts namespace Kellerman.BusinessTest {
//Tests for the Invoice Business Object [TestFixture]
[Category(“Optional Category Attribute”), Description(“Optional Description”)] public class InvoiceTest { private Invoice _invoice = null;
//Code that is run before each test [SetUp] public void Initialize() { _invoice = new Invoice (); }
//Code that is run after each test [TearDown] public void Cleanup() { }
//Example test and asserts [Test, Description(“Property Tests”)] public void InvoiceIdTest() { int expected = 7; _invoice.InvoiceId = expected; Assert.AreEqual(expected, _invoice.InvoiceId,
"Kellerman.Business.Invoice.InvoiceId not set correctly");
//Other example Asserts Assert.IsTrue(true); Assert.IsFalse(false); Assert.IsNull(null); Assert.IsNotNull(_invoice); Assert.IsEmpty(string.Empty); Assert.IsNotEmpty(“This string is not empty”); Assert.Fail(“This is a failure message”);
}
//Expected Exception Test [Test] [ExpectedException(typeof(System.Security.SecurityException))] public void DeleteTestNoRights() { _invoice.Delete(); }
//Not Implemented Test [Test] [Ignore(“Please implement”)] public void UpdateTestNoRights() { } } }
NUNIT Quick Reference www.kellermansoftware.com Free Quick References and .net components.