I have a relatively simple solution. All works fine under MSBuild (in VS 2017 Mac). I'm creating a Cake build script, but I just cannot get unit testing to work. There are tons of examples, but it seems that none are valid anymore. Some call for DotnetCoreTest, most for XUnit2. Neither work at all in my project.
I get the following error when running XUnit2: System.InvalidOperationException: Unknown test framework: could not find xunit.dll (v1) or xunit.execution.*.dll (v2) in /Users/dev/Projects/MyProject/tst/MyProject.Serialization.UnitTests/bin/Release/netcoreapp1.1
And that output is absolutely valid, the file is in fact not there. Here are the references for my unit test project:
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit.runner.console" Version="2.2.0" />
<PackageReference Include="FluentAssertions" Version="4.19.2" />
<PackageReference Include="Moq" Version="4.7.99" />
<PackageReference Include="FluentAssertions.AspNetCore.Mvc" Version="0.7.0-beta1" />
<PackageReference Include="AutoMapper" Version="6.1.1" />
<PackageReference Include="ExpectedObjects" Version="1.3.0" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="xunit.extensibility.execution" Version="2.2.0" />
</ItemGroup>
I have referenced xunit.runner.console
AND xunit.extensibility.execution
, yet these are not copied to the destination directory. .NET Core doesn't appear to have any way to force that, and even if I copy them manually the test assemblies still won't load.
Here is my Cake Test script:
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0
#tool nuget:?package=xunit.runner.console
...
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
Information("Start Running Tests");
XUnit2(string.Format("./tst/**/*Tests/bin/{0}/**/*Tests.dll", configuration), new XUnit2Settings
{
});
});
Clearly I'm missing something very basic, but with all the conflicting information out there I don't know what it is. Should I not be using XUnit?
#tool
preprocessor in your Cake script? – Jaynes