NUnit 3驱动程序在执行反射代码时遇到错误(NUnit.Engine.NUnitEngineException) [英] The NUnit 3 driver encountered an error while executing reflected code (NUnit.Engine.NUnitEngineException)

查看:74
本文介绍了NUnit 3驱动程序在执行反射代码时遇到错误(NUnit.Engine.NUnitEngineException)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Nunit项目,其中仅包含一个测试.我想使用命令执行代码,因此我在Windows 10计算机上安装了"Nunit-console.exe".安装后,使用以下命令在命令提示符下执行代码

I have a simple Nunit project which contains only a single test. I want to execute my code using command, so I have installed ‘Nunit-console.exe’ on my Windows 10 machine. After installation, executed the code on command prompt using below command

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

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

After executing this command, I have discovered below error message:

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
  1. Microsoft.NET Framework version 4.7.0
  2. OS: window 10
  3. IDE: Visual studio 2019
  4. Use Nunit framework for unit testing
  5. NUnit3TestAdapter (Version) 3.16.1
  6. Microsoft.NET.Test.Sdk (Version) 16.5.0
  7. NUnit.Console (Version) 3.11.1
  8. Target .NET framework (Version) 3.1

此外,我尝试禁用Visual Studio 2019中的代码覆盖率"选项,但是-我看不到它.任何人都可以建议-Visual Studio 2019中的代码覆盖率"选项在哪里可用./p>

Also, I have tried to disable the ‘code coverage’ option in visual studio 2019, however - I am not able to see it in. Can anyone suggest - where is ‘code coverage’ option available in visual studio 2019.

推荐答案

查理(Charlie)的评论是正确的-但不幸的是仍无法解决您的问题.您的测试套件以.NET Core为目标-NUnit Console尚不支持.(尽管有支持的Beta版本.)

Charlie's comment is correct - however unfortunately still won't resolve your issue. Your test suite targets .NET Core - which the NUnit Console does not yet support. (Although there is a beta version out with support.)

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

For now, the best solution is to run with dotnet test, rather than the nunit console. For more details, see the guide here: https://docs.nunit.org/articles/nunit/getting-started/dotnet-core-and-dotnet-standard.html

这篇关于NUnit 3驱动程序在执行反射代码时遇到错误(NUnit.Engine.NUnitEngineException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