Maccurt
Maccurt

Reputation: 13817

Does .NET Core work with the NUnit console runner?

I have a very simple test!

[Test]
public void TestMethod1()
{
    Assert.IsTrue(false);
}

When I try to run this with nunit3-console.exe I get the following error.

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

I am running .NET Core 2.1, with NUnit Console Runner 3.9 and NUnit test adapter 3.1. I did do a Google search and got conflicting answers. Am I missing something?

Upvotes: 12

Views: 10377

Answers (3)

Andrew McClement
Andrew McClement

Reputation: 1408

As of 3.13, NUnit.Console appears to support non .NET Framework tests, i.e. .NET Core, .NET 6, etc.

See https://github.com/nunit/nunit-console/releases/tag/3.13

3.16.3 supports .NET 8.0 (https://github.com/nunit/nunit-console/releases/tag/3.16.3).

Upvotes: 0

Andrew Gray
Andrew Gray

Reputation: 3661

The recent release of NUnit 3.11 notes on the releases page that:

PlatformAttribute is available on .NET Standard 2.0 and now detects .NET Core

Try using NUnit 3.11.

I also found this page in the NUnit documentation that talks about .NET Standard and .NET Core support. A cursory reading seems to me to suggest it is supported.

UPDATE

With dotnet core Coverlet is your friend. Also see this.

I have moved on to the Cloud and Azure DevOps. Yes, it is just TFS with a lot of lipstick but it is the Cloud. (Psst: GitHub Actions is the future imo).

Here is my Unit Test task (in a yaml pipeline) that runs my NUnit test suite. Essentially it is executing dotnet test, with which Coverlet is fully integrated.

# UnitTests
- task: DotNetCoreCLI@2
  displayName: 'Unit Tests'
  inputs:
    command: test
    projects: '$(APEX_SOLUTION)'
    arguments: '--no-restore -c $(BUILD_CONFIGURATION) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover /p:Threshold=50 /p:ThresholdType=branch /p:ThresholdStat=Average /p:Exclude="[DevOpsOnboarding.Views]*"'
    testRunTitle: 'Unit Tests $(Build.DefinitionName) - $(Build.BuildNumber)'

Coverlet also allows you to produce OpenCover output in one step. After this task I can run ReportGenerator.

Should be straightforward to convert to a Jenkins Batch Step.

Upvotes: -1

Maccurt
Maccurt

Reputation: 13817

I reached out to the NUnit community and got this answer: Does NUnit Console work with .NET Core? #487

NUnit Console is compiled using the full .NET Framework and does not currently support .NET Core. To run .NET Core tests from the command line, you need to use dotnet test. For information on how to do this, see .NET Core and .NET Standard (NUnit wiki).

We are looking at creating a .NET Core based console runner, but it is still in the planning stages.

Upvotes: 10

Related Questions