question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option --threshold doesn't work, coverage.json is empty

See original GitHub issue

Hi there!

I am trying to implement Coverlet in my pre-commit script, unit tests are still to be written. I am using this option: coverlet CBPm.Validations.Test --target "dotnet" --targetargs "test . --no-build" --threshold 80

This snippet sholud retrun non zero value if code coverage is less than 80%. In my case code coverge is 0% and I still get zero exit code instead of non zero exit code.

In addition to this coverage.json file is generated but it is empty.

Any help would be appreciated.

Kind regards! 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
milica-nikoliccommented, Sep 21, 2021

Hi Dave,

Thank you for your help and instructions.

I managed to get it working using coverlet.msbuild in GitLab CI pipeline, everything works properly now.

Here is snippet of code, maybe it will be helpful for other developers 😃

code coverage:
  stage: Test
  image: mcr.microsoft.com/dotnet/nightly/sdk:3.1
  allow_failure: false
  before_script:
    - cd ./Path.To.Tests
    - dotnet add package coverlet.msbuild
  script:
    - cd ..
    - mkdir coverletReport
    - dotnet test /p:CollectCoverage=true /p:Threshold=0 /p:CoverletOutput=testResults/ /p:CoverletOutputFormat=opencover
    - mv ./Path.To.Tests/testResults/coverage.opencover.xml coverletReport
  artifacts:
    when: always
    paths:
      - coverletReport
    expire_in: 8 week
  tags:
    - dev
    - docker
1reaction
daveMuellercommented, Aug 3, 2021

I guess your ouput looks somewhat like this?

Calculating coverage result...
  Generating report 'D:\Repos\coverlet\src\coverlet.console\bin\Debug\net5.0\coverage.json'
+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 0%   | 0%     | 0%     |
+---------+------+--------+--------+
| Average | 0%   | 0%     | 0%     |
+---------+------+--------+--------+


D:\Repos\coverlet\src\coverlet.console\bin\Debug\net5.0\coverlet.console.exe (process 25356) exited with code 0.

Your solution doesn’t seem to have any module or the module can’t be detected by coverlet. Thus coverlet can’t instrument any module and isn’t able to calculate any coverage. If the coverage result is empty then also the coverage report is empty.

The command in your first comment should return a non zero exit code even when no assemblies can be instrumented. This is a bug, thanks for reporting 👍. It seems that I missed this while working on #1083.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest finds tests but doesn't collect coverage
I found that when upgrading jest (from 23 to 26) that i had this issue, and the resolution was to run with the...
Read more >
How do I increase my code coverage, or why can't I cover ...
Code coverage is a measurement of how many unique lines of your code are executed while the automated tests are running.
Read more >
Full code-coverage with Jest - tsmx
When running Jest with the --coverage option (like in our npm run test-coverage ), it generates a report under coverage/lcov-report/index.html .
Read more >
Use code coverage for unit testing - .NET
Code coverage is a measurement of the amount of code that is run by unit tests - either lines, branches, or methods. As...
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found