Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,33 @@ gometalinter.v1 --checkstyle > report.xml

# Coverage (since release 1.1)

For coverage metrics you must have a `coverage.xml` (cobertura xml format) file *per package*.
For coverage metrics you must have one or multiple `coverage.xml` (cobertura xml format) files.

* First install the tools for converting a coverprofile in cobertura file:
```shell
go get github.com/axw/gocov/...
go get github.com/AlekSi/gocov-xml
```

* Then for all packages execute those commands:
* Then from the root of your project:
```shell
gocov test ./... | gocov-xml > coverage.xml
```

Note that `gocov test ./...` internally calls `go test` with the `-coverprofile` flag for
all folders and subfolders, and assembles the coverprofile accordingly by itself (this is
nessecary, as Golang up to 1.9 did not support the combination `gocov test ./... -coverprofile=...`).

If you want to invoke `go test` manually, you need to do this and the conversion by each
package by yourself. For example:

* For all packages execute those commands:
```shell
go test -coverprofile=cover.out
gocov convert cover.out | gocov-xml > coverage.xml
```

You must end-up with one coverage file per directory:
You then end-up with one coverage file per directory:
```
pkg1/coverage.xml
pkg2/coverage.xml
Expand All @@ -103,7 +115,7 @@ pkg3/coverage.xml
```


This is an example of script for create all coverage files for all packages in one time.
This is an example of script for create all coverage files for all packages in one time.


```bash
Expand All @@ -121,10 +133,10 @@ do
cd $D
go test -coverprofile=cover.out
gocov convert cover.out | gocov-xml > coverage.xml
cd ..
cd ..
done
```
or
or

```bash
go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/cover.out {{.ImportPath}}"{{end}}' ./... | xargs -L 1 sh -c
Expand Down