Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

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

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 works well if I load up my unit tests from Nunit (v2.4), but I've got to the point where it would be really useful to run in debug mode and set some break points.

I've tried the suggestions from several guides which all suggest changing the 'Debug' properties of the test project:

Start external program: C:Program FilesNUnit 2.4.8in
unit-console.exe
Command line arguments: /assembly: <full-path-to-solution>TestDSPinDebugTestDSP.dll

I'm using the console version there, but have tried the calling the GUI as well. Both give me the same error when I try and start debugging:

Cannot start test project 'TestDSP' because the project does not contain any tests.

Is this because I normally load DSP.nunit into the Nunit GUI and that's where the tests are held?

I'm beginning to think the problem may be that VS wants to run it's own test framework and that's why it's failing to find the NUnit tests?

Edit: To those asking about test fixtures, one of my .cs files in the TestDSP project looks roughly like this:

namespace Some.TestNamespace
{
    // Testing framework includes
    using NUnit.Framework;

    [TestFixture]
    public class FirFilterTest
    {
        [Test]
        public void Test01_ConstructorTest()
        {
            ...some tests...
        }
    }
}

...I'm pretty new to C# and the NUnit test framework so it's entirely possible I've missed some crucial bit of information ;-)

Final Solution: The big problem was the project I'd used. If you pick Other Languages -> Visual C# -> Test -> Test Project ...when you're choosing the project type, Visual Studio will try and use it's own testing framework as far as I can tell. You should pick a normal C# class library project instead and then the instructions in my selected answer will work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When I need to debug my NUnit tests, I simply attach to the NUnit GUI application nunit-agent.exe using "Debug|Attach to Process" and run the tests from the GUI. Any breakpoints in my tests (or the code they're testing) are hit. Am I misunderstanding your question, or will that work for you?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...