How to debug Nunit test in Visual Studio 2010

前端 未结 5 1397
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 02:11

I have a problem debugging an NUnit test from VisualStudio. I created an empty project (Console Application), then I added references to the NUnit library and wrote a simple tes

5条回答
  •  感情败类
    2021-02-04 02:47

    Assuming you're using a version of Visual Studio other than Express Edition then TestDriven.NET might be of use.

    After installing it

    1. Set a breakpoint within your test method
    2. Right click and choose Debugger from the Test With menu
    3. The debugger should launch and hit your breakpoint

    Unfortunately you can't use this method with Express editions of visual studio because TestDriven.NET is a plugin for visual studio and the Express editions do not support the use of plugins

    Running a test within a console app

    You can also run a test in the debugger via a console application:

    1. Create a new console application
    2. Reference your unit tests project
    3. Inside the Main method of the console application create a new instance of your test fixuture and then call one of the test methods. For example if I have a fixture named MyTests and a test named Test1 I'd write:

      var myTests = new MyTests();
      myTests.Test1();
      
    4. Set a breakpoint at the line where you create an instance of the MyTests class and press F5

    5. The debugger will hit your breakpoint and then you can use F11 to step into your TestFixture's constructor, or step over that into the test itself

提交回复
热议问题