DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Skeleton C# Class With Test Harness (

  • submit to reddit
        Using SnippetCompiler ( 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)
public class MyNewClassTestClass
        // Method for testing the method in the class above ([Test] tells nunit this is a test method)
		public void MyMethodTest() 
            // create an instance of the class
			NewClass obj_newClass = new NewClass();
            // Verify assertion
			Assertion.Assert(obj_newClass.MyMethod(10, 20) == 30);