'TeamCity doesn't pick up result of xUnit tests when testing .NET Core project

I have a small .NET Core project, where the complete build/test/deploy process is handled in a Cake script.

I have a powershell script that runs the cake script.

When running the script locally, I get the result of each failing xUnit test, but when running the same script through TeamCity's PowerShell runner, I don't get the result of each test, just a summary of the number of failing tests.

The Cake task:

Task("Test")
    .IsDependentOn("Clean")
    .Does(() =>
    {
        GetFiles("./tests/**/*.csproj")
            .ToList()
            .ForEach(file => DotNetCoreTest(file.FullPath));
    });

This Cake code runs "dotnet test" under the hood.

When running the script manually in PowerShell on the build server, I get this output:

Test run for c:\project\myproject\tests\Web.Tests\bin\Debug\netcoreapp2.0\Web.Tests.dll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Starting test execution, please wait...
[xUnit.net 00:00:00.7397647]        Web.Tests.UnitTest1.Test1[FAIL]
Error Message:
 Assert.False() Failure
Expected: False
Actual:   True
Test Run Failed.
Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.
Test Run Failed.

When running the same script with TeamCity's PowerShell runner, I get this instead:

[14:27:45]  [Step 1/1] Test run for D:\TeamCity\buildAgent\work\7ff27c4721bc4a68\tests\Web.Tests\bin\Release\netcoreapp2.0\Web.Tests.dll(.NETCoreApp,Version=v2.0)
[14:27:45]  [Step 1/1] Microsoft (R) Test Execution Command Line Tool Version 15.7.0
[14:27:45]  [Step 1/1] Starting test execution, please wait...
[14:27:48]  [Step 1/1] Failed   Web.Tests.UnitTest1.Test1
[14:27:48]  [Step 1/1] Error Message:
[14:27:48]  [Step 1/1]  Assert.False() Failure
[14:27:48]  [Step 1/1] Expected: False
[14:27:48]  [Step 1/1] Actual:   True
[14:27:48]  [Step 1/1] Test Run Failed.
[14:27:48]  [Step 1/1] Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.

As you can see, it's missing the one line containing the name of the failing test.

Any idea why that might be?



Solution 1:[1]

Test .NET Core projects with TeamCity article explains this behavior.

You have to install the TeamCity.VSTest.TestAdapter package to grab the output from the tests.

Solution 2:[2]

Not sure if this is the same problem, but I ran into a similar issue when I recently upgraded from dotnet v2.0.8 to v2.1.0. In my case, after upgrading I no longer got any output from unit tests in Teamcity.

So far, the only workaround I have found was to use the dotnet xunit CLI tool in my unit test build step in Team City.

Note: This command can only be run from within the project using the command "dotnet xunit -teamcity".

It should be possible to configure this to run with Cake using the DotNetCoreTool alias.

Solution 3:[3]

Tests might not be reported correctly for .NET Core xunit test projects when logging verbosity levels is minimal or quiet because of issue 1706, so try avoiding using these verbosity levels.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wai Ha Lee
Solution 2 Røye
Solution 3 Wai Ha Lee