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?
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.
Visual Studio 2022 is supported only on 64-bit editions of Windows 10 version 1909 and higher and Windows Server 2016 and higher.
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.
Unit tests run one at a time. There is no parallelism.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With