Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS : dotnet with Docker fail to publish tests

I try to publish my unit tests on VSTS during the continuous integration, I use docker, and at the time the Publish task is played, I still get the following error, thus the xml file resulting from the dotnet test command can"t be found.

No test result files matching **\test-results.xml were found.

If I run the command docker-compose run web-tests locally, a tests-results folder is created containing the expected test-results.xml file.

What I am doing wrong on VSTS ?

The code repo : Github

My folder architecture:

web/
├── web/
│   └── web.csproj
│   └── Dockerfile
│       
├── web.test/
│  └── web.test.csproj
│       
└── web.sln
└── docker-compose.yml
└── docker-compose.override.yml

Dockerfile (EDIT remove extra dotnet test command) :

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src 
COPY web.sln ./
COPY web/web.csproj web/
COPY web.test/web.test.csproj web.test/
RUN dotnet restore -nowarn:msb3202,nu1503
COPY . .
WORKDIR /src/web
RUN dotnet build -c Release -o /app

FROM build as test
WORKDIR /src/web.test
#RUN dotnet test

FROM build AS publish
WORKDIR /src/web
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "web.dll"]

docker-compose.yml:

version: '3.4'
services:
  web:
    image: web
    build:
      context: .
      dockerfile: web/Dockerfile
  web-tests:
    image: web-tests
    build:
      context: .
      dockerfile: web/Dockerfile      
      target: test
    volumes: 
      - ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests

docker-compose.override.yml:

version: '3.4'
services:
  web:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "80"
  web-tests:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "80"
    entrypoint:
      - dotnet
      - test
      - --logger
      - trx;LogFileName=/tests/test-results.xml

And my both VSTS Tasks docker-compose run task publish tests task

like image 947
Cladoo Avatar asked Mar 26 '18 13:03

Cladoo


2 Answers

You should remove the RUN dotnet test in the Dockerfile as you are running the tests using the entrypoint option in compose file. If you have the RUN dotnet test and any test fails, the whole build will fail without generating any test result file.

If all your tests pass, then the "publish test results" tasks should succeed (but note that you run the tests twice).

Did you tried with a successful test suite?

like image 87
eiximenis Avatar answered Nov 15 '22 22:11

eiximenis


You need to uncheck Run In Background option of Docker Compose task.

enter image description here

like image 33
starian chen-MSFT Avatar answered Nov 15 '22 21:11

starian chen-MSFT