Mathieu
Mathieu

Reputation: 4520

NUnit debugging a single test

I use NUnit plugin from ReSharper. I can't find any way of debugging a single test. The BUG button always launches all the tests, even when I launch the debug specifically from one test method.

I'm trying to reach a breakpoint with one specific test and I don't want to reach it with the other tests.

Do you know any way of doing this? Google didn't help me on this one...

Example of my test code

[Test]
public void IsValidDoer_DoerValid()
{
    var mockRepositoryDoer = new Mock<IDoerRepository>();
    mockRepositoryDoer.Setup(c => c.ActiveDoers).Returns(activeDoers.AsQueryable);

    var doerValidation = new DoerValidation(mockRepositoryDoer.Object);

    Assert.IsTrue(dModel.IncludedDoers.Any());
}

[Test]
public void IsValidDoer_DoerInvalidNoQuota()
{
    var mockRepositoryDoer = new Mock<IDoerRepository>();
    var activeDoers = listDoers.ToList();
    activeDoers.First().QuotaActivity.Clear();
    mockRepositoryDoer.Setup(c => c.ActiveDoers).Returns(activeDoers.AsQueryable);

    var doerValidation = new DoerValidation(mockRepositoryDoer.Object);

    Assert.IsFalse(dModel.IncludedDoers.Any());
}

Upvotes: 9

Views: 2762

Answers (4)

krystan honour
krystan honour

Reputation: 6783

Yes Alongside the code is a green and yellow mark just click this and click run it will run that single test. You just left click it once you will get options and depending on what you also have installed from Jetbrains you could launch code coverage from here too.

You can also choose to append it to an already existing session of other tests or create it in a session all on its own.

Resharper test

Clarification:

Someone downvoted this so I went back and took a look and tested it both for MSTEST and NUnit. it is true it is not desirable to execute the 15 tests if you only wish to debug one. The test was conducted in visual studio 2015 with Resharper 10 and visual studio 2013 with Resharper 8. If you click on the mark in the individual test file it will indeed only run the code once.

If you run multiple tests and get a test session in Resharper's runner with three tests it will, on right click, show "debug tests", however if you only select one it only runs one test and so only hitting the code only once.

Upvotes: 4

syclee
syclee

Reputation: 697

I had same issue. When trying to debug single test by clicking on the circle and selecting 'Debug (bug icon)' it would Debug for all unit tests.

I resolved it by upgrading Resharper. I upgraded from Resharper Ultimate 10.0.1 to 10.0.2.

Upvotes: 1

Niels van Reijmersdal
Niels van Reijmersdal

Reputation: 2035

We also where having the same issue when using ReSharper 10 as the test runner. It would run all the tests, even if I configured only a single test in the session. Also it would run all tests when I used the right click on the test ball for this test.

After installing the NUnit3 Test Adapter under Tools->Extensions and Updates->Online I could debug the tests from the regular Test Explorer of Visual Studio 2015 by right clicking and selecting Debug selected tests. This does only run this one test :)

Upvotes: 1

escargot agile
escargot agile

Reputation: 22379

Try to right-click the code of the specific test. You should see "Debug Unit Test" or something like this in the context menu.

Upvotes: 0

Related Questions