https://github.com/ikarishinjieva/golang-live-coverage-report
golang coverage report in live, as an HTTP handler
https://github.com/ikarishinjieva/golang-live-coverage-report
coverage-report coverage-testing golang
Last synced: 5 days ago
JSON representation
golang coverage report in live, as an HTTP handler
- Host: GitHub
- URL: https://github.com/ikarishinjieva/golang-live-coverage-report
- Owner: ikarishinjieva
- License: mit
- Created: 2019-02-10T11:30:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-19T07:47:56.000Z (about 5 years ago)
- Last Synced: 2025-04-10T01:44:35.025Z (3 months ago)
- Topics: coverage-report, coverage-testing, golang
- Language: Go
- Size: 203 KB
- Stars: 4
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# golang-live-coverage-report
Golang coverage report was official supported by `go test -coverprofile`.
This tool makes it available for **integration test** of long-run project, e.g. a web server.
Most code is copied from golang `cmd/cover` and `testing` pakcage.
**Support golang 1.11+**.
# Demo
1. Run the following script```
# prepare temp directory
mkdir /tmp/gopath
cd /tmp/gopath
# go get
GOPATH=/tmp/gopath go get github.com/ikarishinjieva/golang-live-coverage-report/cmd/golang-live-coverage-report
# build demo
cd /tmp/gopath/src/github.com/ikarishinjieva/golang-live-coverage-report/examples/
GOPATH=/tmp/gopath PATH=$GOPATH/bin:$PATH make
# start demo server
./demo
```2. open a browser with http://localhost:8080/report, you will see a report like:

3. open http://localhost:8080/run_once, to run the target function once
4. open http://localhost:8080/report again, you will see the report with some code line already covered

# How to use
The brief steps of this tool are:
1. Before building your project, run `golang-live-coverage-report -pre-build ... {files-included-in-the-report}`:
1.1 This tool will copy the files to temporary directory (`-raw-code-build-dir`)
1.2 This tool will inject some codes into the files
1.3 This tool will generate a bootstrap golang file (`-bootstrap-outfile`), the package name could be specified by `-bootstrap-package-name`
2. Build your project:2.1 Add a HTTP handler using `GenerateHtmlReport()` in your code, example is [here](https://github.com/ikarishinjieva/golang-live-coverage-report/blob/master/examples/demo.go)
2.2 Compile your project with the bootstrap file
2.3 Remember to exclude the temporary directory in step 1.1 when compiling
2.4 Copy the temporary directory to `{your building directory}/{path specified by '-raw-code-deploy-dir'}`
3. After building your project, run `golang-live-coverage-report -post-build ... {files-included-in-the-report}` to rollback the changes:3.1 Remove the bootstrap file in step 1.3
3.2 Rollback the injected files, with files in temporary directory in step 1.1
3.3 Remove the temporary directory in step 1.1
4. The entire process example is [here](https://github.com/ikarishinjieva/golang-live-coverage-report/blob/master/examples/Makefile)