Nunit: Could not load file or assembly 'nunit.framework'

Created on 14 Feb 2018  ·  12Comments  ·  Source: nunit/nunit

Hello, I created a new project with dotnet nunit and I recieve this error when I try and execute my tests via Unit.ConsoleRunner.3.8.0 .

Dotnet SDK version 2.1.4

Sample repository showing error: https://github.com/VictorioBerra/nunit3-errors

Run ./build.ps1 to execute the cake file. Once you do that, it will download Unit.ConsoleRunner.3.8.0 from NuGet. So after you run that or download the nuget package you can skip the cake business and just run this in PowerShell if you like:

.\tools\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe .\tests\Demo.Tests\bin\Release\netcoreapp2.0\Demo.Tests.dll

question

Most helpful comment

I agree btw that it's a shame we don't have a fully-functional NUnit.Console on .NET Core 2.0 yet. Once I finish my current PRs, I'm headed that way if no one beats me to it.

All 12 comments

This is because, unlike .NET Framework projects, .NET Core projects do not have their dependencies such as nunit.framework.dll copied to the bin\{configuration}\{tfm} folder on build. You need to run dotnet publish. For Cake, that's DotNetCorePublish or see what NUnit does. Then you run tests on the assemblies in bin\{configuration}\{tfm}\publish which does contain dependencies.

dotnet test does all of this publishing for you before passing the \publish path to dotnet vstest.
Both dotnet vstest and NUnit Console operate on assemblies, not projects, and therefore require you to publish first just like you would if you were writing self-executing tests.

Ahhhhhh this is really enlightening and helpful thank you so much. If you look at the example over at cake they clearly show navigating to the bin directory to execute the tests: https://cakebuild.net/api/Cake.Common.Tools.NUnit/NUnit3Aliases/5A473496

Hopefully anyone else who bumps into this will see this and save some time.

Before I go too fast: NUnit.ConsoleRunner does not run on .NET Core yet. NUnitLite does, though this is the easiest way to run NUnit tests: https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

Example: https://github.com/jnm2/ApiContractGenerator/blob/aa3c085fdb9c978b252b630187325d6eeb504235/build.cake#L21-L25

@jnm2 does your example produce test results? From the wiki you posted:

dotnet test does not currently support passing command line options on to the test adapter, so NUnit cannot produce TestResults.xml yet.

This was the state of things last time I looked:

https://github.com/jnm2/Cake.SqlServer/blob/ed6093e268114ef640851414e64aabec49d284e8/build.cake#L114-L134

try
{
    DotNetCoreTest("src/Tests/Tests.csproj", new DotNetCoreTestSettings
    {
        Configuration = configuration,
        NoBuild = true,
        Logger = "trx",
        ArgumentCustomization = a => a.AppendSwitchQuoted("--results-directory", tempDirectory)
    });
}
finally
{
    if (parameters.IsRunningOnAppVeyor)
    {
        // dotnet test cannot do more than one target framework per TRX file
        // AppVeyor seems to ignore all but the first TRX upload– perhaps because the test names are identical
        // https://github.com/Microsoft/vstest/issues/880#issuecomment-341912021
        foreach (var testResultsFile in GetFiles(tempDirectory + "/**/*.trx"))
            AppVeyor.UploadTestResults(testResultsFile, AppVeyorTestResultsType.MSTest);
    }
}

I agree btw that it's a shame we don't have a fully-functional NUnit.Console on .NET Core 2.0 yet. Once I finish my current PRs, I'm headed that way if no one beats me to it.

Hi, any updates on this?

@orihomie This is a closed issue. We're you intending to ask about a different one?

@CharliePoole No, I've just met this issue on my build plan when tryin to launch .netcore tests by *\NUnit.Console-3.6.1\nunit3-console.exe and got exception which lead me right here

@orihomie For followup on the issue of running .Net Core tests via the console, keep an eye on nunit/nunit-console#478

Was this page helpful?
0 / 5 - 0 ratings