Debugging Unit Tests
From OpenSimulator
(→Debugging Unit Tests with Vistual Studio) |
m (Robot: Replacing 'OpenSim' to 'OpenSimulator', which is the precise name) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | __NOTOC__ | ||
+ | {{Quicklinks}} | ||
+ | <br /> | ||
Debugging unit tests is useful for both test driven development and resolving build failures. | Debugging unit tests is useful for both test driven development and resolving build failures. | ||
== Debugging Unit Tests with Visual Studio == | == Debugging Unit Tests with Visual Studio == | ||
+ | |||
+ | === Visual Nunit Addin (Open Source) === | ||
+ | |||
+ | 1) Download and install Visual Nunit: http://www.bubblecloud.org/visualnunit | ||
+ | |||
+ | 2) Open Solution in Visual Studio. | ||
+ | |||
+ | 3) Ensure that your projects have copy local enabled on all dependencies which are not in GAC. (Tests are executed in project bin/Debug folder) | ||
+ | |||
+ | 4) Open NUnit View from menu: View -> Other Windows -> NUnit View | ||
+ | |||
+ | If no tests are visible then projects do not contain NUnit tests or dependencies are not available in project/bin/Debug folder. | ||
+ | |||
+ | 6) Start debugging by clicking the red arrow in the beginning of the test row. | ||
+ | |||
+ | 7) Debug as you would debug any executable on Visual Studio. | ||
+ | |||
+ | === NUnit GUI === | ||
1) Download and install NUnit which includes NUnit GUI. | 1) Download and install NUnit which includes NUnit GUI. | ||
Line 11: | Line 32: | ||
4) Open project and choose the test dll you want from OpenSim/bin directory (for example OpenSim.Data.MySQL.Tests.dll) | 4) Open project and choose the test dll you want from OpenSim/bin directory (for example OpenSim.Data.MySQL.Tests.dll) | ||
− | 5) Open your | + | 5) Open your OpenSimulator solution to Visual Studio. |
6) Attach NUnit GUI process to Visual Studio by choosing Debug -> Attach to Process. | 6) Attach NUnit GUI process to Visual Studio by choosing Debug -> Attach to Process. | ||
Line 19: | Line 40: | ||
8) Execute unit tests from NUnit GUI and Visual Studio should let you debug at the chosen break points. | 8) Execute unit tests from NUnit GUI and Visual Studio should let you debug at the chosen break points. | ||
+ | Note: Alternatively you can add the NUnit GUI to the Visual Studio as external tools so you can start it from Tools menu. | ||
Note: This seems to be an option for the Professional Editions of Visual Studio. The Express Edition (the free one) seems to have no Debug->Attach to Process option. | Note: This seems to be an option for the Professional Editions of Visual Studio. The Express Edition (the free one) seems to have no Debug->Attach to Process option. | ||
+ | * You might be able to work around this by downloading nunit gui sources and building and running it from the the express edition. You need to have the nunit gui project added to the solution you want to debug. | ||
+ | |||
+ | == Debugging Unit Tests with Visual Studio Express 2008 == | ||
+ | |||
+ | Microsoft obviously has removed the capability to run an external program to load and debug an assembly. | ||
+ | |||
+ | "Obviously" as there is no way to activate this feature from the GUI. But the underlying engines still have all features included that you need. And there is a way to make the necessary settings. The following steps will help you to achieve your goal: | ||
+ | |||
+ | 1. Close your solution first, in case you have it open | ||
+ | |||
+ | 2. Find the file XXX.csproj.user where XXX is the DLL that holds your unit tests. | ||
+ | |||
+ | 3. Open it with an editor and find the "<PropertyGroup>" tag. | ||
+ | |||
+ | 4. Add the following lines beyond the <PropertyGroup> tag: | ||
+ | <PropertyGroup> | ||
+ | ... | ||
+ | <StartAction>Program</StartAction> | ||
+ | <StartProgram>D:\NUnit248\bin\nunit.exe</StartProgram> | ||
+ | ... | ||
+ | </PropertyGroup> | ||
+ | |||
+ | Of course you must put the right path to ''your'' nunit.exe into it. | ||
+ | |||
+ | 5. Open the solution again | ||
+ | |||
+ | 6. Now set the Test DLL you just modified as "startup project" and press F5. You will get a NUnit GUI running under the debugger. Put breakpoints to your code and debug as you like, let your code run as often as you want ..... | ||
+ | |||
+ | Happy Debugging :-) | ||
+ | |||
+ | This procedure was taken from the following link: http://stewartr.blogspot.com/2006/09/debugging-nunit-in-visual-studio.html which lbsa71 provided. | ||
== Debugging using TestDriven.net == | == Debugging using TestDriven.net == | ||
− | + | OpenSimulator comes with a "testing" file that mentions a tool name "TestDriven.net". It looks good when you visit the page (http://www.testdriven.net) and there is a lot of positive feedback about it. | |
Anybody who has experience with it: please write a bit about it here. | Anybody who has experience with it: please write a bit about it here. | ||
Unfortunately it is a plugin and it seems that Microsoft removed support for plugins from Visual Studio 2008 Express (the free edition). So if you are working with this (like I) TestDriven.net unfortunately isn't an option. | Unfortunately it is a plugin and it seems that Microsoft removed support for plugins from Visual Studio 2008 Express (the free edition). So if you are working with this (like I) TestDriven.net unfortunately isn't an option. |
Latest revision as of 22:20, 3 March 2012
Debugging unit tests is useful for both test driven development and resolving build failures.
[edit] Debugging Unit Tests with Visual Studio
[edit] Visual Nunit Addin (Open Source)
1) Download and install Visual Nunit: http://www.bubblecloud.org/visualnunit
2) Open Solution in Visual Studio.
3) Ensure that your projects have copy local enabled on all dependencies which are not in GAC. (Tests are executed in project bin/Debug folder)
4) Open NUnit View from menu: View -> Other Windows -> NUnit View
If no tests are visible then projects do not contain NUnit tests or dependencies are not available in project/bin/Debug folder.
6) Start debugging by clicking the red arrow in the beginning of the test row.
7) Debug as you would debug any executable on Visual Studio.
[edit] NUnit GUI
1) Download and install NUnit which includes NUnit GUI.
2) Start NUnit GUI
3) Enable Visual Studio Support from Tools->Options-IDE Support->Visual Studio
4) Open project and choose the test dll you want from OpenSim/bin directory (for example OpenSim.Data.MySQL.Tests.dll)
5) Open your OpenSimulator solution to Visual Studio.
6) Attach NUnit GUI process to Visual Studio by choosing Debug -> Attach to Process.
7) Set break points in visual studio.
8) Execute unit tests from NUnit GUI and Visual Studio should let you debug at the chosen break points.
Note: Alternatively you can add the NUnit GUI to the Visual Studio as external tools so you can start it from Tools menu.
Note: This seems to be an option for the Professional Editions of Visual Studio. The Express Edition (the free one) seems to have no Debug->Attach to Process option.
- You might be able to work around this by downloading nunit gui sources and building and running it from the the express edition. You need to have the nunit gui project added to the solution you want to debug.
[edit] Debugging Unit Tests with Visual Studio Express 2008
Microsoft obviously has removed the capability to run an external program to load and debug an assembly.
"Obviously" as there is no way to activate this feature from the GUI. But the underlying engines still have all features included that you need. And there is a way to make the necessary settings. The following steps will help you to achieve your goal:
1. Close your solution first, in case you have it open
2. Find the file XXX.csproj.user where XXX is the DLL that holds your unit tests.
3. Open it with an editor and find the "<PropertyGroup>" tag.
4. Add the following lines beyond the <PropertyGroup> tag:
<PropertyGroup> ... <StartAction>Program</StartAction> <StartProgram>D:\NUnit248\bin\nunit.exe</StartProgram> ... </PropertyGroup>
Of course you must put the right path to your nunit.exe into it.
5. Open the solution again
6. Now set the Test DLL you just modified as "startup project" and press F5. You will get a NUnit GUI running under the debugger. Put breakpoints to your code and debug as you like, let your code run as often as you want .....
Happy Debugging :-)
This procedure was taken from the following link: http://stewartr.blogspot.com/2006/09/debugging-nunit-in-visual-studio.html which lbsa71 provided.
[edit] Debugging using TestDriven.net
OpenSimulator comes with a "testing" file that mentions a tool name "TestDriven.net". It looks good when you visit the page (http://www.testdriven.net) and there is a lot of positive feedback about it.
Anybody who has experience with it: please write a bit about it here.
Unfortunately it is a plugin and it seems that Microsoft removed support for plugins from Visual Studio 2008 Express (the free edition). So if you are working with this (like I) TestDriven.net unfortunately isn't an option.