Showing posts with label nunit. Show all posts
Showing posts with label nunit. Show all posts

Friday, July 22, 2011

4 nice ways to automate Test Runs in .NET

So far I've found the following convenient ways to run tests:

Using the Resharper plugin

This allows right clicking next to a Test method and selecting Run or Debug.

These two actions and a lot more can also be bound to keyboard combinations. My favourite are CTRL+' for Debug Test and CTRL+SHIFT+' for Run Test


Using the Testdriven.NET plugin

Testdriven.Net has a very nice twist: it not only allows running Test methods. It also allows running any method that is currently selected (the pointer is somewhere inside the body of the method). The only condition  for this to work is that the method must be either static or be defined inside a class that has a default (parameterless) constructor.
Note that if that method to run takes any parameters, TestDriven.Net will pass default values for them (null for reference types, default for value types).

I typically bind the CTRL+Q keystroke to running the current method with TestDriven.Net

Using the NUnit Test Runner

This one is especially useful when doing TDD: after loading an assembly in the NUnit test runner, go to the Tools -> Settings -> Assembly Reload and check all three boxes: 'Reload after each test run', 'Reload when test assembly changes' and 'Re-run last tests run'.

Now whenever you do a build, the assembly is automatically re-loaded in the runner tests are run for you.

Using the NUnit Test Command-line utility

The NUnit command-line test runnning utility can be plugged-in as a Post-Build event (set this up in the .NET Project configuration).

This way, each (successful) build will trigger a test run for the whole assembly.

Obviously, even if the code compiles, failing tests will fail the build (the NUnit test runner will return an error code).