Coverage testing tool for The Go Programming Language

Overview

gocov

Coverage reporting tool for The Go Programming Language

Build Status

Installation

go get github.com/axw/gocov/gocov

Usage

There are currently four gocov commands: test, convert, report and annotate.

gocov test

Running gocov test [args...] will run go test [args...] with an implicit -coverprofile added, and then output the result of gocov convert with the profile.

gocov convert

Running gocov convert <coverprofile> will convert a coverage profile generated by go tool cover to gocov's JSON interchange format. For example:

go test -coverprofile=c.out
gocov convert c.out | gocov annotate -

gocov report

Running gocov report <coverage.json> will generate a textual report from the coverage data output by gocov convert. It is assumed that the source code has not changed in between.

Output from gocov test is printed to stdout so users can pipe the output to gocov report to view a summary of the test coverage, for example: -

gocov test | gocov report

gocov annotate

Running gocov annotate <coverage.json> <package[.receiver].function> will generate a source listing of the specified function, annotating it with coverage information, such as which lines have been missed.

Related tools and services

GoCovGUI: A simple GUI wrapper for the gocov coverage analysis tool.

gocov-html: A simple helper tool for generating HTML output from gocov.

gocov-xml: A simple helper tool for generating XML output in Cobertura format for CIs like Jenkins and others from gocov.

