How to install Cobertura in azure Devops? - unit-testing

I have a .net core whith CI in Azure devops.
After successfully running my unit tests, I would like to generate and display code coverage using ReportGenerator, based on this article:
https://www.meziantou.net/computing-code-coverage-for-a-dotnet-core-project-with-azure-devops-and-coverlet.htm
Part of the YAML:
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines;Cobertura
displayName: Create Code coverage report
This gives me the folling error:
...line 2: Cobertura: command not found
By removing the Cobertura from reporttypes, there are no errors, but then there are no report to be shown.
How can I install or enable Cobertura?

By removing HtmlInline_AzurePipelines from reporttypes, it worked

This way you are skipping a parameter option. Accordingly to the documentation, you can try to wrap that option with " like in the following:
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/**Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
displayName: Create Code coverage report
This should probably work as well without skipping it.

Related

Cut text of variable in google cloud pipeline

I am trying to bump a version automatically when deploying a project into a QA environment.
I have the following code
args:
- '-c'
- |
set -x
npm install
npm i -g #nrwl/cli
npm version --git-tag-version false --commit-hooks false $(TZ=UTC0 git show --quiet --date='format-local:%Y' --format="%cd").$(TZ=UTC0 git show --quiet --date='format-local:%m%d' --format="%cd").${BUILD_ID}-${SHORT_SHA}
nx run-many --target=build --all --configuration=qa-1 --parallel
nx run-many --target=deploy-qa-1 --all --configuration=qa-1 --token "$$FIREBASE_TOKEN" --parallel
This works, but I would like to shorten the BUILD_ID to only 8 digits and not the full strings.
I tried using ${BUILD_ID::8} ${$(echo BUILD_ID::8)} but what I get is a empty string.
How to achieve it ?
Currently this is not possible in Cloud Build, you can't shorten the value of substitutions by making a substring within the args of a build.
However, if you'd like to have this implemented into Cloud Build, you can open a Feature Request into Google's Issue tracker system, so that this can be considered by their product team.
This seems to work
substitutions:
_SHORT_BUILD: ${BUILD_ID:0:8}
then you can use ${_SHORT_BUILD}

Publish code coverage not finding coverage file in Azure DevOps

I'm using Node 14.x and Jest 26.x. There is a npm test script in package.json file which contains the following:
cross-env NODE_ENV=test jest --coverage --forceExit
When I run it locally, it generates the code coverage report in ./coverage directory. The contents of ./coverage directory is as follows:
lcov-report (folder)
clover.xml
coverage-final.json
lcov.info
It looks like clover.xml contains code coverage report. There are more details which can be found in lcov-report folder.
I've setup the Azure DevOps pipeline as follows for code coverage:
...
- task: PublishTestResults#2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '**/junit.xml'
# Publish code coverage results
# Publish Cobertura or JaCoCo code coverage results from a build
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/clover.xml'
After running the pipeline, Azure DevOps doesn't seem to find the cover.xml file. I get the following error:
##[debug]Result: true
##[debug]Report directory: /home/vsts/work/_temp/cchtml
Reading code coverage summary from '/home/vsts/work/1/s/coverage/clover.xml'
##[warning]No coverage data found. Check the build errors/warnings for more details.
##[debug]Processed: ##vso[codecoverage.publish codecoveragetool=Cobertura;summaryfile=/home/vsts/work/1/s/coverage/clover.xml;reportdirectory=/home/vsts/work/_temp/cchtml;]
I also tried the following options for summaryFileLocation but all resulted in same error.
'**/coverage/clover.xml'
'$(System.DefaultWorkingDirectory)/**/coverage/clover.xml'
I understand that the format of clover.xml may not be the same as Cobertura or JaCoCo, but at least Azure should be able to locate the file.
What I'm missing?
I've found a way accidentally.
It looks like Jest can generate cobertula coverage report. It needs to be added in Jest configuration. I've added the following in jest.config.js:
coverageReporters: ['text', 'text-summary', 'clover', 'cobertura']
Jest generated the cobertura coverage file in:
./coverage/cobertura-coverage.xml
Next I modified Azure pipeline file as follows:
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
After this changes, when I run the pipeline, Azure DevOps can find the file and show coverage report!

