【问题标题】:The NUnit 3 driver encountered an error while executing reflected code (NUnit.Engine.NUnitEngineException)NUnit 3 驱动程序在执行反射代码时遇到错误 (NUnit.Engine.NUnitEngineException)
【发布时间】:2021-02-13 01:48:51
【问题描述】:

我有一个简单的 Nunit 项目,它只包含一个测试。我想使用命令执行我的代码,所以我在我的 Windows 10 机器上安装了“Nunit-console.exe”。安装后,使用以下命令在命令提示符下执行代码

nunit3-console.exe "G:\LiveProjects\NUnitTestProject2\NUnitTestProject2\bin\Debug\netcoreapp3.1\NUnitTestProject2.dll"
like so

执行此命令后,我发现以下错误消息:

NUnit.Engine.NUnitEngineException : The NUnit 3 driver encountered an error while executing reflected code.
  ----> System.InvalidCastException : Unable to cast transparent proxy to type 'System.Web.UI.ICallbackEventHandler'.
--NUnitEngineException
The NUnit 3 driver encountered an error while executing reflected code.
like so

请参考我下面的代码:

[TestFixture]   
    public class Tests
    {
        [SetUp]
        public void Setup()
        {

            Console.WriteLine("Welcome setup");

        }

        [Test]
        public void Test1()
        {
          
            Console.WriteLine("Welcome first Test ");
            Assert.Pass();
        }
    }
like so

我的项目的配置详情:

  1. Microsoft.NET Framework 4.7.0 版
  2. 操作系统: 窗口 10
  3. IDE:Visual Studio 2019
  4. 使用 Nunit 框架进行单元测试
  5. NUnit3TestAdapter(版本)3.16.1
  6. Microsoft.NET.Test.Sdk(版本)16.5.0
  7. NUnit.Console(版本)3.11.1
  8. 目标 .NET 框架(版本)3.1

此外,我尝试在 Visual Studio 2019 中禁用“代码覆盖率”选项,但是 - 我无法在其中看到它。谁能建议 - Visual Studio 2019 中的“代码覆盖率”选项在哪里可用。

【问题讨论】:

    标签: c# .net automation console nunit


    【解决方案1】:

    查理的评论是正确的 - 但遗憾的是仍然无法解决您的问题。您的测试套件以 .NET Core 为目标 - NUnit 控制台尚不支持。 (虽然有一个支持的测试版。)

    目前,最好的解决方案是使用dotnet test 运行,而不是使用 nunit 控制台。有关详细信息,请参阅此处的指南:https://docs.nunit.org/articles/nunit/getting-started/dotnet-core-and-dotnet-standard.html

    【讨论】:

      【解决方案2】:

      NUnit 3 测试适配器的 3.16.1 版本与您安装的控制台包使用的引擎 3.11.1 版本不兼容。

      您必须将控制台运行器降级到 3.10 或将适配器升级到 3.17。

      详细解释见我的博文http://charliepoole.org/technical/nunit-engine-version-conflicts-in-visual-studio.html

      【讨论】:

      • 我有同样的错误“无法投射”最新的:nunit 3.13.0; nunit.console.runner 3.12.0; nunit3TestAdapter 3.17.0:NUnit.Engine.NUnitEngineException:NUnit 3 驱动程序在执行反射代码时遇到错误。 ----> System.InvalidCastException:无法将透明代理转换为类型“System.Web.UI.ICallbackEventHandler”。
      猜你喜欢
      • 1970-01-01
      • 2015-08-30
      • 2021-10-24
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-19
      • 2017-05-23
      相关资源
      最近更新 更多