How can I get started using Nunit in my Visual Studio project?
I want to start using Nunit (finally), I am using Visual Studio 2008.
Is it as simple as importing Nunit into my test project?
I remember seeing a GUI for NUnit, does that do the exact same thing that a separate test project would do, except show you the pass/fail visually?
I like to add a link to NUnit in my external tools.
Under Tools->External Tools add NUnit
Title: &NUnit Command: <path to nunit> Arguments $(ProjectFileName) /run Initial directory: $(ProjectDir)
After that you can quickly run it by compiling then hitting alt-t + n
Having a test project which runs nunit-gui or nunit-console separately is all very well, but you really want the whole unit testing experience to be as seamless as possible. The easier it is to write and run tests, the more likely you are to do it - which is a very good thing. Don't underestimate the gradual build-up of frustration due to a slightly poorer user experience, flipping between windows etc.
NUnit is something that isn't inside Visual Studio 2008. It does have a console OR a graphical user interface (gui) that can be run both outside VS2008 OR can be attached to the process of VS2008 for debugging.
If you do want something inside VS2008 you need to have a third party pluging like ReSharper.
Edit: This has been answered in the past (not for VS2008 specificly but still relevant)
I've used TestDriven.NET with VS2005, and it has changed how I develop and test code.
You can run all of the tests on any class, module, project, or solution. You can also run a test in the debugger, which is tremendously useful to diagnose and fix issues when they crop up.
The GUI is nice, but if you run your tests often, you'll probably abandon it for a faster/integrated runner.
In any case, you have some options on how to run your tests:
- NUnit.Gui.Exe -- you can run this & select your test project dll to run the tests. While it is open it will refresh when you build, so you can ALT-TAB to it & re-run your tets. Another technique I've seen is to set this application as the startup program for your test project. Then set your test project as the startup project and push F5.
- Download & use TestDriven.net. This is fast and lets you run tests from a right click menu, while you're sitting on a test or at a node in the solution explorer. This is what I use mostly. I have it mapped to CTRL+T for quick access.
- Resharper has a test runner as well. This gives you the GUI with red/green lights inside of visual studio. It also gives you a little icon next to each of your tests to quickly run them.
You can use the plugin NUnitForVS that is available here: http://www.codeplex.com/NUnitForVS
This integrates the test running and results in your VS 2008 IDE. We've been using it for a couple of months and it's working well for us.
You should also remember that with VS 2008 professional you can use the MS Unit testing tool that was previously only available in the team versions.
You can run it as external program, but as for me it is not very nice. I like, when test starts within the VS. So, if you have ReSharpe you can go to Tools -> Options -> Environment -> Keyboard and set the hot key for ReSharper_UnitTest_ContextRun. I set it to Ctrl + t.
I attach my nunit console program to the Post-build event so every time I build my project the tests are run without the need for third party tools (apart from NUnit). I'm using Visual Studio 2010, but I am pretty sure you can achieve the same behaviour in Visual Studio 2008.
To do this:
- Open the project's properties window (the project containing the tests)
- In the Post-build event command line add the line: "C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe" "$(TargetDir)$(TargetFileName)"
Build the project and the output should be written to the Ouptput window (Build). It's important to choose the x86 version of the console runner.