Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should FakesAssemblies files be added to source control?

The new Fakes framework in VS11 allows you to create fake (mock or stub) implementations of assembly references in a Unit Test project. When an assembly is faked, VS11 generates two files for each fake:

/FakesAssemblies/[Project].Fakes.dll
/FakesAssemblies/[Project].Fakes.xml

Should these files be added to source control? My assumption is no, because they are auto-generated, but wondered if anyone had other opinions.

like image 763
mcknz Avatar asked Apr 05 '12 18:04

mcknz


People also ask

How does Microsoft fake work?

Microsoft Fakes helps you isolate the code you're testing by replacing other parts of the application with stubs or shims. The stubs and shims are small pieces of code that are under the control of your tests.


2 Answers

Being auto-generated shouldn't be discriminating factor for presence in repository. After all, all kinds of auto-generated files make their way there fairly often - for example designer files.

Problem is, generating extra fakes assembly all the time could be time consuming. Microsoft posts guidelines on how you can try to optimize that:

The compilation of Fakes assemblies can significantly increase your build time. You can minimize the build time by generating the Fakes assemblies for .NET System assemblies and third-party assemblies in a separate centralized project. Because such assemblies rarely change on your machine, you can reuse the generated Fakes assemblies in other projects.

So, rarely-changing, .NET FCL / 3rd party based fake assemblies should be part of repository to speed up build process. The ones based on your own code, are probably best generated on the fly.

like image 182
k.m Avatar answered Oct 23 '22 16:10

k.m


According to http://hamidshahid.blogspot.com.au/2012/11/microsoft-fakes-framework.html

The "FakesAssemblies" folder and all the files in it are generated whenever the project is compiled. This is important because if you are adding fakes for assembly for a changing component, the generation of FakesAssemblies will ensure that all changes are reflected in the generated assembly.

Also in GitHub it is recommended to exclude them in .gitignore

# Microsoft Fakes
FakesAssemblies

If you worry about time of generation during build, you can specify only what you need and disable stubs

mscorlib.fakes:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="mscorlib" Version="4.0.0.0" />
  <StubGeneration Disable="true"/>
  <ShimGeneration>
    <Clear />
    <Add FullName="System.Environment"/>
    <Add FullName="System.TimeZoneInfo"/>
    <Add FullName="System.DateTime"/>
  </ShimGeneration>
</Fakes>
System.fakes:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="System" Version="4.0.0.0"/>
  <StubGeneration Disable="true" /> 
  <ShimGeneration Disable="true" /> 
</Fakes>
like image 44
Michael Freidgeim Avatar answered Oct 23 '22 16:10

Michael Freidgeim