NUnit 3 驱动程序在执行反射代码时遇到错误 (NUnit.Engine.NUnitEngineException)

问题描述 投票:0回答:3

我有一个简单的 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
3个回答
7
投票

查理的评论是正确的 - 但不幸的是仍然无法解决您的问题。您的测试套件针对 .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.com/technical/nunit-engine-version-conflicts-in-visual-studio.html


-1
投票

删除控制台运行程序并运行以下有效的命令

dotnet test [nunit 测试项目解决方案文件的路径]

例如:

dotnet test D:\MyProject\MobileProject\MobileProject.NUnitTest.csproj

麦克:

dotnet test /Users/MyName/MobileProject/MobileProject.NUnitTest.csproj

https://docs.nunit.org/articles/nunit/getting-started/dotnet-core-and-dotnet-standard.html

© www.soinside.com 2019 - 2024. All rights reserved.