Skip to content

Instantly share code, notes, and snippets.

@hansrajdas
Last active April 14, 2024 16:04
Show Gist options
  • Save hansrajdas/852ffa70d36311558b5bc2cae86ccbf1 to your computer and use it in GitHub Desktop.
Save hansrajdas/852ffa70d36311558b5bc2cae86ccbf1 to your computer and use it in GitHub Desktop.
Golang debugging

Run golang test with dlv

Below command will run the tests defined in current package

dlv test

# If Go version is outdated
dlv test --check-go-version=false

# Ignore protobuf conflict
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn dlv test --check-go-version=false

# Run specific test
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn dlv test -- -test.run TestSomething/Create

Get code coverage and lines covered/missing

# 1. Generate coverage file
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn go test -cover -coverprofile=/tmp/coverage.out -run ./...

# 2. Convert to readable/html format
go tool cover -html=/tmp/coverage.out -o /tmp/coverage.html

# 3. Open /tmp/coverage.html in browser

Links and references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment