Search code examples
.net-coreteamcityxunitcakebuild

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

  • 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.