Skeleton C# Class With Test Harness (
Join the DZone community and get the full member experience.
Join For FreeUsing SnippetCompiler (http://www.sliver.com) a lot, I needed a template which has the nUnit components started... Here it is.
using System;
using System.Collections;
using NUnit.Framework;
#region entry point
public class EntryClass
{
public static void Main()
{
NewClass t = new NewClass();
}
}
#endregion entry point
// To test, select Build|Build To File... then point nunit's guii at the resultant dll
// Class we will build up for testing
public class NewClass
{
// Sample Method which is tested
public int MyMethod(int firstNumber, int secondNumber)
{
return firstNumber + secondNumber;
}
}
// Class that does the nunit testing ([TestFixture] tells nunit it's the test class)
[TestFixture]
public class MyNewClassTestClass
{
// Method for testing the method in the class above ([Test] tells nunit this is a test method)
[Test]
public void MyMethodTest()
{
// create an instance of the class
NewClass obj_newClass = new NewClass();
// Verify assertion
Assertion.Assert(obj_newClass.MyMethod(10, 20) == 30);
}
}
Test harness
Skeleton (computer programming)
Testing
Opinions expressed by DZone contributors are their own.
Comments