I have a lot of integration tests which read expected results from files. My tests access those files by relative paths. Relative paths are one level of depth different for x86 vs Any CPU. For example, when my tests run under x86, they need to read the following file "../../TestResults/MyTest.csv", but under Any CPU they need to access "../TestResults/MyTest.csv"
So far I have the following constant in every test fixture:
private const string platformDependentPrefix = "";
If I run my tests for x86, I need to manually change "" to "../" in every test fixture.
Is there a way to automate it?
Checking at run time if you are running a 64-bit application: To see whether your process is 64-bit or 32-bit you can simply check the IntPtr. Size or any other pointer type. If you get 4 then you are running on 32-bit.
"Any CPU" means that when the program is started, the . NET Framework will figure out, based on the OS bitness, whether to run your program in 32 bits or 64 bits. There is a difference between x86 and Any CPU: on a x64 system, your executable compiled for X86 will run as a 32-bit executable.
Since x86 apps run on both x64 and x86 systems, the most compatible choice is to build x86. If you MUST build a 64 bit solution, you'll need to target x64 and use our x64 dlls.
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.
Very hacky way but works:
public static string Platform
{
get
{
if (IntPtr.Size == 8)
return "x64";
else
return "x86";
}
}
Also you can access the CSharpProjectConfigurationProperties3.PlatformTarget
property.
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