Reputation: 1444
I have 2 projects in my solution, one is the actual code (NUnitSample1) while the other is the test project (NUnitSample1.Test) with the unit tests. NUnitSample1.Test contains a reference of the first project NUnitSample1. The Build Output path for both projects are different and are explicitly specified. The CopyLocal
property of the NUnitSample1 project reference needs to be set to false
.
Now, when I build and try to run the unit test using ReSharper, it fails with the following message:
System.IO.FileNotFoundException : Could not load file or assembly 'NUnitSample1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
I guess this is because the binaries are in separate folders. Is there any way to run the tests using ReSharper while maintaining this structure? Also, there are already tens of thousands of tests written, so I need a solution which involves minimal code change. Dynamically loading the assembly (as suggested by AlexeiLevenkov) works, however, it would involve setting up each method individually, which is not feasible.
+NUnitSample1Solution
+NUnitSample1 //This folder contains the actual class library project
+NUnitSample1.Test //This folder contains the test project
+Binaries //This folder contains the binaries of both projects
+bin //This folder contains the project dll
+tests
+bin //This folder contains the test project dll
I found this NUnit link where multiple assemblies may be specified, however, even this does not work when I try to run using ReSharper. I'm also not sure if I'm doing it correctly, where does the config file need to be added? In the actual project or the test project? What is the build action supposed to be?
Any pointers would be appreciated. TIA.
Upvotes: 1
Views: 745
Reputation: 1444
I was able to load the missing assembly using the answer from here in the TestFixtureSetup
(will also work in the Setup
method).
[TestFixtureSetUp]
public void Setup()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);
}
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
{
string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
if (File.Exists(assemblyPath) == false) return null;
Assembly assembly = Assembly.LoadFrom(assemblyPath);
return assembly;
}
The above code in the LoadFromSameFolder
method may be modified to locate the assembly exactly.
PS: Thanks to Alexei Levenkov for putting me on the right path.
Upvotes: 0