Hasty Briefsbeta

Show HN: Identifiy test coverage gaps in your Go projects

11 days ago
  • #Testing
  • #Static Analysis
  • #Go
  • A Go static analysis tool named testvet identifies missing test coverage and misplaced test functions in Go projects.
  • Features include Missing Test Detection, Low Coverage Detection, AST-Based Call Analysis, Misplaced Test Detection, Method Support, Flexible Filtering, and Clean Output.
  • Installation can be done via `go install github.com/LeanerCloud/testvet@latest` or building from source.
  • Usage examples include analyzing current or specific directories, excluding private functions, showing verbose output, and setting coverage thresholds.
  • Output includes functions without test coverage, misplaced tests, and low coverage functions with line numbers and percentages.
  • The tool uses Go's `go/ast` package for parsing, function extraction, test extraction, call analysis, coverage filtering, and matching.
  • Exclusions include `main()` and `init()` functions, `vendor/` and `testdata/` directories, and hidden directories.
  • Flags available for directory analysis, excluding private functions, verbose output, coverage threshold, and using coverage data.
  • Comparison with `go test -cover` shows testvet answers if a function is called from any test, while `go test -cover` measures statement coverage percentage.
  • Combining both tools helps find untested functions, measure thoroughness of existing tests, and identify poorly-tested functions.
  • Contributions are welcome under the MIT License, and the tool is developed by LeanerCloud for cloud cost optimization.