Guerrilla
Guerrilla

Reputation: 14866

Nunit not hitting breakpoints in test project class library (VS2012)

I have a console application and I added a class library solution to the project to hold all my unit tests.

All is working fine apart from the fact that breakpoints do not get hit when I run my tests.

If I run the whole application, breakpoints on the console app get hit fine.

If I run the tests, breakpoints in the test classes and the console app are completely ignored.

I saw another post saying to go to debug > start new instance, but as it is a class library I cannot do this. Should I have test classes in a different project type?

I am using Nunit, VS2012 and the NUnit runners.

I have a couple of tests failing and I cant figure out why, I really need to be able to step through the code.

Any help is greatly appreciated.

Upvotes: 15

Views: 6462

Answers (4)

Andreas Forslöw
Andreas Forslöw

Reputation: 2738

In my case a line of code seemed to execute a never-ending loop, which made it impossible to reach the breakpoint.

Solution: Put a breakpoint in the beginning of the debug method in order to check for this error!

Upvotes: 1

Leo
Leo

Reputation: 14820

Instead of running your tests, try debugging your tests

enter image description here

Upvotes: 32

AJ Richardson
AJ Richardson

Reputation: 6820

For anyone else having this issue: check if you are building in Release mode.

I had this problem with NUnit 3.7.0, and dotnet core 1.0, and VS 2017. It turned out that I was building in Release mode. Building in Debug mode fixed the issue.

Upvotes: 11

Prashanjit Ghosh
Prashanjit Ghosh

Reputation: 31

My test code was compiled in .Net 4.5 and was using the Nunit2.6.1.

The breakpoints were not getting hit if I had only made the test project's debug option->start external program->nunit-86x.exe and give the .dll name to be the command line argument.

This starts off the Nunit exe but without breakpoints.

1) To solve this go to

C:\Program Files (x86)\NUnit 2.6.1\bin

2) Search for nunit-x86.exe.config or if you plan to use the nunit.exe then open nunit.exe.config.

3) Open the fine in notepad and search for the line

<startup useLegacyV2RuntimeActivationPolicy="true">
<!-- Comment out the next line to force use of .NET 4.0 -->
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0.30319" />
</startup>

4) Remove the line of supported Runtime version=v2.0.50727 and save the file(open in administrator mode by opening notepad in admin by right click and open as admin).

5) Rebuild project the run your test code's debug session. The breakpoints will be hit.

Upvotes: 3

Related Questions