Document fixed OJSI-121 vulnerability
[aaf/sms.git] / docs / coverage.md
1 ## Code Coverage Reports for Golang Applications ##
2
3 This document covers how to generate HTML Code Coverage Reports for
4 Golang Applications.
5
6 #### Generate a test executable which calls your main()
7
8 ```sh
9 $ go test -c -covermode=count -coverpkg ./...
10 ```
11
12 #### Run the generated application to produce a new coverage report
13
14 ```sh
15 $ ./sms.test -test.run "^TestMain$" -test.coverprofile=coverage.cov
16 ```
17
18 #### Run your unit tests to produce their coverage report
19
20 ```sh
21 $ go test -test.covermode=count -test.coverprofile=unit.out ./...
22 ```
23
24 #### Merge the two coverage Reports
25
26 ```sh
27 $ go get github.com/wadey/gocovmerge
28 $ gocovmerge unit.out coverage.cov > all.out
29 ```
30
31 #### Generate HTML Report
32
33 ```sh
34 $ go tool cover -html all.out -o coverage.html
35 ```
36
37 #### Generate Function Report
38
39 ```sh
40 $ go tool cover -func all.out
41 ```