NUnitRunOverMe

 

What Is This

Runs NUnit.ConsoleRunner from Visual Studio

with results in the output window.

Double-clicking lines in the output windows which reference the source, jump to that related line; making it easy to goto the source for an error.

 

Why Bother

The console runner presents a nice stand-alone summary showing which tests passed or failed, but it is not well integrated with the VS IDE:

Starting console runner requires extra steps, even if you are using a 3rd party tool bar.

 

The results appear in a separate window outside of VS, forcing to switch windows to see the errors and then the code.

 

          Finding the source of test failures is more difficult than it has to be.

 

The console window is closed at the end of the tests. Yes, you could add a Console>ReadKey() at the end of your tests, but then the tests will hang when run during an unattended build.

 

Finally, if you apply some changes to the source you will have to quit the application first, closing the console window.

 

 

How NUnitRunOverMe Helps

NUnitRunOverMe offers these features:

<F5> One key no brainer start runs your unit tests.

 

All output from NUint and your code is captured by the VS output window, not just Debug.WriteLine output.

 

After your tests run to completion, the output is still available.

 

You may visit the source of errors by clicking in the output window.

 

 

See Also

NUnitRunOverMeDemoLibTestsToRun.cs

 

Getting Started

NUnitRunsOverMe allows you to separate UnitTests from your deliverable code. One project contains your NUnit related code. Other projects are deliverable libraries. (dll’s)

 

Steps

Create a solution, with one or more projects including:

Class(es) to test. Your deliverable code.

Classes which contain the UnitTests

Normally these will be in separate assemblies, but that is not a requirement.

 

In Solution properties:

Set UnitTests project as startup project.

 

In the UnitTest Project:

Add NUnit required references. (See Below)

Add NUnitRunOverMe.cs (See I Hate Cut & Paste)

Drag&Drop/Link this file into the UnitTests project. (add existing item | Link)

Set startup object to: NUnitRunOverMe.main

 

Now when you hit <F5> in this solution the UnitTests are run. You output appears in VS, and you can visit errors.

 

The classes can still be invoked by NUnit standalone as usual.

Required References

You can cut & paste these into your .csproj file

<Reference Include="nunit-console-runner, Version=2.4.1.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />

<Reference Include="nunit.framework, Version=2.4.1.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />

 

Or through Visual Studio (References | Add Reference | Browse)

C:\Program Files\NUnit 2.4.1\bin\nunit-console-runner.dll

C:\Program Files\NUnit 2.4.1\bin\nunit.framework.dll

 

 

Example

 

NUnitRunOverMeDemo.zip

 

DemoLib is a very simple example library class to get you started with NUnit.

 

DemoTests is an example of how to report UnitTest results using the NUnit Framework. It also shows how to use NUnitRunOverMe.

 

 

The expected output includes a failure in each test.

(The ReadKey() allows you to see what is going on. It is for demonstration purposes only.)

 

See DemoLibTests.cs for additional notes on getting started with NUnit.

 

Expected Output

The Console Window

NUnit version 2.4.1

Copyright (C) 2002-2007 Charlie Poole.

Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.

Copyright (C) 2000-2002 Philip Craig.

All Rights Reserved.

 

Runtime Environment -

   OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3

  CLR Version: 2.0.50727.1433 ( Net 2.0.50727.1433 )

 

.F.F.F

Tests run: 3, Failures: 3, Not run: 0, Time: 0.219 seconds

 

Failures:

1) NUnitRunOverMeDemoTestsToRun.additionTests :   Expected: 3

  But was:  4

 

   at NUnitRunOverMeDemoTestsToRun.additionTests() in C:\NUnitRunOverMeDemo.2008.11.21.14.25.04\DemoTests\DemoTests.cs:line 60

 

2) NUnitRunOverMeDemoTestsToRun.divideByZeroTest :   Expected: True

  But was:  False

 

   at NUnitRunOverMeDemoTestsToRun.divideByZeroTest() in C:\NUnitRunOverMeDemo.2008.11.21.14.25.04\DemoTests\DemoTests.cs:line 93

 

3) NUnitRunOverMeDemoTestsToRun.divisionTests :   Expected: 5

  But was:  4.0d

 

   at NUnitRunOverMeDemoTestsToRun.divisionTests() in C:\NUnitRunOverMeDemo.2008.11.21.14.25.04\DemoTests\DemoTests.cs:line 76

 

 

NUnit output is in the IDE output window. View | Output or Ctl+ Alt + O

Press Enter to continue.

The Visual Studio Output Window

###########################    Starting up      ############################

################################ UNIT TESTS ################################

Running tests in 'C:\NUnitRunOverMeDemo\DemoTests\bin\Debug\NUnitRunOverMeDemoLibTestsToRun.exe'...

Entering NUnitRunOverMeDemoTestsToRun.additionTests

A first chance exception of type 'NUnit.Framework.AssertionException' occurred in nunit.framework.DLL

 after an exception failure NUnit continues?

 Yes!

A first chance exception of type 'NUnit.Framework.AssertionException' occurred in nunit.framework.DLL

Entering NUnitRunOverMeDemoTestsToRun.divisionTests

A first chance exception of type 'NUnit.Framework.AssertionException' occurred in nunit.framework.DLL

############################################################################

##############                F A I L U R E S              #################

1) NUnitRunOverMeDemoTestsToRun.additionTests :

  Expected: 3

  But was:  4

at

C:\NUnitRunOverMeDemo.2008.11.21.14.25.04\DemoTests\DemoTests.cs(60)

2) NUnitRunOverMeDemoTestsToRun.divideByZeroTest :

  Expected: True

  But was:  False

at

C:\NUnitRunOverMeDemo.2008.11.21.14.25.04\DemoTests\DemoTests.cs(93)

3) NUnitRunOverMeDemoTestsToRun.divisionTests :

  Expected: 5

  But was:  4.0d

at

C:\NUnitRunOverMeDemo.2008.11.21.14.25.04\DemoTests\DemoTests.cs(76)

############################################################################

Executed tests       : 3

Ignored tests        : 0

Failed tests         : 3

Unhandled exceptions : 0

Total time           : 0.21875 seconds

############################################################################

###########################  Some Tests Failed. ############################

 

To visit the source for an error, double click the error message location in the output window.

These lines end with a line number and are of the form:

C:\dir1\dir2\solution\project\sourcefile.cs (99)

If you double click other lines the IDE quietly ignores you.

 

I Hate Cut & Paste

I hate cut & paste. It is the fastest way to propagate bugs. I originally had NUnitRunOverMe.cs in it own DLL. In fact I recommend that, always. But, for the purposes of this example, I wanted the simplest set of steps. Three Assemblies and the required references seem like a bit much to test two one-line functions.

 

On a large project with many assemblies, it makes sense to have a single copy of NUnitRunOverMe.cs in an assembly. This assembly will grow to include other useful primitives, such as MyMethodFullName(), TraceIn() and TraceOut.

Updated 11/21/2008 2:43:22 PM