NUNIT Quick Reference Free Quick References and .net components.

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() { } } }

Sign up to vote on this title
UsefulNot useful