How to trigger Coverage badge and Test Coverage Visualization with cobertura coverage xml?

I’m trying to trigger proper coverage badge generation and test coverage visualization for one of my pet project.

This is my current config file.

I have successfully generated a Cobertura format xml for my coverage that stores in tests/_output/cobertura.xml. And I can also see my artifacts setting work there:

I’ve merged it into my main branch. Everything seems to work except the coverage badge is still
2022-01-15 23-27-51 的螢幕擷圖.

Also, the Cobertura xml file generated seems quite normal to me.

What did I miss?

@yookoala Thanks for the post and welcome to the forum!

I’m glad to see you got the text coverage visualization working!

To get the badge working you still need to setup parsing for the coverage value from the logs as described here in the documentation. Looking at your latest Merge Request adding ^\s*Lines:\s*\d+.\d+\% should work and then the badge will start to work once a pipeline has completed.

I hope this helps!

-James H, GitLab Product Manager, Verify:Pipeline Execution

Thanks! Did the following and the badge works:

  1. Added an extra grep to show the text coverage text without ANSI (I want colour for my test output).
  2. Add the coverage regex as mentioned.

Thanks for the help.

1 Like

@jheimbuck_gl I don’t see anything in that link about

parsing for the coverage value from the logs.

Can you be more specific?

@gabriel.co it looks like the docs changed since this post.

Searching the docs for “Code Coverage” leads me to this: Code coverage | GitLab

Hope that helps!

-James H, GitLab Product Manager, Analytics:Product Analytics

OK, I found it, and it works, but here’s some feedback:

  1. It’s quite confusing that you need to change two different sections of the job configuration to enable the code coverage features of GitLab. Some features are enabled by the coverage attribute and the corresponding regex, and others are enabled by the coverage report under artifacts.
  2. It also doesn’t make a lot of sense that only one format (Cobertura) is supported for the report and multiple are supported for the regex.
1 Like