Wednesday, January 23, 2008

How to debug dll by using NUnit

Keywords: NUnit, Unit Test, Visual Studio


这里是一个精简版使用NUnit来测试一个Class Library的步骤. 这个方法比通过NUnit GUI的菜单File/Open Project方便, 因为后者在调试程序时候, 不得不在Visual Studio的Tools/Attach to Process中为Debuger绑定一个Host程序(Attach NUnit.exe). 然后才能设置断点.


或者是为VS安装UnitRun -(Resharper tool) 或TestDriven.NET 插件, 也可以很方便地在VS中直接使用NUnit进行测试.


另有一个blog更详细地说明了怎样使用NUnit.


下面的方法, 不需要任何VS插件, 却可以很方便地调试dll:(适用于 Visual Studio Standard or higher, 不适用于Express版)


1.Place a breakpoint at the first line of the TestAdd method.


2.Right-click on the L100MathTests project in Solution Explorer and select Properties.


Select the Debug tab and fill in the following options:


Start External Program text box : C:\Program Files\NUnit-Net-2.0 2.2.8\bin\nunit-gui.exe 或者 nunit.exe

Command Line Arguments text box: L100MathTests.dll

Working Directory text box: C:\L100MathLib\L100Math\L100MathTests\bin\Debug\

3. Select Debug | Start Debugging from the main menu or use the F5 shortcut.


4. Switch to the NUnit GUI application and double-click on the TestAdd method. The breakpoint that you previously set should be hit and a yellow cursor and line will be shown.

5.Select Debug | Step Into from the debugger main menu to enter the MathHelper.Add method.

No comments: