I'm running into an issue with unit tests on our Team City (8.0.4) build server - the code builds & runs all tests locally via Resharper and nCrunch.
But when running on the server I get the following error, even though the Unity assembly exists in the same directory as the unit test assembly, and is referenced in the unit test assembly.
SetUp method failed. SetUp : System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at XXXX.Unity.UnityContainerAdapter..ctor() at XXXX.GraphExtensionsTests..ctor() in c:\TeamCityV7\Agent-1\work\f02f7e27c0bedfa2\XXXX\Graph.Tests\Extensions\GraphExtensionsTests.cs:line 44
I've confirmed the copy of Microsoft.Practices.Unity is the correct version.
I've also confirmed the assemblies are built using the full version of the framework - not using client profile.
Any ideas why Team City might be failing?
Check the pattern you're using to locate your test assemblies. I had a similar problem with another library and it turns out the pattern was finding the test assembly under bin\Release and obj\Release; the obj folder doesn't contain all the assemblies referenced by the project and is really just a scratch folder for the compiler.
Another possibility I recently discovered is if you are using a library that you are not explicitly referencing, TeamCity will not collect the library for use and fail when it is implicitly referencing the assembly. I discovered this when trying to figure out why NHibernate.ByteCode.Castle, which was referenced in my test project, was not being loaded and resulting in a FileNotFoundException on TeamCity. Ultimately, I made a "dummy" unit test like so:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NHibernate.ByteCode.Castle;
namespace MyNamespace
{
[TestClass]
public class CastleProxyPresenceTest
{
[TestMethod]
[TestCategory("Infrastructure: This test forces TeamCity to load the NHibernate.ByteCode.Castle.dll file.")]
public void CastleProxyLoads()
{
var dummy = new LazyFieldInterceptor();
Assert.IsNotNull(dummy);
}
}
}
...after this, the file loaded properly and my unit tests compiled.
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