Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 650
Bjarte Aune Olsen Avatar asked May 18 '18 09:05

Bjarte Aune Olsen


People also ask

How do I run xUnit tests in Teamcity?

Using the pluginDownload and install the plugin as per Teamcity documentation. Select the xUnit runner for the build step, then select the version of xUnit your tests are written in, and finally a pattern to match your test binaries. Wildcards are supported, such as **/*. Tests.

Can xUnit be used with .NET framework?

I've been using xUnit for quite some time now, and it's my Unit testing framework of choice. It's an open source unit testing tool for . Net framework that's compatible with ReSharper, CodeRush, TestDriven.Net, and Xamarin. You can take advantage of xUnit.Net to assert an exception type easily.

What test runners can be used to test xUnit.net tests?

Running tests with Visual Studiorunner. visualstudio ). If you have Visual Studio Community (or a paid-for version of Visual Studio), you can run your xUnit.net tests within Visual Studio's built-in test runner (named Test Explorer).


1 Answers

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.

like image 135
Andrii Litvinov Avatar answered Sep 20 '22 00:09

Andrii Litvinov