uartois / sonar-golang

Sonarqube plugin for the golang language.
GNU Lesser General Public License v3.0
245 stars 32 forks source link

Untested files are ignored for code coverage #56

Open kernle32dll opened 6 years ago

kernle32dll commented 6 years ago

Description

I noticed that files which are not tested at all do not decrease the code coverage. E.g. a project with two files, with one being 100% tested and the other not at all, code coverage in total will still be 100%.

Steps to Reproduce

  1. Create a project with two files to test (e.g. main.go and test.go)
  2. Write code and tests for test.go
  3. Coverage will only depend on test.go, not on main.go

Additional Information

If coverage for untested files should be ignored or set to 0 is a choice of preference. Thus, it should be settable via sonar-project.properties.

danielleberre commented 6 years ago

We provide the per file coverage to SonarQube. The total coverage is then computed automatically by SonarQube.

Since we provide metrics only for the files found in the coverage xml file, the other classes have no coverage information, thus are "ignored" in the coverage computation.

We can add a new property to force to 0% untested files, just like JaCoCo plugin.

@thibaultfalque If we want to implement this, we probably need a new type of files (test files) in our plugin.

thibaultfalque commented 6 years ago

I asked for correctly detect source code file and test file. https://groups.google.com/forum/#!topic/sonarqube/4CkPFEKYRpc

thibaultfalque commented 6 years ago

@Kernle32DLL can you test the new release.

kernle32dll commented 6 years ago

@thibaultfalque works like a charm. Might be worth to include the parameters as stated in https://github.com/uartois/sonar-golang/releases/tag/v1.2.11-rc10 as sensible defaults.

thibaultfalque commented 6 years ago

I searched a solution for add default value but it's not directly possible because properties are sonar properties and not plugin properties, so I can't set a default value. You can change the default value of these properties from the web interface.