summaryrefslogtreecommitdiffstats
path: root/docs/coverage.md
blob: 61683423097da6393d78cdc11fdf98ac64e1601e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## Code Coverage Reports for Golang Applications ##

This document covers how to generate HTML Code Coverage Reports for
Golang Applications.

#### Generate a test executable which calls your main()

```sh
$ go test -c -covermode=count -coverpkg ./...
```

#### Run the generated application to produce a new coverage report

```sh
$ ./sms.test -test.run "^TestMain$" -test.coverprofile=coverage.cov
```

#### Run your unit tests to produce their coverage report

```sh
$ go test -test.covermode=count -test.coverprofile=unit.out ./...
```

#### Merge the two coverage Reports

```sh
$ go get github.com/wadey/gocovmerge
$ gocovmerge unit.out coverage.cov > all.out
```

#### Generate HTML Report

```sh
$ go tool cover -html all.out -o coverage.html
```

#### Generate Function Report

```sh
$ go tool cover -func all.out
```