[英]Resharper - NUnit - unable to run unit tests because code and test project binaries in different locations
我的解决方案中有2个项目,一个是实际代码( NUnitSample1 ),而另一个是带有单元测试的测试项目( NUnitSample1.Test )。 NUnitSample1.Test包含第一个项目NUnitSample1的引用。 两个项目的“构建输出”路径均不同,并且已明确指定。 NUnitSample1项目引用的CopyLocal
属性需要设置为false
。
现在,当我构建并尝试使用ReSharper运行单元测试时,它失败并显示以下消息:
System.IO.FileNotFoundException:无法加载文件或程序集'NUnitSample1,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一。 该系统找不到指定的文件。
我猜这是因为二进制文件位于单独的文件夹中。 有什么方法可以在保持此结构的同时使用ReSharper运行测试吗? 另外,已经有成千上万的测试编写,因此我需要一个涉及代码更改最少的解决方案。 但是,动态加载程序集(如AlexeiLevenkov所建议)的工作需要单独设置每种方法,这是不可行的。
+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
我找到了可以在其中指定多个程序集的NUnit链接 ,但是,当我尝试使用ReSharper运行时,即使这样也不起作用。 我也不确定我是否做得正确,需要在哪里添加配置文件? 在实际项目还是测试项目? 构建动作应该是什么?
任何指针将不胜感激。 TIA。
我能够加载缺少的组件使用的答案从这里在TestFixtureSetup
(也将在工作中Setup
方法)。
[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;
}
可以修改LoadFromSameFolder
方法中的上述代码以精确地定位程序集。
PS:感谢Alexei Levenkov让我走上正确的道路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.