Comments
  • feature request: gocov test should accept multiple packages to test

    feature request: gocov test should accept multiple packages to test

    gocov should accept the path globs that go test does. ie

    gocov test ./... gocov test std

    The goal is to be able to produce test coverage for an entire project, ie

    gocov test launchpad.net/juju-core/... | gocov report

    Internally gocov will execute an independent instrumentAndTest() for each package.

    opened by davecheney 22
  • annotate: option to only produce results for <100% coverage

    annotate: option to only produce results for <100% coverage

    Discovered this nice tool a few days ago. Thank you for making it available. What I would like is an option to annotate to only show routines that have less than 100% coverage (= have at least one 'miss' mark). That could be of help to quickly find out where exactly testing could be improved. Johan

    opened by JohanSamyn 16
  • no Go source files

    no Go source files

    I'm not quite sure what's happening here, but I'm trying to run tests in github.com/couchbaselabs/cbgb/cbgb and I get the following:

    /var/folders/nt/_3y11_t12szbmgshvz6zgbhh0000gn/T/gocov343768907/src/pkg/github.com/couchbaselabs/cbgb/cbgb/main.go:11:2: no Go source files in /var/folders/nt/_3y11_t12szbmgshvz6zgbhh0000gn/T/gocov343768907/src/pkg/github.com/couchbaselabs/cbgb
    go test failed: exit status 1
    failed to parse gocov output: stat /var/folders/nt/_3y11_t12szbmgshvz6zgbhh0000gn/T/gocov343768907/gocov.out: no such file or directory
    
    bug 
    opened by dustin 14
  • If a package has no test files, the lines in that package are not added to the total line count.

    If a package has no test files, the lines in that package are not added to the total line count.

    As described in the issue title.

    Ideally, when I run gocov test ./... under a certain project folder, I want to see the reported total line numbers be the total lines to be covered in the project, no matter whether there is test file existing for a certain package or not.

    However, this is not what gocov does for now, in my experiments. It seems that if there is no test file existing for a certain package, the line numbers in that package are not added to the total line number count. (please let me know if you are not able to replicate this result. :)

    Also, in some circumstances, we don't want to add tests for some packages, for example, some packages are solely for testing purposes like mocks, testdata etc. If we do want to count lines no matter whether there is test file existing, we should also add an option to ignore packages. That would make the tool report the total line numbers correctly as I expect.

    Thanks!

    P.S. gocov is really an awesome and handy tool! It enables and empowers me to do my testing job! :)

    opened by chao1995 10
  • gocov reports test coverage on transitive dependencies

    gocov reports test coverage on transitive dependencies

    Hello,

    I may be mistaking something, but for some reason gocov will annotate and report coverage on transitive dependencies. Am I missing something, or is this a bug ?

    % go get github.com/davecheney/a/... % gocov test github.com/davecheney/a/b | gocov report warning: building out-of-date packages: github.com/axw/gocov github.com/davecheney/a time os fmt flag runtime/pprof testing installing these packages with 'go test -i github.com/davecheney/a/b' will speed future tests.

    ok github.com/davecheney/a/b 0.008s

    github.com/davecheney/a/a.go A 100.00% (1/1) github.com/davecheney/a - 100.00% (1/1)

    github.com/davecheney/a/b/b.go B 66.67% (2/3) github.com/davecheney/a/b - 66.67% (2/3)

    Why is the coverage of package a being reported ?

    opened by davecheney 10
  • False Duplicate Package Name panic

    False Duplicate Package Name panic

    In some cases, the 'gocov test' is generating a json file which contains duplicate package name records. This is happening despite the fact that there is not a duplicate package name. Due to this incorrect behavior the generated json is unusable by the 'gocov report' as the condition on line 88 in report.go is met and panic("package already exists: result merging not implemented yet") is executed.

    opened by xchapter7x 10
  • Add support for test coverage merging; e.g. gocov test ./...

    Add support for test coverage merging; e.g. gocov test ./...

    go test -cover refuses to run tests from multiple package at once. I wrote a function to work around this in TestCoverage.run(), see https://github.com/maruel/pre-commit-go/blob/master/checks/checks.go#L532.

    It runs each package test independently and concurrently, each with their own coverage file, then merges all the coverage files into one. It's ~130 lines of code in practice.

    This feature request is to handle this automatically and transparently inside gocov so that the following command would work:

    gocov test ./... | gocov report
    
    opened by maruel 8
  • XML-output in Cobertura format

    XML-output in Cobertura format

    It would be nice to have an output in Cobertura format for integration with Jenkins/Hudson and other CIs. Example is there: https://raw.github.com/jenkinsci/cobertura-plugin/master/src/test/resources/hudson/plugins/cobertura/coverage-with-data.xml

    opened by AlekSi 8
  • Compile error with Go 1.0.3 on Windows

    Compile error with Go 1.0.3 on Windows

    As the title indicates, this will not compile with Go 1.0.3 on Windows as of commit cacb452347903453c8483c92e2ce1842c1ceef8a.

    The error message is: $GOPATH\src\github.com\axw\gocov\io.go:35: cannot use int(w) (type int) as type syscall.Handle in function argument.

    opened by davecgh 8
  • Getting the expected pwd instead of the generated pwd

    Getting the expected pwd instead of the generated pwd

    In my testing code, I use relative paths to pull in fixtures (non-go files). This however doesn't work because there is a new, temporary path being generated such as:

    /var/folders/qy/zmrxj1t14mnbxsxrz9gtknxc0000gn/T/gocov672324733/src/pkg/github.com/imosquera/uploadthis/conf

    for gocov to work. Whats the best way to get the original file path?

    opened by imosquera 7
  • Cannot pass parameters to `go test`

    Cannot pass parameters to `go test`

    Sorry if I'm just blind to see it(1), but it seems to me that there's no way to pass-through parameters to the "underlying" 'go test'.

    Specifically, my problem is that I need to add -timeout (or -test.timeout) as the package I want to run gocov against is taking about 4 minutes to test w/o the coverage tooling and it timeouts after 600 secs with it.

    However, the need to pass any other parameters is a general problem, which should be addressed (if not solved already[1]).

    opened by cznic 7
  • gocov failed when trying on file that has a formatting directive

    gocov failed when trying on file that has a formatting directive

    Running the command: gocov test /go/src/github.com/xxx/fff/xx-controller/... | gocov-xml > /reports/coverage.xml it fails with: # github.com/xxx/fff/xx-controller/router #11 12.45 xx-controller/router/router.go:168: Info call has possible formatting directive %#v #11 12.48 error: exit status 2 #11 12.48 panic: EOF

    The code is log.Info("NoRoute claims: %#v\n", claims)

    opened by liyaka 0
  • gocov output data format as standard go test does?

    gocov output data format as standard go test does?

    Is it possible to generate output in the same format as standard go test does? Some tools require output to be in standard go test format, not json. I wonder if there is any limitation to do this. In theory it could be directly generated from json... however I'm not sure if there are any known limitations?

    opened by arvenil 8
  • Automated tests for

    Automated tests for "gocov test"

    The instrumentation code has become increasingly complex. As bugs are fixed, new ones are getting introduced; automated tests would be useful to mitigate this.

    opened by axw 0
  • Include line number information

    Include line number information

    This code is copied there and will be copied in gocov-xml, unless gocov test output will include line number information. It will also allow you to make text report by lines.

    opened by AlekSi 2
  • gocov test ./my doesn't work

    gocov test ./my doesn't work

    gocov test ./my doesn't work (at least for a package not in GOPATH), but go test ./my works.

    gocov test ./my
    ok      _/Users/AlekSi/Code/secret-path/colorizer   0.009s
    failed to parse gocov output: stat /var/folders/v2/xzyp4lkn5nl0gpjrs3n66_5w0000gn/T/gocov740203931/gocov.out: no such file or directory
    
    opened by AlekSi 9
