c# - 使用第三方 dll 的 VisualStudio NUnit3TestAdapter 测试项目

标签 c# visual-studio nunit-3.0

我有一个测试项目 Proj_Test ,其中包含两个 nuget 包。

<packages>
  <package id="NUnit" version="3.6.0" targetFramework="net45" />
  <package id="NUnit3TestAdapter" version="3.6.0" targetFramework="net45" />
</packages>

Proj_Test 具有对测试项目 Proj 的引用。 Layout

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/

相关文章:

vb.net - 自动引用 Microsoft.Data.Tools.Schema.Sql.UnitTesting

c - Visual C 接受错误数量的参数?

unit-testing - NUnit 3.X - 如何将动态参数传递到 TestCase 或 TestCaseSource?

teamcity - dotnet test 命令忽略带有 NUnit 结果的文件的创建

c# - 从控制台运行参数化测试

c# - 比较两个列表的顺序变化

c# - 在同一主机和端口下运行多个应用程序

c# - xUnit 断言两个值在一定公差范围内相等

c# - 如何将 .NET 标准库更改为 .NET 框架库?

c# - 将对象列表转换为类型数组并删除空值