我有一个测试项目 Proj_Test
,其中包含两个 nuget 包。
<packages>
<package id="NUnit" version="3.6.0" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="3.6.0" targetFramework="net45" />
</packages>
Proj
引用了其他几个需要加载的 dll。
我可以在哪里添加此信息,以便我可以在 IDE 中使用 NUnit3TestAdapter 启动测试,而无需实际将 dll 复制到输出文件夹。
有a solution for the Nunit2 Runners 。但当尝试通过 NUnit3TestAdapter 将其用于 Nunit3 时,我失败了。
根据tips and tricks section我通过菜单添加了一个设置文件 Test.runsettings
。
<RunSettings>
<NUnit>
<PrivateBinPath>D:\Drive\AnyThirdParty</PrivateBinPath>
</NUnit>
</RunSettings>
该设置似乎被忽略。
如何管理我的测试的这些依赖项?
编辑: This is我想我发生了什么事。
Private assemblies are deployed in the same directory structure as the application. If the directories specified for PrivateBinPath are not under ApplicationBase, they are ignored.
创建副本真的是唯一的解决方案吗?
最佳答案
如果你找不到更好的办法,请尝试自己解决
using ConsoleApplication6;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestInitialize]
public void Init()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += MyResolveEventHandler;
}
[TestMethod]
public void TestMethod1() { Assert.AreEqual(new MyClass().DoSomething(), 1); }
[TestMethod]
public void TestMethod2() { Assert.AreEqual(new MyClass().DoSomething(), 1); }
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
return Assembly.LoadFile(@"C:\MyPath\MyAssembly.dll");
}
}
}
不幸的是,程序集探测仅适用于子目录,因此您无法使用它...
关于c# - 使用第三方 dll 的 VisualStudio NUnit3TestAdapter 测试项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41573851/