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?

Bjarte Aune Olsen
  • 3,230
  • 4
  • 24
  • 36
  • Did you find a fix for this? I'm getting a similar (ish) issue. – mcintyre321 May 31 '18 at 10:52
  • 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 "[" – Bjarte Aune Olsen Jun 01 '18 at 12:09
  • @mcintyre321 if you still struggling with it my answer may help. I have just solved it for my project by installing the package. – Andrii Litvinov Sep 08 '18 at 15:23
  • I just got the test to pass silently in the end :/ thanks, though! – mcintyre321 Sep 11 '18 at 15:41
  • 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... – Louis Somers May 31 '22 at 09:23

3 Answers3

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Andrii Litvinov
  • 12,402
  • 3
  • 52
  • 59
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.

Røye
  • 1,077
  • 3
  • 14
  • 27
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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
NikolayP
  • 389
  • 2
  • 5