Git Product home page Git Product logo

go_cover's Introduction

Go coverage with -coverpkg

This repository demonstrates how the -coverpkg option works when you get test coverage of your projects.

This project has two packages, one is pkg1 and the other is pkg2. The pkg1 has enough tests, it's actually 100%. On the other hand, the pkg2 has no tests.

without_coverpkg.sh calculates the "total" coverage using go test commands without -coverpkg. with_coverpkg.sh does the same thing with the -coverpkg option. The script lists up dependency packages in the project and pass that to the -coverpkg option.

Outputs

yudai@yudai01% ./without_coverpkg.sh
?       github.com/yudai/go_cover       [no test files]
=== RUN   TestPkg1
--- PASS: TestPkg1 (0.00s)
PASS
coverage: 100.0% of statements
ok      github.com/yudai/go_cover/pkg1  1.014s
?       github.com/yudai/go_cover/pkg2  [no test files]
github.com/yudai/go_cover/pkg1/pkg1.go:7:       DoSomething     100.0%
github.com/yudai/go_cover/pkg1/pkg1.go:15:      DoSomethingElse 100.0%
github.com/yudai/go_cover/pkg1/pkg1.go:23:      CallPkg2        100.0%
total:                                          (statements)    100.0%

We don't have any tests for pkg2, but the shown coverage is 100%.

yudai@yudai01% ./with_coverpkg.sh
warning: no packages being tested depend on github.com/yudai/go_cover/pkg1
warning: no packages being tested depend on github.com/yudai/go_cover/pkg2
?       github.com/yudai/go_cover       [no test files]
warning: no packages being tested depend on github.com/yudai/go_cover
=== RUN   TestPkg1
--- PASS: TestPkg1 (0.00s)
PASS
coverage: 51.9% of statements in github.com/yudai/go_cover, github.com/yudai/go_cover/pkg1, github.com/yudai/go_cover/pkg2
ok      github.com/yudai/go_cover/pkg1  1.019s
warning: no packages being tested depend on github.com/yudai/go_cover
warning: no packages being tested depend on github.com/yudai/go_cover/pkg1
?       github.com/yudai/go_cover/pkg2  [no test files]
github.com/yudai/go_cover/main.go:3:            main            0.0%
github.com/yudai/go_cover/pkg1/pkg1.go:7:       DoSomething     100.0%
github.com/yudai/go_cover/pkg1/pkg1.go:15:      DoSomethingElse 100.0%
github.com/yudai/go_cover/pkg1/pkg1.go:23:      CallPkg2        100.0%
github.com/yudai/go_cover/pkg2/pkg2.go:3:       DoSomething     30.0%
github.com/yudai/go_cover/pkg2/pkg2.go:18:      DoSomethingElse 0.0%
total:                                          (statements)    51.9%

Now you see the real total coverage.

Conclusion

It's good to have -coverpkg option in the script to calculate the project-wide test coverage. It can revial hidden untested packages.

However, when you want to see if each package has enough unit tests, you don't want to use the -coverpkg option, becasue it makes the test comand output "integrated" coverages.

go_cover's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.