最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gitlab - Coverlet Report not working when dotnet test --no-build try split build and test stage - Stack Overflow

programmeradmin3浏览0评论

Gitlab runs gitlab-ci on ever push where the project gets build and tested.

Currently we had a "build" stage and a "test" stage but in the test stage it was still build and then testen what take time that is waste!

so i am trying to get dotnet test --no-build to work but the the covertura report will not get generated, it seems that this step needs something from the build phase that i dont transfer via artifacts but i dont know what.

to compare in one go this ci works perfect for me Working AllinOneStage:

image: at432gitlab01:5050/gitlab-helper/images/sdk:latest

variables:
  CONFIGURATION: Release
  #LOGGER: junit;LogFilePath=test-result.xml
  #COVERAGE: XPlat Code Coverage
  LOGGER: "junit;LogFilePath=test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
  COVERAGE: "XPlat Code Coverage"
    #/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura

stages:
  - buildAtest


before_script:
  - export TZ=Europe/Vienna
  - export LANG=de_DE
  - export ENV DOTNET_CLI_HOME=/tmp/build/
  - export XDG_DATA_HOME=/tmp/build/

build-project:
  artifacts:
    paths:
      # Collect all test result and coverage files from all test projects
     # - test/**/test-result.xml
     # - test/**/TestResults/**/coverage.cobertura.xml
      - TestResults/coverage.cobertura.xml
      - TestResults/test-result.xml
    reports:
      junit:
        - "test/**/test-result.xml"
    expire_in: 1 days
    when: always
  coverage: '/Total\s*\|\s*(\d+(?:\.\d+)?)/'
  script:
    - dotnet build Marketing.Api.sln -c $CONFIGURATION 
    - dotnet test test/Marketing.Api.UnitTests/Marketing.Api.UnitTests.csproj -c "$CONFIGURATION"  --logger:"junit;LogFilePath=test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"  --results-directory ../TestResults /p:CollectCoverage=true /p:CoverletOutput=../TestResults/ /p:MergeWith=../TestResults/coverage.cobertura.xml /p:CoverletOutputFormat=\"cobertura\"
  stage: buildAtest  
  tags:
    - openshift

the output from this:

Testlauf für "/builds/dienste/merketing/test/Marketing.Api.UnitTests/bin/Release/net8.0/Marketing.Api.UnitTests.dll" (.NETCoreApp,Version=v8.0)
VSTest-Version 17.11.1 (x64)
Die Testausführung wird gestartet, bitte warten...
Insgesamt 1 Testdateien stimmten mit dem angegebenen Muster überein.
Results File: test-result.xml
Bestanden!   : Fehler:     0, erfolgreich:    86, übersprungen:     0, gesamt:    86, Dauer: 400 ms - Marketing.Api.UnitTests.dll (net8.0)
  [coverlet] 
  Calculating coverage result...
   Generating report '/builds/dienste/merketing/test/Marketing.Api.UnitTests/TestResults/coverage.cobertura.xml'
+---------------+--------+--------+--------+
| Module        | Line   | Branch | Method |
+---------------+--------+--------+--------+
| Marketing.Api | 64.16% | 36.07% | 60.14% |
+---------------+--------+--------+--------+
+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 64.16% | 36.07% | 60.14% |
+---------+--------+--------+--------+
| Average | 64.16% | 36.07% | 60.14% |
+---------+--------+--------+--------+
Uploading artifacts for successful job

this is the 2 staged version where i only want it to build in first stage and only test in the test stage

image: at432gitlab01:5050/gitlab-helper/images/sdk:latest

variables:
  CONFIGURATION: Release
  LOGGER: "junit;LogFilePath=test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
  COVERAGE: "XPlat Code Coverage"

stages:
  - build
  - test

before_script:
  - export TZ=Europe/Vienna
  - export LANG=de_DE
  - export ENV DOTNET_CLI_HOME=/tmp/build/
  - export XDG_DATA_HOME=/tmp/build/

build:
  script:
    - dotnet build Marketing.Api.sln -c $CONFIGURATION
  stage: build
  artifacts:
    expire_in: 1 days
    paths:
      - "src/Marketing.Api" # Include the source directory
      - "src/Marketing.Api/bin/$CONFIGURATION/net8.0/" # Important  Artifact the build output
      - "test/Marketing.Api.UnitTests/bin/$CONFIGURATION/net8.0/"  # Include test binaries!
  tags:
    - openshift

test:
  stage: test
  needs:
    - build
  script:
    - dotnet test test/Marketing.Api.UnitTests/Marketing.Api.UnitTests.csproj -c "$CONFIGURATION" --no-build --logger:"$LOGGER" --results-directory TestResults /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat="cobertura"
  artifacts:
    expire_in: 1 days
    paths:
      - "TestResults/coverage.cobertura.xml" # Artifact the coverage report
      - "TestResults/test-result.xml" # Artifact the test results
    reports:
      junit:
        - "TestResults/test-result.xml"
      coverage_report:
        coverage_format: cobertura
        path: "TestResults/coverage.cobertura.xml"
  coverage: '/Total\s*\|\s*(\d+(?:\.\d+)?)/'
  tags:
    - openshift

output from the separeted version:

Testlauf für "/builds/dienste/merketing/test/Marketing.Api.UnitTests/bin/Release/net8.0/Marketing.Api.UnitTests.dll" (.NETCoreApp,Version=v8.0)
VSTest-Version 17.11.1 (x64)
Die Testausführung wird gestartet, bitte warten...
Insgesamt 1 Testdateien stimmten mit dem angegebenen Muster überein.
Results File: test-result.xml
Bestanden!   : Fehler:     0, erfolgreich:    86, übersprungen:     0, gesamt:    86, Dauer: 270 ms - Marketing.Api.UnitTests.dll (net8.0)
Uploading artifacts for successful job

Here very obvisouly iam missing the Report part this only happens when i suppres the build via dotnet test --no-build

发布评论

评论列表(0)

  1. 暂无评论