Piyusha Naphade
Piyusha Naphade

Reputation: 71

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.

Upvotes: 7

Views: 7447

Answers (3)

Charlie
Charlie

Reputation: 13681

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.com/technical/nunit-engine-version-conflicts-in-visual-studio.html

Upvotes: 2

Suchith
Suchith

Reputation: 1527

Remove the console runner and run the below command that works

dotnet test [path to your nunit test project solution file]

Ex:

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

Mac:

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

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

Upvotes: -1

Chris
Chris

Reputation: 6042

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

Upvotes: 7

Related Questions