Can teamcity pick up test results from dotnet test in a docker container to display on the test tab?

Viewed 54

I am testing and building my service in a docker container using Teamcity's docker build command. This works fine for the build, but I would ideally like the nunit test results to be picked up and displayed in the test tab in the same way it does if you use Teamcity's dotnet test functionality.

Is this at all possible?

Using this as a guide for creating a multi-stage build to run my tests, here is my docker file so far.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /src
 
COPY ["MyService/MyService.csproj", "MyService/"]
COPY ["MyService.Tests/MyService.Tests.csproj", "MyService.Tests/"]

RUN dotnet restore "MyService/MyService.csproj"
RUN dotnet restore "MyService.Tests/MyService.Tests.csproj"

FROM restore AS build
COPY . .
RUN dotnet build "MyService/MyService.csproj" -c Release -o /app/build

FROM build AS test
RUN dotnet test "MyService.Tests/MyService.Tests.csproj" -c Release --logger "trx;LogFileName=TestResults.trx"

FROM scratch AS export-test-results
COPY --from=test /src/MyService.Tests/TestResults/*.trx .

FROM build AS publish
RUN dotnet publish "MyService/MyService.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "MyService.dll"]

My teamcity build step config looks like this:

dockerCommand {
    commandType = build {
        source = file {
            path = "MyService/Dockerfile"
        }
        contextDir = "."
        namesAndTags = "myservice:latest"
        commandArgs = "--network host --target export-test-results --output type=local,dest=."
    }
    param("dockerImage.platform", "linux")
}

I was sort of hoping that teamcity could pick up the .trx file if I presented it as an artefact of the step, but not sure if that's how tc works.

Has anyone managed this and if so, how?

TIA

Rich

1 Answers

Disclaimer: I neither tested it nor did I ever set up such a setting. But I have some experience with TeamCity, and since you didn't receive any feedback within a week, I thought it might be better than nothing

According to the TeamCity docs, I think a Build Feature called XML Report Processing could do the trick. Can you try to configure the following and see what happens?
enter image description here

Related