nuke-build / nuke

🏗 The AKEless Build System for C#/.NET
https://nuke.build
MIT License
3.02k stars 364 forks source link

XUnit Support on .Net Core #215

Closed netclectic closed 5 years ago

netclectic commented 5 years ago

When trying to use with XUnit2 to run tests on .Net Core, it fails with an error telling me that xunit.runner.console 'requires a framework: net452, net46, net461, net462, net47, net471, net472'.

After adding a call to SetToolPath on my XUnit build step

    Target Test => _ => _
        .DependsOn(Compile)
        .Executes(() =>
        {
            var xUnit_netcore_Settings = new Xunit2Settings()
                .AddTargetAssemblies(GlobFiles(TestsDirectory, $"*/bin/*/netcore*/*.Tests.dll").NotEmpty())
                .AddResultReport(Xunit2ResultFormat.Xml, OutputDirectory / "netcore_tests.xml")
                .SetToolPath(ToolPathResolver.GetPackageExecutable("xunit.runner.console", "xunit.console.dll", "netcoreapp2.0"));

            Xunit2(s => xUnit_netcore_Settings);
        });

it now fails with the error:

System.InvalidOperationException: Could not find/load any of the following assemblies: xunit.execution.dotnet.dll
One or more of the tests failed.
   at Nuke.Common.ControlFlow.Fail(String text)
   at Nuke.Common.Tools.Xunit.XunitTasks.Xunit2(Configure`1 configurator)
   at Build.<get_Test>b__24_1() in D:\Source\Nuke_Test\build\Build.cs:line 76
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, IEnumerable`1 executionList)
   at Nuke.Common.Execution.BuildExecutor.Execute[T](Expression`1 defaultTargetExpression)

I tried adding a reference to the 'xunit.extensibility.execution' package (which seems to be where xunit.execution.dotnet.dll lives), but the error remains.

matkoch commented 5 years ago

https://github.com/nuke-build/common/tree/feature/fix-package-executable

netclectic commented 5 years ago

Thanks, I managed to test with the update you provided and I got a little bit further.

I cloned the Nuke Common repo, built it locally and updated my build project to reference the local dll, then added all the necessary packages to my build project. To trigger the build from the command line I used dotnet run from within my solution folder with a --project parameter pointing to the local build of the Nuke Global tool.

dotnet run --project "C:\Source\NukeBuild\source\Nuke.GlobalTool"

That all seemed to work and trigger the build correctly, it gave this output at the start:

NUKE Global Tool version LOCAL (Windows,.NETStandard,Version=v2.0)

The error I now get is: Assertion failed: Package executable xunit.execution.dotnet.dll [xunit.extensibility.execution] requires a framework: netstandard1.1

While investigating, I across this issue: https://github.com/xunit/xunit/issues/1839, which seems to suggest that the .NET Core console runner is no longer supported.

matkoch commented 5 years ago

We were using XunitTasks once too, but then moved to DotNetTest... I don't remember the reason though.

matkoch commented 5 years ago

I’m closing this as I assume it’s not longer relevant, given that xUnit dropped support for it. Feel free to reopen otherwise.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.