Releases(v1.1.0)
Owner
Andrew Wilkins
Andrew Wilkins
Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing

Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing Architecture Usage package main import ( restAPI "github.com/iasthc/hsuan-

Chung-Hsuan Tsai 21 Jul 13, 2022
The portal gates to coverage reports

Covergates - Portal Gates to Coverage Reports Purpose Covergates is to make the easiest way to setup a self-hosted coverage report service. It's an al

Covergates 53 Nov 17, 2022
go-carpet - show test coverage in terminal for Go source files

go-carpet - show test coverage for Go source files To view the test coverage in the terminal, just run go-carpet. It works outside of the GOPATH direc

Sergey Mudrik 231 Nov 3, 2022
Generate a test coverage badge like this one for your go projects.

coverage-badge-go ?? Generate a test coverage badge like this one for your go projects. Usage on: pull_request: branches: -

tj-actions 31 Nov 26, 2022
Test coverage in Go, the whole package

Test coverage in Go, the whole package

Eleni Fragkiadaki 5 Jan 20, 2022
Powerful mock generation tool for Go programming language

Summary Minimock generates mocks out of Go interface declarations. The main features of minimock are: It generates statically typed mocks and helpers.

Juno Inc. 468 Nov 24, 2022
siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.

siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.

Re 290 Nov 26, 2022
A yaml data-driven testing format together with golang testing library

Specimen Yaml-based data-driven testing Specimen is a yaml data format for data-driven testing. This enforces separation between feature being tested

Design it, Run it 1 Nov 24, 2022
Rich testing for the Go language

Instructions Install the package with: go get gopkg.in/check.v1 Import it with: import "gopkg.in/check.v1" and use check as the package name inside

null 666 Nov 5, 2022
Hamcrest matchers for the Go programming language

Note: This has not been maintained and/or updated since 2011. Perhaps consider corbym/gocrest, instead. Introduction Hamcrest is a fluent framework fo

null 28 Sep 27, 2022
GoMock is a mocking framework for the Go programming language.

gomock GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testing package, but can be used in other

Go 8.2k Nov 27, 2022
Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language.

cdp Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language. The bindings are generated

Mathias Fredriksson 647 Nov 11, 2022
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.

Fortio Fortio (Φορτίο) started as, and is, Istio's load testing tool and now graduated to be its own project. Fortio is also used by, among others, Me

Fortio (Φορτίο) 2.8k Nov 28, 2022
A next-generation testing tool. Orion provides a powerful DSL to write and automate your acceptance tests

Orion is born to change the way we implement our acceptance tests. It takes advantage of HCL from Hashicorp t o provide a simple DSL to write the acceptance tests.

Wesovi Labs 45 Aug 31, 2022
Stress testing and benchmarking tool for the NEAR EVM

evm-bully --- stress testing and benchmarking tool for the NEAR EVM

Project Aurora 28 May 30, 2022
HTTP load testing tool and library. It's over 9000!

Vegeta Vegeta is a versatile HTTP load testing tool built out of a need to drill HTTP services with a constant request rate. It can be used both as a

Tomás Senart 20.5k Nov 23, 2022
Ddosify - High-performance load testing tool

Ddosify - High-performance load testing tool Features ✔️ Protocol Agnostic - Currently supporting HTTP, HTTPS, HTTP/2. Other protocols are on the way.

Ddosify 5.1k Nov 21, 2022
Merge Mock - testing tool for the Ethereum Merge

MergeMock Experimental debug tooling, mocking the execution engine and consensus node for testing. work in progress Quick Start To get started, build

Diederik Loerakker 40 Oct 21, 2022
Ditto is a CLI testing tool that helps you verify if multiple HTTP endpoints have the same outputs.

Ditto is a CLI testing tool that helps you verify if multiple HTTP endpoints have the same outputs.

Cristopher 1 Nov 24, 2021