I'm looking for a way to export the test output from a .NET Core application, to TeamCity via a Cake build script.
Currently, I'm simply running:
DotNetCoreTest("./src/MyTestProject");
But I can't see anything within the documentation of ITeamCityProvider or DotNetCoreTest
The above code block works from the command line, but I can't find a way to publish the test results to the build server.
Hope someone can help
Greetings, everyone! As many of you already know, TeamCity has a plugin to build .Net Core projects, which is basically a wrapper for the dotnet command. But if you try running dotnet test, you won’t see test results in TeamCity at the moment.
Test results from e.g. xUnit and MSTests wasn't being picked up by TeamCity anymore. Apparently there was a change in the output of the test runner for .NET Core. But there's a quick solution. In my Cake build script, I just needed to add one little line:
You can either use a TeamCity plugin, or use an external build runner (like MSBuild) when building your project in TeamCity. Download and install the plugin as per Teamcity documentation.
Apparently there was a change in the output of the test runner for .NET Core. But there's a quick solution. In my Cake build script, I just needed to add one little line: You can see a sample of a real change to Ensure.That's build.cake file My step to run the unit tests looks like this:
Found myself Googling again for this situation, and stumbled across my own unhelpful comment on the other answer...
Basically, all you need to be doing in Cake is calling DotNetCoreTest
with standard settings (nothing specific to TeamCity), and include the following NuGet packages in your test project:
TeamCity.Dotnet.Integration
TeamCity.VSTest.TestAdapter
I also have the Cake build systems module configured in tools\modules\packages.config
:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake.BuildSystems.Module" version="0.3.0" />
</packages>
This will light up the Tests tab in TC.
With the NUnit test runner for .NET Core, you need to explicitly pass the --teamcity
option to have it report the test results to TeamCity (see commit 323fb47).
In your Cake script, you can do that by using the ArgumentCustomization
property:
Task("Test")
.Does(() =>
{
DotNetCoreTest(
"path/to/Project.Tests",
new DotNetCoreTestSettings
{
ArgumentCustomization = args => args.Append("--teamcity")
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With