Test Coverage for Integration Tests

241 views
Skip to first unread message

sidgo...@gmail.com

unread,
Dec 30, 2013, 1:41:28 PM12/30/13
to golan...@googlegroups.com
I'm trying to figure out how to generate coverage metrics for integration tests. I have a webapp with two packages: a 'handlers' package that specifies a set of http apis and a 'users' package to fetch user data from the database.

I have unit tests for each package and can use go test -cover to generate coverage reports for each package.

In addition, I have some integration tests to test the end-to-end flow. The tests start the app using httptest and send some http requests to the server. Since go test -cover generates metrics on a per-package basis, the metrics aren't accurate. For instance, if the integration tests are defined in the main package, I only see coverage metrics for the main package. I'd like to also see how much of the code in the handlers and users package was tested.

Is this possible?

Thanks
Sid

Caleb Spare

unread,
Dec 30, 2013, 9:11:09 PM12/30/13
to Siddharth Gopalan, golan...@googlegroups.com
Hi Sid :)

I haven't run many coverage tests myself, but looking at 'go help testflag' I see the -coverpkg flag:

-coverpkg pkg1,pkg2,pkg3
   Apply coverage analysis in each test to the given list of packages.
   The default is for each test to analyze only the package being tested.
   Packages are specified as import paths.
   Sets -cover.

Is this what you need?

-Caleb


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

sidgo...@gmail.com

unread,
Dec 31, 2013, 12:23:44 AM12/31/13
to golan...@googlegroups.com, Siddharth Gopalan
That's exactly what I was looking for.
Thanks Caleb
Sid
Reply all
Reply to author
Forward
0 new messages