Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging x64 Unit Tests in Visual Studio

I am having difficulty debugging C++ x64 unit tests in Visual Studio 2012/13.

My unit test project builds perfectly, for both Win32 and x64, but when debugging a test the symbols are loaded but the breakpoints set are skipped completely and the program never pauses, much like what happens if you just run the test.

If I build the unit test project for Win32, the breakpoints are hit and I can debug as usual.

Are there any special settings for debugging unit tests in x64? The properties were copied from the default Win32 settings for the project, and all win32-specific options were removed. Is this the correct idea for configuring a unit test project?

like image 960
Steve Avatar asked Sep 09 '13 12:09

Steve


People also ask

How do I debug unit tests in Visual Studio?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

How do I run Visual Studio in 64 bit mode?

From the Visual Studio menu, choose Test, then choose Processor Architecture for AnyCPU projects. Choose x64 to run the tests as a 64-bit process.

How do I change my Visual Studio from 32 bit to 64 bit?

From the BUILD menu in Visual Studio, select Configuration Manager. From the Active solution platform drop-down list, select New. The New Solution Platform dialog displays. In the Type or select new platform combination box, select x64.

Is there a Visual Studio 64 bit?

Visual Studio 2022 on Windows is now a 64-bit application.


1 Answers

You have to set the Test runner's default processor architecture to x64. You can find this in Test | Test Settings | Default Processor Architecture | x64.

You can also create a test settings file with this setting in it.

  • Add an XML file to your Visual Studio solution and rename it so that its file extension is .runsettings.
  • Replace the file content with the example.
  • Edit it to your own needs.
  • On the Test menu, choose Test Settings, Select Test Settings File.

Taken from Configuring Unit Tests by using a .runsettings File

You want to change the TargetPlatform flag as noted below.

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <RunConfiguration>
    <ResultsDirectory>.\TestResults</ResultsDirectory>
    <TargetPlatform>x86</TargetPlatform>
    <TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
  </RunConfiguration>
  <!-- more stuff -->
</RunSettings>
like image 154
Ade Miller Avatar answered Oct 13 '22 00:10

Ade Miller