Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get unit tests to run on a x64 platform

I have a C# application that must run in x64 mode. The problem is I try to create unit tests that run methods in the x64 application and the unit test project won't even build. I get the following error when it tries to build.

Error loading C:.....\bin\x64\Debug....UnitTests.dll: Unable to load the test container 'C:.....\bin\x64\Debug....UnitTests.dll' or one of its dependencies. If you build your test project assembly as a 64 bit assembly, it cannot be loaded. When you build your test project assembly, select "Any CPU" for the platform. To run your tests in 64 bit mode on a 64 bit processor, you must change your test settings in the Hosts tab to run your tests in a 32 bit process. Error details: Could not load file or assembly 'file:///C:.....UnitTests\bin\x64\Debug....UnitTests.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I have tried to change the unit test to x64 and also Any CPU and still cannot get it to run. Is there any fix for this?

like image 723
RJ. Avatar asked Apr 06 '11 19:04

RJ.


People also ask

How do I enable unit testing?

Turn live unit testing from the Test menu by choosing Test > Live Unit Testing > Start.

How do I run all unit tests in Visual Studio?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).


2 Answers

In VS 2012 and above you can select the default target platform from Test menu under Test Settings|Default Processor Architecture

Visual Studio Test Settings

like image 105
Sten Petrov Avatar answered Sep 23 '22 15:09

Sten Petrov


I'm assuming that you are using Visual Studios testing framework since you mention no other. In VS2010 you can force the testing host to run in x64. Build your assemblies as Any CPU or x64 then set the test host to x64.

http://msdn.microsoft.com/en-us/library/ee782531.aspx

like image 32
Robert Jeppesen Avatar answered Sep 23 '22 15:09

Robert Jeppesen