How do I run NUnit in debug mode from Visual Studio?

后端 未结 19 1240
闹比i
闹比i 2020-11-30 17:59

I\'ve recently been building a test framework for a bit of C# I\'ve been working on. I have NUnit set up and a new project within my workspace to test the component. All wor

相关标签:
19条回答
  • 2020-11-30 18:14

    I use the same technique as you are trying Jon, without the /assembly flag, i.e.

    Start External Program: C:\Program Files\NUnit 2.4.8\bin\nunit.exe
    
    Command line arguments: "<path>\bin\Debug\Quotes.Domain.Tests.dll"
    

    Does TestDSP.dll contain all your TestFixtures?

    As my test project is not the startup project in the solution, I run my tests by right-clicking on the test project and choosing Debug --> Start New Instance

    0 讨论(0)
  • 2020-11-30 18:14

    Now with pictures:

    1. Run NUnit gui (Download 2.6.2 from here) then go to File -> Open Project

    1. Select your test .dll from bin folder (C:\......\[SolutionFolder][ProjectFolder]\bin\Debug\xxxxTests.dll)

    2. Go to Visual Studio Debug -> Attach to process (Attach to process window will open)

    3. From the list scroll down and select nunit-agent.exe then click Attach

    1. At this point breakpoints in your tests should turn ripe red (from hollow).

    2. Click Run on Nunit Gui and you should get your breakpoint hit...

    Hope this saves you some time.

    0 讨论(0)
  • 2020-11-30 18:18

    Regarding what Mr. Patrick McDonald said

    As my test project is not the startup project in the solution, I run my tests by right-clicking on the test project and choosing Debug --> Start New Instance

    I tried to apply for my test class library but got some error regarding the path, so I tried to remove the 'Command Line Arguments', and luckily it worked well and as expected.

    0 讨论(0)
  • 2020-11-30 18:18

    There is also an extension now "Visual NUnit" that will allow you to run the tests from within Visual studio much like the build in test framework handles. Check it out its in the extension manager.

    0 讨论(0)
  • 2020-11-30 18:20

    Open Visual Studio ---> your Project---> Select 'Properties'---> Select 'Debug' --> Select 'Start external program' and set the path of your NUnit there(Eg: Start external program = C:\Program Files\NUnit 2.6.2\bin\nunit.exe) ---->Save

    After setting this just click Debug

    0 讨论(0)
  • 2020-11-30 18:22

    If you are using NUnit 2.4 or newer you can put the following code in your SetUpFixture class. (You can do this with older versions but you will need to do whatever equivalent that has to the SetUpFixture, or copy it in to the test itself.)

    [SetUpFixture]
    public class SetupFixtureClass
    {
        [SetUp]
        public void StartTesting()
        {
            System.Diagnostics.Debugger.Launch();
        }
    }
    

    What Debugger.Launch() does is cause the following dialog to show up when you click Run inside NUnit.

    JIT Debugger Dialog

    You then choose your running instance of visual studio with your project open (the 2nd one in my screenshot) then the debugger will be attached and any breakpoints or exceptions will show up in Visual Studio.

    0 讨论(0)
提交回复
热议问题