NUnit 3驱动程序在执行反射代码时遇到错误(NUnit.Engine.NUnitEngineException) [英] The NUnit 3 driver encountered an error while executing reflected code (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
我的项目的配置详细信息:
- Microsoft.NET Framework 版本4.7.0
- 操作系统:窗口10
- IDE: Visual Studio 2019
- 使用 Nunit框架进行单元测试
- NUnit3TestAdapter (版本)3.16.1
- Microsoft.NET.Test.Sdk (版本)16.5.0
- NUnit.Console (版本)3.11.1
- 目标.NET框架(版本)3.1
- Microsoft.NET Framework version 4.7.0
- OS: window 10
- IDE: Visual studio 2019
- Use Nunit framework for unit testing
- NUnit3TestAdapter (Version) 3.16.1
- Microsoft.NET.Test.Sdk (Version) 16.5.0
- NUnit.Console (Version) 3.11.1
- 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屋!