'How to get code coverage report when I run tests using java language which tests Go Project code?
I have a very special requirement in integration testing in go. In the past few days I have read through many blogs but I am unable to get the solution for this problem. Please share me if you have done anything below.
Infra details:
- Having Go project up and running
- Having my automation framework written in JAVA
My Exact requirement is:
- I have to instrument the Go code and make the go code running
- Execute my java automation code
- Stop the Go code / get the code coverage report from Go
Thanks in advance!!
Solution 1:[1]
write your Go code as a test, in a file ending_test in the package directory
run the Go test as
$ go test --coverprofile outfile. If it needs to run as a server then add some code to time it outrun your additional Java code
wait for the timeout
use a command like
$ go tool cover -html=outfile -o cover.htmlto see the coverage analysis
Solution 2:[2]
The goc tool should meet your needs, it basically just need three steps:
- launch a services registry center via
goc servercommand - use
goc build .to build your Go code and execute the generated binary which would register itself into the registry center above - Execute your automation codes, then you can use
goc profileto get the code coverage profile at anytime
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shudipta Sharma |
| Solution 2 | CarlJi |
