verygoodsoftwarenotvirus / blanket

Licence: MIT license
MOVED TO GITLAB

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to blanket

gobco
Measure branch coverage of golang tests
Stars: ✭ 36 (+125%)
Mutual labels:  coverage, coverage-testing
react-testing-mocha-chai-enzyme
A solid test setup for React components with Mocha, Chai, Sinon, Enzyme in a Webpack/Babel application.
Stars: ✭ 48 (+200%)
Mutual labels:  coverage, coverage-testing
Python Mocket
a socket mock framework - for all kinds of socket animals, web-clients included
Stars: ✭ 209 (+1206.25%)
Mutual labels:  coverage
solcover
Code coverage for solidity
Stars: ✭ 64 (+300%)
Mutual labels:  coverage
Alsatian
TypeScript testing framework with test cases
Stars: ✭ 244 (+1425%)
Mutual labels:  coverage
Ehtrace
ATrace is a tool for tracing execution of binaries on Windows.
Stars: ✭ 218 (+1262.5%)
Mutual labels:  coverage
Express Mongoose Es6 Rest Api
💥 A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication
Stars: ✭ 2,811 (+17468.75%)
Mutual labels:  coverage
Bisect ppx
Code coverage for OCaml and ReScript
Stars: ✭ 204 (+1175%)
Mutual labels:  coverage
code-coverage-action
GitHub Action that generates code coverage reports
Stars: ✭ 28 (+75%)
Mutual labels:  coverage
Jacoco
🔬 Java Code Coverage Library
Stars: ✭ 3,041 (+18906.25%)
Mutual labels:  coverage
CutterDRcov
DynamoRIO coverage visualization for cutter
Stars: ✭ 51 (+218.75%)
Mutual labels:  coverage
Example Python
Python coverage example
Stars: ✭ 238 (+1387.5%)
Mutual labels:  coverage
Codecov Bash
Global coverage report uploader for Codecov
Stars: ✭ 220 (+1275%)
Mutual labels:  coverage
grcov
📈 GitHub Action for code coverage reporting with grcov
Stars: ✭ 96 (+500%)
Mutual labels:  coverage
Browser Extension
Codecov Browser Extension
Stars: ✭ 212 (+1225%)
Mutual labels:  coverage
MsCoreOne
MsCoreOne is a simple Ecommerce with using many technologies such as .NET 5, Entity Framework Core 5, React 16.13 with modern Clean Architecture, Domain-Driven Design, CQRS, SOLID, Identity Server 4, Blazor. It will focus on resolving the problems always see in the process to develop projects.
Stars: ✭ 77 (+381.25%)
Mutual labels:  coverage
Cmake Scripts
A selection of useful scripts for use in CMake projects, include code coverage, sanitizers, and dependency graph generation.
Stars: ✭ 202 (+1162.5%)
Mutual labels:  coverage
Axocover
Nice and free .Net code coverage support for Visual Studio with OpenCover.
Stars: ✭ 237 (+1381.25%)
Mutual labels:  coverage
Interrogate
Explain yourself! Interrogate a codebase for docstring coverage.
Stars: ✭ 245 (+1431.25%)
Mutual labels:  coverage
ruby-codacy-coverage
DEPRECATED Post coverage results to Codacy
Stars: ✭ 12 (-25%)
Mutual labels:  coverage

blanket

blanket is a tool that helps you catch functions which don't have direct unit tests in your Go packages.

Installation

go get -u gitlab.com/verygoodsoftwarenotvirus/blanket

Docker Image

If you don't want to install blanket locally, you can use the pre-built Docker image like so:

docker run -it --rm -v "$(pwd):/src/<pkg>" verygoodsoftwarenotvirus/blanket:latest analyze --package <pkg>

Where <pkg> could be something like gitlab.com/verygoodsoftwarenotvirus/blanket/analysis. :)

Purpose

Say, for example, you had the following Go file:

package simple

func A() string {
    return "A"
}

func B() string {
    return "B"
}

func C() string {
    return "C"
}

func wrapper() {
   A()
   B()
   C()
}

and you had the following test for that file:

package simple

import (
    "testing"
)

func TestA(t *testing.T) {
    A()
}

func TestC(t *testing.T) {
    C()
}

func TestWrapper(t *testing.T) {
    wrapper()
}

Running go test -cover on that package yields the following output:

PASS
coverage: 100.0% of statements
ok      gitlab.com/verygoodsoftwarenotvirus/blanket/example_packages/simple    0.006s

However, note that B doesn't have a direct test the way that A and C do. B is only "tested" in TestWrapper. Because all the functions are called, -cover yields a 100% coverage value. If you ever decide that wrapper doesn't need to call B anymore, and don't delete the function entirely, you'll have a drop in coverage. Running blanket analyze on that same package yields the following output:

Functions without direct unit tests:
in /Users/vgsnv/golang/src/gitlab.com/verygoodsoftwarenotvirus/blanket/example_packages/simple/main.go:
    B on line 7

Grade: 75% (3/4 functions)

Additionally, you can use the cover command to visualize those functions by passing in a cover profile. So if you run something like go test -coverprofile=coverage.out && blanket cover --html=coverage.out, a browser window will open that shows untested functions in red, functions without direct tests in yellow, and functions that are directly tested in green, like so:

example output

Use Cases

What blanket seeks to do is catch these sorts of things so that package maintainers can decide what the appropriate course of action is. If you're fine with it, that's cool. If you're not cool with it, then you know what needs to have tests added.

You can also use blanket in your CI pipeline to decline PRs that would add functions that don't have direct unit tests. As a matter of fact, blanket does just that for itself! Here is an example of such a scenario working on this very repository!

I think blanket could also be helpful for new developers looking to contribute towards a project. They can run blanket on the package and see if there are some functions they could easily add unit tests for, just to get their feet wet in a project.

Issues

If you've tried blanket on something and found that it didn't accurately handle some code, or panicked, please feel free to file an issue. Having an example of the code you experienced issues with is pretty crucial, so keep that in mind.

Known Issues

blanket doesn't adequately handle deeply nested method calls. So if you had something like this:

package main

import (
    "testing"
)

/*
// in another file:
type Example struct{}
func methodCall() {
    return
}
*/

func TestMethod(t *testing.T) {
    x := struct{
        First: struct{
            Second: struct{
                Third: Example{},
            },
        },
    }
    x.First.Second.Third.methodCall()
}

That should technically satisfy blanket's strict testing requirement, but it doesn't. Blanket can handle single-level selector expressions with great ease, but it doesn't recursively dive into those selectors for a number of reasons.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].