Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Unit Test 32-bit and 64-bit

I have a solution that has projects both with C++ and C++/CLI code, and a set of projects which unit test all of these, using the Microsoft Unit Test Framework. For the C++/CLI projects, the unit test projects are C# unit tests. What I currently have is a platform for 32- and 64-bit. Also, for each platform I have unit test projects set to 32- and 64-bit platforms to match.

The issue I have is that when I switch to 32-bit vs. 64-bit I need to go to TEST > TEST SETTINGS > DEFAULT PROCESSOR ARCHITECTURE and flip from 32- and 64 as needed. If I don't, I get a warning from Visual Studio that a 64-bit image cannot run in a 32-bit process. This makes sense, but surely there is some way to automate this? Otherwise if I do a batch build on a build machine I will not have control of this and the unit tests will fail.

Also I have tried to set the unit test projects to be AnyCPU but this fails with an error saying "An attempt was made to load a program with an incorrect format"

Is there a better way perhaps?

like image 489
Jarek Mitek Avatar asked Nov 05 '13 02:11

Jarek Mitek


People also ask

How can I tell if Visual Studio is 32 bit or 64-bit?

The easiest way, without installing another program or running the file, is just to right click on the file, choose Properties, and then go the the Compatibility tab.

Does Visual Studio run 32 bit?

Visual Studio 2022 is supported only on 64-bit editions of Windows 10 version 1909 and higher and Windows Server 2016 and higher.

How do I run a specific Unit Test in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

Do unit tests run in parallel C#?

Unit tests run one at a time. There is no parallelism.


1 Answers

If you're looking to automate test run i a build machine you can set the project to AnyCPU and run corflags /32bit+ (or /32bit-) to set the .NET assembly to the right platform before running the unit tests.

I'm not aware of an automatic solution for VS other then have two projects (one x64 and on x86) that link to the same files.

like image 155
Dror Helper Avatar answered Sep 17 '22 06:09

Dror Helper