Search code examples
c#docker.net-corenunittest-coverage

Running in "No report files specified" when trying to generate test coverage in docker pipeline (Linux)


I use a linux-based docker pipeline to build and do automatic testing with the NUnit Framework in a C#-.NET-Core based solution.

"Test" job in my .gitlab-ci.yml-File:

runTests:
  stage: test
  image: docker-registry.xyz.de/${CI_PROJECT_PATH}/build:${CI_COMMIT_REF_SLUG}_backend_${CI_COMMIT_SHA}
  services:
    - name: atsnngs/mysql-aurora-compatible
      alias: mysql_test

  tags:
    - docker
    - linux
    - shared
  variables:
    GIT_STRATEGY: none
  artifacts:
    expire_in: 30m
    paths:
      - $CI_PROJECT_DIR/pages
  script:
    - mkdir $CI_PROJECT_DIR/pages
    - mkdir mkdir /tmp/pages
    - cd /app
    - nohup dotnet run --project ./ServiceLoader/ServiceLoader.csproj Test > dotnetcore.log &
    - sleep 10s && dotnet test -v normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude=[NUnit3.TestAdapter]*
    - reportgenerator -reports:/app/Tests/coverage.opencover.xml -targetdir:/tmp/pages
    - ls -l /tmp/pages
    - mv /tmp/pages/index.htm /tmp/pages/index.html
    - mv /tmp/pages $CI_PROJECT_DIR/
  dependencies:
    - build

In the Dockerfile, which I use to build the image I am using to execute testing, I install the report generation tool (For readability reasons I skipped the dotnet restore and build parts of the Dockerfile):

FROM microsoft/dotnet:2.1-sdk AS build

# install reportgenerator
RUN dotnet tool install --global dotnet-reportgenerator-globaltool
ENV PATH /root/.dotnet/tools:$PATH

But when I ran the pipeline the report generation fails:

$ reportgenerator -reports:/app/Tests/coverage.opencover.xml -targetdir:/tmp/pages
No report files specified.

I have already compared the Dockerfile and .gitlab-ci.yml file with another project I used this approach and could not find any difference which could explain this error. Is there any other place where I need to have a look at?

Any help is highly appreciated!


Solution

  • The problem is solved through adding the Nuget packages for coverlet.msbuild and dotnet-reportgenerator-cli. These packages are missing and lead to the error in the report generation.

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <IsTestProject>true</IsTestProject>
        <IsPackable>false</IsPackable>
        ...
      </PropertyGroup>
    
      <ItemGroup>
        ...
        <PackageReference Include="Nunit" Version="3.11.0" />
        <PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
        <PackageReference Include="coverlet.msbuild" Version="2.4.0" />
        <PackageReference Include="dotnet-reportgenerator-cli" Version="4.0.5-rc2" />
    
      </ItemGroup>
    
    </Project>