TFS Fakes Build Unit test crash

We have a solution VS2013.net 5.0 (VS2013 Premium), in which all module tests pass normally locally, but it is not possible to run several tests when running in TFS Build's VS Test Loader with this or a similar exception: System.TypeLoadException: Could not load type 'System.Diagnostics.Fakes.ShimEventLog' from assembly 'System.4.0.0.0.Fakes, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0ae41878053f6703'. This is an example of a failed test:

  [TestMethod] public void WriteToEventLogTest_HappyPath() { EventLogEntryType eTypeInfo = EventLogEntryType.Information; bool sourceExistCalled = false; bool writeEntrycalled = false; using (ShimsContext.Create()) { ShimEventLog.SourceExistsString = s => { sourceExistCalled = true; return true; }; ShimEventLog.AllInstances.WriteEntryStringEventLogEntryType = (@this, str, et) => { writeEntrycalled = true; }; Logging.WriteToEventLog(IpAddress, eTypeInfo); Assert.IsTrue(sourceExistCalled, "SourceExist() not called"); Assert.IsTrue(writeEntrycalled, "WriteEntry() not called"); } }` 

We are using the TFS 2013 5 update that runs on Windows Server 2012 R2. Is there anything that can cause this problem? Should we upgrade TFS to the latest version of Update 5 at the moment?

+7
c # tfsbuild tfs2013
source share
3 answers

The problem was solved by exchanging fake configuration files between test projects at the solution level

+3
source share

In our situation, we ran several unit test DLLs through VSTest in Jenkins.

Call example:

 "c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "./TestDLL1.UnitTests/bin/Debug/TestDLL1.UnitTests.dll" "./TestDLL2.UnitTests/bin/Debug/TestDLL2.UnitTests.dll" "./TestDLL3.UnitTests/bin/Debug/TestDLL3.UnitTests.dll" /Enablecodecoverage /UseVsixExtensions:false /Logger:trx 

In some test projects, there were Fakes for the same DLL, and most of the Fake settings were all. One test project only faked one class, as shown below in XML, to prevent a warning that "some fakes cannot be generated."

 <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true"> <Assembly Name="Utilities"/> <StubGeneration> <Clear /> </StubGeneration> <ShimGeneration> <Clear /> <Add FullName="UIUtils.ExceptionDisplay"/> </ShimGeneration> </Fakes> 

For some reason, VSTest used the above version for other test projects. Changing one test project to create all the fakes fixes the problem with a System.TypeLoadException. We can consolidate our fakes in the future in order to be able to more easily limit which classes are faked, but at the moment this was a much faster solution to the problem.

If only there was an easier way to suppress the warning "Some fakes cannot be generated" ...

0
source share

has a similar problem when using Shims in several separate Unit test projects. Apparently, the created gaskets can overwrite anyone or something like that.

Here are the instructions that I followed to fix this: scroll to the middle of this page: https://msdn.microsoft.com/en-us/library/hh708916.aspx

This is under the heading to optimize build time, but use it to fix your problem.

Since such assemblies rarely change on your computer, you can reuse the created Fakes assemblies in other projects. From your Unit test projects, you can simply take a link to compiled fake assemblies that are placed under FakesAssemblies in the project folder.

  • Create a new class library with .NET version compatibility. your test projects. Lets call it Fakes.Prebuild. Removing class1.cs from the project is not required.

    Add a link to all the system and third-party assemblies you need. Fakes. and generate fakes, edit the .fakes file if you like, and build to create fake assemblies.

    From your Unit test projects Just make sure you have the link for the Fakes runtime DLL: C: \ Program Files \ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ PublicAssemblies \ Microsoft.QualityTools.Testing.Fakes.dll

    Then, for each assembly you created, Fakes for, add a link to the corresponding DLL file in the Fakes.Prebuild \ FakesAssemblies of your project. (This folder is created at compilation)

    To confirm, you will need to add a link after viewing the created fake assembly.

0
source share

All Articles