GoogleTest: How to set a breakpoint? - c++

I'm using Visual Studio 2010 C++ with Google test. I have a post-build event on my test project to run the test project. This works and the google test test results are displayed in the visual studio output window. However, now I'd like to set a debug breakpoint to step through a test. When I set a break point in either my test code or in the code it calls nothing happens.
How can I set a breakpoint with google test? Or probably more accurately, how can I get it to trigger the debugger?

I guess you have a separate project that builds the test. You should just run it under the debugger.

Related

Possible to turn off automatic run of tests in Visual Studio 2017 every time I build my local solution?

I have a solution that includes many tests, but I don't want to automatically run the tests every single time I build. Is there a way to do this in Visual Studio 2017?
I've checked Tools/Options. I've searched for this question in Stack Overflow, but don't find this question.
I've also checked the Solution Properties, but I don't see anything.
This question isn't a duplicate of this Stack Overflow question How to Prevent automatic test execution because it deals with the web portal and not Visual Studio 2017 IDE, itself.
Have you tried disabling "Run Tests After Build" from the Test Explorer window's toolbar? It should be the first button on the toolbar.
To open the Test Explorer window, go to Test -> Windows -> Test Explorer.
You first go to Test in the main menu, then go to Windows and then under the Windows, Run Tests After the Build button

visual studio code unit test discovery frequency setting

When I'm updating my existing unit tests, Visual Studio code drops a status bar from the top letting me know that it could not correctly discover unit tests every time I save the file. This is expected since I'm actively typing so everything is not working python.
Have I configured something incorrectly? Is there some way to tell visual studio to chill out on the unit test discovery?
Of course, I can simply hit the "close" button, but this is extremely distracting.
Disable Live Unit Test running on the background.
Under Test->Test Settings-> uncheck 'Keep Test Execution Engine Running'. I am using VS 2017 & VS 2015.

Keyboard shortcut for debugging the LAST test run in Visual Studio IDE (2013)

I know there are several VS keyboard shortcuts for running unit tests, but the one I really can't find and would like is to be able to run the last executed test in debug mode.
Ctrl+R, L will repeat the last run, but not in debug mode.
If you are debugging a test, and it changes context to the code you are actually running, and then you stop the test, is there a way to start that test in debug mode again using just the keyboard?
I wanted the same thing.
Based on the technique found in the following post
Visual Studio 2012 debug tests keyboard shortcut
I searched for TestExplorer.DebugSelectedTests and assigned a shortcut key to it.
At least in VS2015 (and hopefully in VS 2013) even while debugging changes context to the code you are actually running. The test remains selected in the test explorer window. So, you can run your shortcut key combo and the test will debug again.
Hope this solves the problem for you too.
I know this question was for Visual Studio 2013, but got google go me here.
In Visual Studio 2019 is a shortcut for that Ctrl+R,D:
If you are using ReSharper, you can use Ctrl+U, D to rerun a test in Debug mode.
https://www.jetbrains.com/resharper/features/unit_testing.html

Can't debug test using breakpoint in Visual Studio 2013

I'm trying to debug a failing unit test by putting a breakpoint at the beginning of the test method and choosing Debug Selected Tests in the Test Explorer. However, the test always runs (and fails) without hitting the breakpoint.
I've tried:
Cleaning and rebuilding the project
Restarting Visual Studio
This seems like a pretty basic case - I'm not attaching to a separate process, or doing anything fancy. Just a basic unit test inside VS2013. What else can I try to get the debugger to work correctly?
This did indeed turn out to be simple. I had forgotten that I told Visual Studio not to build the test project (Build - Configuration Manager - unchecked Build). I was trying to speed up my compile times, and it came back to bite me.
Long but simple story short, Build Configuration is another thing you can check if you strangely can't debug code you've placed breakpoints on in the IDE.

Visual Studio 2013 running unit test

I'm using Visual Studio 2013, and I have a legacy solution that I need to modify, containing a a console application and a unit test project.
I want to run the console application project, and while it's running I also want to run one of my unit tests.
I run my console application, but when I go to the test explorer to run my unit test, the option is grayed out.
why is this, and how can I run my unit test?
You don't mention why you want to do this, so I'll just answer blind.
If you run your console app without debugging, then you can run your unit tests at the same time.
To run without debugging, use Ctrl+F5 (DEBUG -> Start Without Debugging).
Alternatively, open your console app's project folder, go to the bin\Debug folder and double-click on <your_app>.exe.
FWIW it doesn't sound like a very good idea to do this. Unit tests are meant to be runnable completely separately from your application.