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

3

7

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?

Lilith answered 18/5, 2018 at 9:25 Comment(5)
Did you find a fix for this? I'm getting a similar (ish) issue.Acetone
No, I'm afraid not. I have upgraded TeamCity and upgraded the project to .NET Core 2.1, but I still have the same issue. Maybe it's just something silly, like TeamCity hiding all lines that start with "["Lilith
@Acetone if you still struggling with it my answer may help. I have just solved it for my project by installing the package.Shephard
I just got the test to pass silently in the end :/ thanks, though!Acetone
I initially thought I had this same issue, but in the end I had forgotten to add the XML report processing build feature, thought adding this might help someone out...Genaro
S
8

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.

Shephard answered 8/9, 2018 at 15:18 Comment(0)
S
3

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.

Smitherman answered 23/7, 2018 at 14:34 Comment(0)
T
0

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.

Timeous answered 11/12, 2018 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.