Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting Cake dotnet core test output to TeamCity

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

like image 844
Nagoh Avatar asked Jan 30 '17 23:01

Nagoh


People also ask

Is it possible to run DotNet test in TeamCity?

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.

Is TeamCity no longer picking up test results from xUnit?

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:

How do I build a project in TeamCity?

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.

Is there a change in the output of the test runner?

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:


2 Answers

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.

like image 137
Adam Houldsworth Avatar answered Sep 19 '22 17:09

Adam Houldsworth


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")
        });
});
like image 36
Enrico Campidoglio Avatar answered Sep 19 '22 17:09

Enrico Campidoglio