Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What does complexity mean? #20

Closed
laserprec opened this issue Oct 29, 2021 · 5 comments
Closed

What does complexity mean? #20

laserprec opened this issue Oct 29, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@laserprec
Copy link

laserprec commented Oct 29, 2021

Feature Request

Hi there! Great tool you are building here! Much appreciated. Looking at the documentation in the README.md, the example output has a measure of complexity:

Company.Example: Line Rate = 83%, Branch Rate = 69%, Complexity = 671, ✔
Company.Example.Library: Line Rate = 27%, Branch Rate = 100%, Complexity = 11, ❌
Summary: Line Rate = 83% (1212 / 1460), Branch Rate = 69% (262 / 378), Complexity = 682, ✔
Minimum allowed line rate is 50% 

I am wondering what does it mean and how it is measured?

The reason I am asking is because I ran the coverage report for the first time in my repo and I have zeroes for the Branch Rate and Complexity (please see the following). I am not sure if this is by design or I did something wrong.

Package Line Rate Branch Rate Complexity Health
some.package.a 77% 0% 0
some.package.b 20% 0% 0
Summary 80% (80 / 100) 0% (0 / 0) 0

Expected Behaviour

It would be great if the documentation can be updated on complexity and branch rate as well.

Thanks!

@laserprec laserprec added the enhancement New feature or request label Oct 29, 2021
@irongut
Copy link
Owner

irongut commented Oct 29, 2021

Hi @laserprec all the values come from the Cobertura file produced by your tests so we would look to the Cobertura FAQ for a definition:

McCabe's cyclomatic code complexity algorithm is used to determine how "complex" a given piece of code is. As code becomes more complex, it becomes more error prone. If a class has a high complexity number, then that class is a good target for additional test coverage.

If you use a tool like Coverlet or gcovr to produce the Cobertura file I assume they use the same algorithm as but it may be worth checking if your tool has an FAQ that describes how it calculates complexity.

Branch rate is to do with conditional code - if you have an if statement in a method it has multiple branches, one for each posible path.

I'm not sure why you're getting results with branch rate & complexity at zero. If you could provide the coverage file that produced those results it would help. If you don't want to post it here we can arrange a private channel for you to share it with me.

@laserprec
Copy link
Author

laserprec commented Oct 29, 2021

Thanks a lot for that explanation! I think the source of the issue is because I am using a python package coverage to regenerate the xml files. Although it does produce reports in Cobertura format, but it does not produce metrics like branch rate and complexity.

Since the tool is not targeted towards the python environment, not sure if there's an interest to provide an option to turn on/off these extra metrics like branch rate and complexity in the generated reports.

@irongut
Copy link
Owner

irongut commented Oct 29, 2021

Options for disabling some metrics would be possible.

I'd like CCS to be compatible with all tools that output Cobertura reports (or something similar enough) and coverqge.py is on my list to test. Unfortunately I'm not a Python dev so it would be a while before I get round to it. If you could provide a sample xml file it would help.

@laserprec
Copy link
Author

Sounds good. Please feel free to fetch any of the build artifacts from this open source repo. All of the .coverage* files are the immediate file format that coverage.py consumes. To produce the Cobertura xml files, you can:

  1. download any .covarage_* file to your working directory
  2. pip install coverage
  3. run python -m coverage xml to produce the xml files.

@irongut
Copy link
Owner

irongut commented Nov 25, 2021

@laserprec I've just released CodeCoverageSummary v1.2.0 which includes support for hiding the Branch Rate and Complexity values. I've also included an explanation of the values in the project wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants