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
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?
You need to uncheck Run In Background option of Docker Compose task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With