Microsoft fakes x64 not x86 and v4.5

I am using Microsoft's fake testing environment. There is not as much as I need to use the shim / moles approach because of the "old" code, which I cannot change. This is code from a vendor without a source, it was written without testing. So I'm stuck in three possible frameworks: TypeMock (dear), Telerik JustMock (dear) or Microsoft Fakes. Since we already have VS Ultimate, we choose fakes. Since most people think that they need to be asked to rewrite or modify the code in some way to support the use of interfaces and / or dependency injection, I will tell you about this, this is not an option.

One of the problems I am facing is that the library that I am trying to fake is huge and requires the use of the 64-bit version of fakes.exe and not the 32-bit version (fakes.x86.exe), this works to the limit memory 32-bit applications.

The second problem is that I need to compile the fake library using the v4.5 framework. This is possible through the command line, although not documented. The reason is that in version 4.5 they added IReadOnly * interfaces to System.Collections.Generic, and the library uses them. Compiling with v4 raises an error indicating that the types were not found as expected.

The problem is, Visual Studio always uses x86 and v4.0, and I cannot find a way to override it. Does anyone know how to make it use 64bit and v4.5 structure? My current idea is to not use the built-in elements of the visual studio and just use the command line and manually link to the file. Then, each time we update the dll, we will manually recreate it and update the link. This file is not updated very often, so it is possible.

The command line that I use to create a fakes library manually (someone can find it):

"c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\fakes\fakes.exe" <assembly> /tfv:v4.5 

The help command only shows that v2, v3.5 and v4 are possible options for tfv, but only for hits I tried v4.5.

I tried to force the application architecture to use x64 instead of any processor, without any changes in which it executed fakes.exe. I looked at the .csproj file for the test, no changes. I looked in the .csproj file that fakes.exe and said that using the v4 framework open in visual studio, changed to v4.5, compiled perfectly. The fake command line is used, compiled in order. There is an attribute in the .fakes file in the project that allows you to determine the version of the compiler, but installing it on v4.5 still did not work. I assume that changing the version in visual studio from v4 to v4.5 also changed assembly references. My next attempt is to try changing the design of the template if I find it.

+6
source share
3 answers

@schellack - this is how I was able to "link to the created fake dll and make sure that the required links are in your test project"

  • Compile and run all unit tests locally and make sure they pass
  • The project’s main directory, in the same place as the .csproj file, should now have the FakesAssemblies directory. The directory will contain the generated System.Web.Mvc.4.0.0.0.Fakes.dll (or whatever version number you use). The link to the System.Web.Mvc.4.0.0.0.Fakes project already has a path to this directory and dll. Both this directory and the DLL must be added to the original control. They do not need to be added to VS.
  • In order for our CI assembly machine to be compiled, I also had to add the Microsoft.QualityTools.Testing.Fakes.dll file to the project.
    • I found Microsoft.QualityTools.Testing.Fakes.dll in C: \ Program Files (x86) \ Microsoft Visual Studio 11.0 \ Common7 \ IDE \ PublicAssemblies
    • In the main directory of the project, in the same place as the .csproj file, there is a "Fakes" directory that is included in the project (visible in VS), as well as under source control. It has one .fakes file. I copied the Microsoft.QualityTools.Testing.Fakes.dll file to this directory via VS so that it is also added to the project.
    • The hint path in the .csproj project file needs to be added / updated to look in the Fakes directory. I found the link in my .csproj file and changed it like this:

 <Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>Fakes\Microsoft.QualityTools.Testing.Fakes.dll</HintPath> </Reference> 

Now all compilations and unit tests run

+4
source

You can only think about the following (apologies if it is already installed):

'Test' β†’ 'Test Settings' β†’ 'Default Processor Architecture' β†’ 'X64'

+1
source

Unfortunately, I was not able to figure out how to get visual studio to run fakes.exe instead of fakes.x86.exe. In addition to copying the fakes.exe file through the fakes.x86.exe file. Despite the fact that although one proposal from Microsoft made the use of fakes to increase speed, you just had to refer to the fake DLL created and make sure that the required links are in your test project. By default, this is Microsoft.VisualStudio.QualityTools.UnitTestFramework. Doing this will not only allow me to use fakes, but also reduce build time, since the fake library should no longer be generated. Not my favorite solution, but it has the advantage of speed. Therefore, I am going along this route.

Thanks to those who helped with this problem.

Remember how to get version 4.5 for compilation ... make sure that the version for your unit test project is 4.5, and if you change it from 4.0, close and reopen the visual studio.

0
source

All Articles