Vitaliy
Vitaliy

Reputation: 183

Is it possible to compile a Go program with specific flags for coverage analysis?

Is it possible to compile a Go program with specific flags for coverage analysis?

The use case:

Should be something similar to Gcov or Python coverage.

Many Thanks!

Upvotes: 3

Views: 376

Answers (1)

Intermernet
Intermernet

Reputation: 19408

Yes, Go has the cover tool (as of version 1.2) incorporated into the test process. go test alone will compile your program and run any automated tests you may have. Adding the -cover flag will provide statistics on test coverage.

To run it:

go test -cover

You can also output a coverage profile:

go test -coverprofile=coverage.out

and then view it with:

go tool cover -func=coverage.out

or

go tool cover -html=coverage.out

for HTML formatted output (with colour coding).

See http://blog.golang.org/cover , go tool cover -h and go help testflag for more info.

Upvotes: 6

Related Questions