Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The NUnit 3 driver encountered an error while executing reflected code (NUnit.Engine.NUnitEngineException)

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

Please refer my below code:

[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

Configuration details of my project:

  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

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.

like image 288
Piyusha Naphade Avatar asked Oct 30 '20 15:10

Piyusha Naphade


2 Answers

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.)

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

like image 123
Chris Avatar answered Oct 23 '22 03:10

Chris


Version 3.16.1 of the NUnit 3 test adapter is not compatible with version 3.11.1 of the engine, which is used by the console package you installed.

You must either downgrade the console runner to 3.10 or upgrade the adapter to 3.17.

For a detailed explanation see my blog post at http://charliepoole.org/technical/nunit-engine-version-conflicts-in-visual-studio.html

like image 37
Charlie Avatar answered Oct 23 '22 04:10

Charlie