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

Piy*_*ade 6 .net c# console automation nunit

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

\n
nunit3-console.exe "G:\\LiveProjects\\NUnitTestProject2\\NUnitTestProject2\\bin\\Debug\\netcoreapp3.1\\NUnitTestProject2.dll"\nlike so\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
NUnit.Engine.NUnitEngineException : The NUnit 3 driver encountered an error while executing reflected code.\n  ----> System.InvalidCastException : Unable to cast transparent proxy to type 'System.Web.UI.ICallbackEventHandler'.\n--NUnitEngineException\nThe NUnit 3 driver encountered an error while executing reflected code.\nlike so\n
Run Code Online (Sandbox Code Playgroud)\n

请参考我下面的代码:

\n
[TestFixture]   \n    public class Tests\n    {\n        [SetUp]\n        public void Setup()\n        {\n\n            Console.WriteLine("Welcome setup");\n\n        }\n\n        [Test]\n        public void Test1()\n        {\n          \n            Console.WriteLine("Welcome first Test ");\n            Assert.Pass();\n        }\n    }\nlike so\n
Run Code Online (Sandbox Code Playgroud)\n

我的项目的配置详细信息:

\n
    \n
  1. Microsoft.NET 框架版本 4.7.0
  2. \n
  3. 操作系统:窗口 10
  4. \n
  5. IDE:视觉工作室 2019
  6. \n
  7. 使用Nunit框架进行单元测试
  8. \n
  9. NUnit3TestAdapter(版本)3.16.1
  10. \n
  11. Microsoft.NET.Test.Sdk(版本)16.5.0
  12. \n
  13. NUnit.Console(版本)3.11.1
  14. \n
  15. 目标.NET框架(版本)3.1
  16. \n
\n

另外,我尝试在 Visual Studio 2019 中禁用 \xe2\x80\x98code 覆盖 \xe2\x80\x99 选项,但是 - 我无法看到它。任何人都可以建议 - \xe2\x80\x98code 在哪里Visual Studio 2019 中提供了coverage\xe2\x80\x99 选项。

\n

Chr*_*ris 5

查理的评论是正确的 - 但不幸的是仍然无法解决您的问题。您的测试套件针对 .NET Core - NUnit 控制台尚不支持。(尽管有一个提供支持的测试版。)

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


Cha*_*lie 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