dotunit is a port of
JUnit (www.junit.org) to the Microsoft .net
platform. It provides a testing framework to support automated testing of
applications, particularly to facilitate unit, function and regression testing.
Testing is tedious and time
consuming. As a result, it is not a popular chore among developers and few do it
thoroughly, if at all. However, software must be tested to maintain quality and
More often than not, a
developer’s code does not work the first time (or the second, third…). The
debugging process is often interactive and iterative. This requires the repeated
testing of the same code.
The cost of testing does not
stop with initial debugging unfortunately. As the system develops and is
revised, regression testing is necessary to ensure previous sections still
function properly as new ones are added.
Automated testing frameworks
provide the developer with a method of capturing test cases and automate their
execution, validation and the collection of results. The cost of testing goes
down considerably and the developer can grow in confidence that the quality and
stability of his code is high, without the excessive cost of traditional
(For more on the value of
automated testing, please see http://junit.sourceforge.net/doc/testinfected/testing.htm )
After installing dotunit, open the project you
wish to test in the Visual Studio.net IDE.
Add a reference to dotunit.framework.dll (You may
need to browse to locate the dll)
In general, tests are methods in a class
that descends from dotUnit.Framework.TestCase. Each method that begins
with the word Test (case matters) is a test case.
Such functions take no arguments and should not return anything.
Each value that should be
tested is done with either:
void AssertTrue(bool expression)
(AssertEquals is overloaded for each
simple data type (bool, string, int, double, etc.) The general format is
message, expected value, actual value)
following is a simple test case.
SimpleTest : dotUnit.Framework.TestCase
contexts for a series of tests. Many tests will use a common set of
objects/state for testing. A fixture provides this common context. In order to
establish a fixture, override the SetUp
and TearDown (optional)
methods. SetUp will be called before any tests
are run and TearDown will be
called after the tests are run.
public class SimpleFixture:
override void SetUp()
public void TestSimpleCase()
are collections of tests. You can arrange a hierarchy of test cases, as suites
can contain other suites or test cases. Suites organize your tests.
In order to
define a suite, create a class that implements a Suite property (return a
public class MySuite:
suite = new
dotunit GUI can be used to run your tests.
browse to you compiled test cases (dll), select the class to test and click
Go. You will see the results in the Errors window. You can browse
the test hierarchy as well.
Running Tests from within a Test
Set a reference to
dotUnit.GUI. Assuming your test project is a console application, use the
following Main definition:
static void Main(string
In the above, MyTestCase is the TestCase and “TestSomething” is the
name of the test routine to run. If there are multiple tests/cases, it is
advisable to use a TestSuite
instead of a TestCase
(instead of MyTestCase).
Testing Internal / Private Classes and
it is useful to unit test internal and private methods, that support the
implementation of larger functionality. It is time consuming and error-prone to
toggle access modifiers between “public” and “private”.
dotunit provides several utility functions to allow for the
testing of non-public methods and classes. The following code snippet highlights
the functions. (Please see the documentation for dotUnit.Utility.NonPublicType and the
for more information.)
Type a =
above example, m_target is a reference to an object that has non-public