Over a million developers have joined DZone.

Skeleton C# Class With Test Harness (

DZone's Guide to

Skeleton C# Class With Test Harness (

Free Resource
Using 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)
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);



Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}