Giter VIP home page Giter VIP logo

golang-live-coverage-report's Introduction

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:

Coverage Report 1

  1. open http://localhost:8080/run_once, to run the target function once

  2. open http://localhost:8080/report again, you will see the report with some code line already covered

Coverage Report 2

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

    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

golang-live-coverage-report's People

Contributors

giant-panda666 avatar ikarishinjieva avatar

Stargazers

 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.