Testing Standards¶
Test Types¶
Unit Tests¶
- File naming:
*_test.goalongside the implementation - Run with:
make testorgo test ./... - Framework: testify/assert + testify/mock (most projects) or Ginkgo/Gomega (hery, LibraryFramework)
Integration Tests¶
- File naming:
*_integration_test.go - Require build tag:
go test -tags=integration ./... - Test real external interactions (filesystem, Git, SQLite)
Table-Driven Tests¶
Table-driven tests are the standard pattern:
func TestParseVersion(t *testing.T) {
tests := []struct {
name string
input string
expected string
wantErr bool
}{
{
name: "valid semver",
input: "v1.2.3",
expected: "1.2.3",
},
{
name: "invalid format",
input: "not-a-version",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := ParseVersion(tt.input)
if tt.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
}
}
Mock Generation¶
Mocks are generated by mockery v2, configured in .mockery.yaml at the project root.
Mocks are generated in-package alongside their interfaces. File naming: mock_I*.go.
Coverage¶
Coverage configuration is in .covignore:
These patterns are excluded from coverage calculations.
BDD Testing (hery, LibraryFramework)¶
hery and LibraryFramework use Ginkgo v2 + Gomega for BDD-style tests:
var _ = Describe("Entity", func() {
Context("when validating", func() {
It("should accept valid schema", func() {
err := entity.Validate(validYAML)
Expect(err).ToNot(HaveOccurred())
})
})
})
Run with: go test ./... (Ginkgo is compatible with go test).