Bala Krishnan
Bala Krishnan

Reputation: 580

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:

My Exact requirement is:

  1. I have to instrument the Go code and make the go code running
  2. Execute my java automation code
  3. Stop the Go code / get the code coverage report from Go

Thanks in advance!!

Upvotes: 2

Views: 4841

Answers (2)

CarlJi
CarlJi

Reputation: 251

The goc tool should meet your needs, it basically just need three steps:

  1. launch a services registry center via goc server command
  2. use goc build . to build your Go code and execute the generated binary which would register itself into the registry center above
  3. Execute your automation codes, then you can use goc profile to get the code coverage profile at anytime

Upvotes: 1

Vorsprung
Vorsprung

Reputation: 34427

  1. write your Go code as a test, in a file ending_test in the package directory

  2. run the Go test as $ go test --coverprofile outfile . If it needs to run as a server then add some code to time it out

  3. run your additional Java code

  4. wait for the timeout

  5. use a command like $ go tool cover -html=outfile -o cover.html to see the coverage analysis

Upvotes: 6

Related Questions