How can one view line-by-line code coverage in GitHub? - github

I have a Node.js project, which includes Istanbul, a tool that can generate a code coverage report. I would like to see which lines are not covered and which are covered by tests in my GitHub Pull Requests for this project.
Istanbul allows me to see the coverage locally in the coverage/lcov-report directory, but I would like to see this the "Files Changed" tab of my Pull Requests in GitHub.
There are some tools that provide visual line-by-line coverage:
CodeCov does this, but requires that I upload a coverage report to their servers.
Covaralls does also, but requires that you give them access to your repository.
Jest coverage report uses GitHub actions to add annotations, but cannot add visual indications (e.g. highlighting) of line-by-line test coverage.
Is there any other way to visualize line-by-line test coverage in a GitHub Pull Request?

Related

How to see the Code Coverage results in Sonar Qube using Azure DevOps pipelines

I have an .Net Core application along with unit test cases. For that I have configured the Build pipeline in Azure DevOps. In that pipeline I have integrated SonarQube tasks (prepare analysis, run code analysis, and publish quality gate results).
I can see the report in SonarQube server after successful run. But in that report, I didn’t see the Code Coverage Results and Unit test results. Even though I used Cobertura for unit tests.
Your pipeline seems to contain the right steps, so there can be two issues:
1. Code coverage file is not generated (correctly)
The easiest way to validate if the code coverage file is generated correctly, is by publishing it as an artifact. Now check what format the output file is. If there is no output file, please check if you did include /p:CollectCoverage=true --logger trx to the test command. If you are running the build pipeline on Linux, you should also add /p:CoverletOutputFormat=opencover and install the coverlet.collector NuGet package in the .NET Test Project.
2. Code coverage file is not sent to Sonarqube
If you configured step 1 correctly, it is still possible that the generated files are not sent to Sonarqube. The best way to see what is going wrong, is by checking the build logs of the Run Code Analysis and Publish Quality Gate Results steps.
The most common issue, is that Sonarscanner is checking the wrong directory. In the prepare step, please specify where the files are located, like:
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
Build pipeline generates code coverage files would it be coverlet or opencover, the problem is that Azure Devops pipeline creates the reports outside the working directory on the build agent, it uses the _temp folder inside _work whereas soanrquube searches inside the working directory. I am facing this issue with coverlet as well as Visual studio coverage tool. You can read the following 2 threads
https://github.com/coverlet-coverage/coverlet/issues/1399
https://github.com/microsoft/azure-pipelines-tasks/issues/11536.
I posted an issue on snoarqube community site but did not get any response so far. The solution I think is either make the test step in the build pipeline change the directory or configure somewher sonarqube to search the agent build directory _temp which is above the working directory

how to display unit test results from azure devops in github

I have a pipeline that runs on pull requests and executes tests , it also produces an xml execution report (it is a node project and tests run via jest) , and coverage report that I use for sonarcloud. However , the developers want to be able to see the tests results on each pr and see what tests failed in particular, so my question is whether it is possible to somehow export and display those results in github or sonarcloud
Please refer to the following two methods to get the test cases metric in sonarcloud:
You can add sonar.testExecutionReportPaths in Additional Properties option in Prepare Analysis Configuration task. About sonar.coverageReportPaths
For SonarQube to pick up and analyse the content of the report file, you need to inform the sonar scanner. About the location of the XML file. To do so, edit the sonarqube.properties file. Please refer to this.
coverage reporting:
sonar.testExecutionReportPaths=reports/xxx/xxx.xml
In addition, you can also refer to this similar case.

How to add code coverage metrics to a PR?

I am going to add code coverage to a repo, so when a PR is created the CI is going to generate code coverage reports with lcov.
What is the best way to show this metric in a PR to the dev?
In the end, I had to make a python script to:
1- Look for packages with tests.
2- For each language have a different strategy (I had Python 2, Python 3 and C++ tests in the same repository).
3- Combine all the coverage results in one folder.
4- With regex look for the coverage percentages.
5- Build a nice table with the data and show it via a PR comment.
Graphs and more fancy output can also be done after the regex step.

how to generate codeception code coverage badge on github?

I'm looking for some automated way to generate a badge with code coverage information in Github repo's README file based on reports created by Codeception. I am aware of hosted services like coverals, but is there a script/library to generate on my own in a travis pipeline?

Missing "Code Coverage" tab on Python project

I have a Python project hosted on GitHub, which I test using Azure Pipelines (here is a link to the configuration).
I am running unit tests with pytest and get coverage results, which I upload in my pipeline. I get an overall code coverage percentage in the pipeline execution summary (example), but I don't see a "Code Coverage" tab that contains the details of which lines are covered. The build artifacts contain the HTML code coverage report, which contains this information, but it'd be nicer to see it in the pipeline run page itself.
Here is the invocation of pytest:
pytest tests --doctest-modules --junitxml=junit/test-results.xml
--cov=callgraph --cov-report=xml --cov-report=html
What am I missing?
that doesnt work like that, unfortunately. at least that was the case 6 months ago.
https://github.com/Microsoft/azure-pipelines-tasks/issues/7703