Exporting Cake dotnet core test output to TeamCity
Asked Answered
A

2

5

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

Allowance answered 30/1, 2017 at 23:58 Comment(2)
What test runner are you using? If you're using xUnit it should work out of the box.Lafleur
The project has the Nunit runnerAllowance
L
4

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")
        });
});
Lafleur answered 1/2, 2017 at 9:32 Comment(2)
Ah yes I see. Thanks for that!Allowance
Just an FYI this no longer works if the NUnit Test Adapter is used (the runner is deprecated).Although
A
5

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.

Although answered 18/9, 2018 at 6:55 Comment(2)
Shouldn't need to add TeamCity.Dotnet.Integration, just TeamCity.VSTest.TestAdapter: blog.jetbrains.com/teamcity/2017/04/test-net-core-with-teamcityBreccia
TeamCity.VSTest.TestAdapter is the only thing that works for me with .NET Core 3.1Hales
L
4

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")
        });
});
Lafleur answered 1/2, 2017 at 9:32 Comment(2)
Ah yes I see. Thanks for that!Allowance
Just an FYI this no longer works if the NUnit Test Adapter is used (the runner is deprecated).Although

© 2022 - 2024 — McMap. All rights reserved.