Code coverage is always unknown in GitLab

I'm trying to understand the GitLab Pipelines and after a few tries I was able to successfully automate my unit tests. Now I'm trying to add the code coverage badge into my project and/or readme file but it always seems to show unknown.
Files:
+ application
+ system
- unit-tests
- tests
UtilTest.php
autoload.php
phpunit
.gitignore
.gitlab-ci.yml
.htaccess
index.php
readme.md
.gitlab-ci.yml:
image: php:5.6
stages:
- test
app:unit-tests:
stage: test
script:
- php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests
coverage: '/Code Coverage: \d+\.\d+/'
On the project's Test coverage parsing section I have this set up:
So I was able to fix this by using PHP 7.2 as the Docker image and installing xdebug on the before_script call.
.gitlab-ci.yml:
image: php:7.2
stages:
- test
before_script:
- pecl install xdebug
- docker-php-ext-enable xdebug
app:unit-tests:
stage: test
script:
- php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests --coverage-text --colors=never
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
I had to use PHP 7.2 because when I tried running pecl install xdebug it said it requires PHP 7. Ideally I would like to use PHP 5.6 because that's what our current server has just so the tests are on similar versions but I'll leave it as it is for now.
I had to add --coverage-text --colors=never on the script call for it to output the numbers. Then on the coverage call I changed it to '/^\s*Lines:\s*\d+.\d+\%/' which I also used under the Test coverage parsing section on the project settings.
And now the code coverage properly shows me my expected values.

How can I add JavaScript code coverage to TeamCity?

I have Chutzpah running QUnit tests in TeamCity with the following command:
chutzpah.console.exe /path src /debug /teamcity /coverage /emma coverage.xml
The tests are executed and listed in the Tests tab for the build.
The file coverage.xml is created and imported using a build feature. TeamCity is reporting a successful import:
[Ant JUnit report watcher] Successfully parsed
[Successfully parsed] 1 report
[Successfully parsed] coverage.xml
I cannot get the coverage report to be displayed in TeamCity.
How can I add the code coverage report to TeamCity?
I found 2 main ways to post coverage information in Teamcity:
Teamcity Service Messages: Some coverge reporters came with Teamcity report capabilities. This is the best one in my opinion, because you can use Coverage Thresholds as build failure conditions: i.e make the build fail if coverage is below 60%
HTML reports: If your coverage reporter generates HTML reports, you can either store them as Build Artifacts, or you can create a custom build tab to display coverage information, you only need a index.html file for this: https://confluence.jetbrains.com/display/TCD9/Including+Third-Party+Reports+in+the+Build+Results

Jenkins tests reports analyzer integration with catch

I've recently started working with Jenkins to automatically build my c++ project and run my tests (I'm using catch.cpp).
I wanted some sort of a table of test run time and status and that led me to the "Test Results Analyzer" Plugin for Jenkins.
I have my builds run like this:
And you can see they actually run in the console output:
finally, my test results analyzer plugin shows nothing:
It looks like the plugin does not recognize that these are my tests. Which is reasonable since I've only told jenkins to execute these commands and i don't think it's smart enough to understand these are the tests to report. But i could not find how to tell "Test Reports Analyzer" what are the tests it needs to report.
My question is how do i get a table of tests like in the Plugins webpage:
Tests Reports Analyzer
Solution:
Jenkins needs a Junit format xml file of the test results.
specifically, in Catch.cpp this is achieved by the "-r junit" command line option.
after this i needed to configure jenkins to "Publish JUnit test result report" post-build action and git it a path to the output xml file i create with my "make test" command.
Solution provided by OP:
Jenkins needs a Junit format xml file of the test results.
specifically, in Catch.cpp this is achieved by the "-r junit" command line option.
after this i needed to configure jenkins to "Publish JUnit test result report" post-build action and git it a path to the output xml file i create with my "make test" command.