How can I get test result from .NET Core/MSTest with docker wrapper?
Answered
I'm trying to get test result on TeamCity but I have no idea how to do that.
My setup is:
- TeamCity Server 2019.1.2 (build 66342)
- .NET Core 3.0-preview8 project
- depends on Microsoft.NET.Test.Sdk, MSTest.TestFramework and MSTest.TestAdapter
- Command runner which runs only follow command:
`dotnet test` - with Docker image: `mcr.microsoft.com/dotnet/core/sdk\:3.0.100-preview8-alpine3.9
And log:
[11:48:04] [Step 3/5] Microsoft (R) Test Execution Command Line Tool Version 16.3.0-preview-20190715-02
[11:48:04] [Step 3/5] Copyright (c) Microsoft Corporation. All rights reserved.
[11:48:04] [Step 3/5]
[11:48:05] [Step 3/5] Starting test execution, please wait...
[11:48:06] [Step 3/5] Test run for /home1/irteamsu/BuildAgent/work/a5cf358b9cf0df99/My.Api.Test/bin/Debug/netcoreapp3.0/My.Api.Test.dll(.NETCoreApp,Version=v3.0)
[11:48:06] [Step 3/5] Microsoft (R) Test Execution Command Line Tool Version 16.3.0-preview-20190715-02
[11:48:06] [Step 3/5] Copyright (c) Microsoft Corporation. All rights reserved.
[11:48:06] [Step 3/5]
[11:48:06] [Step 3/5]
[11:48:06] [Step 3/5] Test Run Successful.
[11:48:06] [Step 3/5] Total tests: 23
[11:48:06] [Step 3/5] Passed: 23
[11:48:06] [Step 3/5] Total time: 1.7095 Seconds
[11:48:06] [Step 3/5] Starting test execution, please wait...
[11:48:09] [Step 3/5]
[11:48:09] [Step 3/5] Test Run Successful.
[11:48:09] [Step 3/5] Total tests: 50
[11:48:09] [Step 3/5] Passed: 50
[11:48:09] [Step 3/5] Total time: 2.2964 Seconds
[11:48:09] [Step 3/5] Process exited with code 0
I saw `https://github.com/JetBrains/TeamCity.VSTest.TestAdapter` but I don't think it gonna work for MSBuild(v2).
How can I make `dotnet test` to work with TeamCity?
Please sign in to leave a comment.
Hi Gongdo,
How do you run tests? Which build runner do you use? May I ask you to provide more details (maybe a couple of settings screenshots, a build result screenshot and a build log)?
@Nadia, my project is pretty simple.
As I wrote above, the Docker container image is: mcr.microsoft.com/dotnet/core/sdk\:3.0.100-preview8-alpine3.9
And build log for the `dotnet test` is also in the post.
Maybe I should add some MSBuild adapter implementation in my project then add some argument for `dotnet test`.
But I couldn't find a way to implement MSBuild adapter for TeamCity.
I just wonder if there's easier way or guideline to integrate dotnet core test(MSBuild v2) result with TeamCity.
Could you please try to use .NET CLI build step? It also has an ability to start a build in a docker wrapper and automatically parse test results.
@Nadia, unfortunately, .NET CLI build step doesn't work with docker container setting. It's known issue: https://youtrack.jetbrains.com/issue/TW-61085
Hi Gongdo,
You're right. In this case, you need to add the additional TeamCity adapter to your test project to make TeamCity parse tests result. Please, refer to the adapter page on the GitHub for more information.
The steps are quite simple:
1. add the adapter to the test project: `dotnet add package TeamCity.VSTest.TestAdapter`
2. run tests the same way as you did before in Command Line step: `dotnet test`
@Nadia, It works! I thought I had to set extra configs for TeamCity, but it turns out it's dead simple as you said.
I only want to add comment that you need to set `TEAMCITY_VERSION` environment when you want to see the TeamCity test result in your machine.
Thanks very much!
Yes, the adapter uses this env variable to understand that it's started inside TeamCity build if you want to see the same output locally on a machine you can set this variable.
Thank you for letting us know and glad to hear that I could help.