rillig / gobco

Measure branch coverage of golang tests
62 stars 12 forks source link

How can I get branch coverage using gobco simultaneously while running go test coverage? #23

Closed ShriprasadM closed 11 months ago

ShriprasadM commented 2 years ago

How can I get branch coverage using gobco simultaneously while running go test coverage?

I am already using go test cover command, which can compute the coverage of actually running go server

rm -frv ./test-able-exe 
go test -coverprofile=coverage.out -c main.go main_test.go -o test-able-exe -coverpkg=./...
./test-able-exe -test.coverprofile=coverage.out -test.v -test.run=TestMain 

and looking for something like following such gobco and go test will simultaneously compute coverage. Right now, I need to up the server 2 times.

rm -frv ./test-able-exe 
go test -coverprofile=coverage.out -c main.go main_test.go -o test-able-exe -coverpkg=./...
./test-able-exe -test.coverprofile=coverage.out -test.v -test.run=TestMain  -toolexec 'gobco'
rillig commented 2 years ago

I'm not sure whether it is a good idea to run go test and gobco simultaneously, even though I don't know your project setup.

Both go test and gobco take the original code and transform it to code that counts the coverage paths. Combining these counting methods may be confusing since one of them would operate on the code that has been transformed by the other, thus generating wrong position information for the tokens.

I didn't know the option -toolexec before, but it seems to me that you are not using it in the way it was originally intended to be used.

Did you try gobco's option -test? That could work to combine both coverage measurements. But since gobco doesn't support ./..., that also doesn't work.

So after these thoughts, I'd still prefer to run both tools separately on the original code. You can run them in parallel by the shell or some other mechanism that is outside of go test or gobco.

ShriprasadM commented 2 years ago

Thanks @rillig for your response.

I am trying to run QA Test Automation on Running go server. For that we are looking for go server, who can capture go test coverage as well as branch coverage (using gobco) It could be expensive and not looks logical to run QA Test automation separately for getting Line coverage and Branch coverage. Hence like Jacoco, in Java, Similar to that I am trying to combine Line Coverage and Branch coverage

ShriprasadM commented 2 years ago

Can you provide example on gobco's option -test?

rillig commented 2 years ago

Sure, here is the gobco command line to run go test -test.v -test.count 5 -check.vv:

gobco -test -test.v -test -test.count -test 5 -test -check.vv

It looks a bit strange to have these options interleaved with -test, but I didn't see any better way to avoid all the quoting and escaping issues when passing command line arguments.

rillig commented 11 months ago

I won't implement this "parallel" mode myself, as it looks too complicated to get it right. If you want to prove the opposite, feel free to do so.