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

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
Nagoh
  • 813
  • 2
  • 10
  • 23
  • What test runner are you using? If you're using [xUnit](https://xunit.github.io/docs/getting-started-dotnet-core.html) it should work [out of the box](https://blog.jetbrains.com/teamcity/2016/11/teamcity-dotnet-core#testing). – Enrico Campidoglio Feb 01 '17 at 08:23
  • The project has the Nunit runner – Nagoh Feb 01 '17 at 09:19

2 Answers2

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.

Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
  • 1
    Shouldn't need to add TeamCity.Dotnet.Integration, just TeamCity.VSTest.TestAdapter: https://blog.jetbrains.com/teamcity/2017/04/test-net-core-with-teamcity/ – MPritchard Jun 10 '19 at 09:10
  • TeamCity.VSTest.TestAdapter is the only thing that works for me with .NET Core 3.1 – ryanulit Apr 03 '20 at 13:54
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")
        });
});
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154