In an earlier blog post I described how to use Nunit for unit testing in Visual Studio Express. One short coming of this strategy is that you can’t easily debug your tests. This is because Visual Studio Express doesn’t seem to let you attach external processes. (We would need to attach the external Nunit process to step into the code).
To get around this rather annoying problem, I have created my own testing framework; ExpressUnit. The current version of ExpressUnit is now 3.x. The latest version offers two new benefits over previous versions:
- The new UI interface has been created using WPF
- ExpressUnit 3.x supports continuous integration with Hudson which means you can use ExpressUnit to run your tests on your build server. In my current development environment I have configured ExpressUnit to run all tests on every code check-in. My continuous Integration environment is currently set up using Subversion, Hudson and ExpressUnit.
Instead of relying on an external application to run the tests, ExpressUnit will run from within your Visual Studio Solution. The idea is that you download ExpressUnit in the form of a Visual Studio project and add it to your solution.
The added project becomes your unit test project where you may add your test classes with the belonging unit tests. No configuration is required.
To add tests, simply add a test class with public test methods. The class and methods must be decorated with the [TestClass] and [UnitTest]/[ItegrationTest ] attributes respectively. The unit test attribute should be used for unit tests and the Integration test attribute is meant for integration tests. ExpressUnit will let you filter test runs on these attributes.
It’s usually my preference to add all my tests to the ExpressUnit project, but ExpressUnit allows for tests to be defined in any project in your solution (as long as the ExpressUnit project has a reference to it).
Anyway, that’s enough background information! To make this as useful as possible I will demonstrate how to use ExpressUnit through an example.
Step1:
Download ExpressUnitGui from
http://code.google.com/p/expressunit/
Step2:
Add the ExpressUnitGui project to your already existing Visual Studio 2008 solution.
After completing this step, your solution will look similar to Figure1

Figure1
Step3:
Start writing your first ExpressUnit test.
As mentioned earlier, you must start by adding a test class with at least one test method to the ExpressUnitGui project. The class may look something like the following:
[TestClass]
public class SampleTest
{
[UnitTest]
public void AddTest()
{
MathClass math = new MathClass();
Confirm.Equals(4,math.Add(1,3));
}
}
Step4:
Run your test!
To run your tests, select ExpressUnitGui as your startup project and press F5
The UI window will load with a simple interface to execute one or more of your tests. (Figure2). You may run entire test suits or individual test by right clicking the appropriate tree node in the tree view, but to run all tests at once, all you have to do is click the green “Play” button. The test results are shown in the right pane, and as you can see in Figure2, each test result offers an expand button to view more details about failing tests.
There is also an option to run all tests automatically on start-up of ExpressUnit. This feature is controlled by the runTestsOnStartup flag in the application’s App.Config (Default value is false)

Figure2
API
The following is an overview of the API offered by ExpressUnit
Confirm methods
The confirm class contains several static methods used to confirm the outcome of your tests
Confirm.Equals(object obj1, object obj2):
This method compares two objects for equality by using the object’s own Equals implementation.
Confirm.Equals will throw EqualsException if the two objects are not equal.
Confirm.Different(object obj1, object obj2):
This method is the inverse of Confirm.Equals, and is used to check if two objects are unequal.
UnEqualityException is thrown if the two objects are equal.
Confirm.IsGreater(long/double val1, long/double val2)
This method is used to test if val1 is numerical bigger than val2
Confirm.SameCollections(IEnumerable param1, IEnumerable param2)
This method will test if two objects of type IEnumerable are the “same”, and the definition of “same” is that all contained objects are equal.(based on the contained object’s own Equal implementation. For example, it may be used to compare the content of two arrays or collections.
EqualityException is thrown if the two instances are not the “same”.
Confirm.ExceptionThrown(Type expectedExceptionType,TargetMethod target)
This method will check if the target method throws the expected exception. The target method is passed in as a delegate of type TargetMethod.
Attributes
The following are attributes defined by ExpressUnit
[TestClass]
This attribute defines a class as a test class.
[UnitTest]
This attribute defines a method as a unit test
[IntegrationTest]
This attribute defines a method as an integration test
[Ignore]
This attribute will cause a test to be ignored when running your tests
[ExceptionThrown(Type exceptionType)]
This attribute can be put on a test to indicate that an exception of type exceptionType is expected to be thrown. The test will fail if the exception is not thrown.
Conclusion
If this this article has made you curious about ExpressUnit, you may download it from
http://code.google.com/p/expressunit/
Don’t hesitate to drop me a line if you have comments or would like to see additional functionality in ExpressUnit.