V5 Documentation

X86 And X64 Platform Related issues

X86/X64 platform related issues are very common when executing tests using different test runners, and NCrunch is no exception to this. Because NCrunch is also integrated with the build process, there is an extra dimension of complexity that is worth understanding when trying to troubleshoot platform related issues within the NCrunch environment.

NCrunch Building To Wrong Platform

If you notice that the output assembly built by NCrunch (in one of its workspaces) is targeting the wrong CPU architecture, be aware that this problem is likely to be caused by differences in the way that NCrunch handles the $(Configuration) and $(Platform) build properties (see project build platform and configuration).

By default, NCrunch will always build to the CPU architecture that is defined within the project file. It is possible to change the CPU architecture via NCrunch configuration through the use of the use build platform setting.

Test Environment CPU Architecture

NCrunch will apply certain rules when deciding the CPU architecture that should be used within its testing environment:

  • Firstly, NCrunch will consider the target platform of the test assembly as output from the build process. If the platform of this assembly is set to anything other than AnyCPU, NCrunch will use this platform in building the test environment and will consider nothing further.
  • Where the test assembly is built to target AnyCPU, NCrunch will then inspect the use cpu architecture NCrunch configuration setting on the test project. If this setting is anything other than AutoDetect, NCrunch will use the platform specified and will consider nothing further.
  • Finally, if the assembly was built to a target platform of AnyCPU and the use cpu architecture setting is AutoDetect, NCrunch will default to an X86 test environment.

Common Pitfalls And Recommendations

MSTest relies on a global .testsettings file to specify the target platform that should be used in a test environment. NCrunch does not consider the .testsettings file. Instead, adjust the use cpu architecture setting to set the target platform for your test environment.

There is a lack of standardisation between test runners in which processor architecture should be used in a test environment. Best practice is to always set up test projects with a target build platform identical to the platform that should be used inside the test environment. In this way, it should be very easy to understand which platform will be used for the test environment, as the output assembly won't support anything else.

By configuring your test projects with a target platform of AnyCPU, you are effectively stating that the tests within the project and all referenced code can function without problems in both X86 and X64 environments. If you have code within the test project or referenced by the test project that does not fit this description, then do not use AnyCPU.

Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download