Cursor rule
.cursor/rules/testing-standards.mdcComprehensive testing standards and patterns for Compozy Go development - enforces mandatory t.Run patterns, testify usage, and mock standards
Cursor rules
Quality
77/100
Scores the file, not the repository.Length
886 words
10 headings · 4 code blocksRepository
9
— · pushed 389 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Testing Standards for Compozy Go Development78<critical>9**MANDATORY REQUIREMENTS:**10- **ALWAYS** check dependent files APIs before write tests to avoid write wrong code11- **ALWAYS** verify against PRD and tech specs - NEVER make assumptions12- **NEVER** use workarounds, especially in tests - implement proper solutions13- **MUST** follow all established project standards:14 - Architecture patterns: `.cursor/rules/architecture.mdc`15 - Go coding standards: `.cursor/rules/go-coding-standards.mdc`16 - Testing requirements: `.cursor/rules/testing-standards.mdc`17 - API standards: `.cursor/rules/api-standards.mdc`18 - Security & quality: `.cursor/rules/quality-security.mdc`19- **MUST** run `make lint` and `make test` before completing ANY subtask20- **MUST** follow `.cursor/rules/task-review.mdc` workflow for parent tasks21**Enforcement:** Violating these standards results in immediate task rejection.22</critical>2324## Core Testing Requirements2526<requirements type="mandatory">27**MANDATORY testing patterns for all Go code:**28- Use `t.Run("Should describe expected behavior")` pattern for all tests29- Use `stretchr/testify` for assertions and mocks30- Follow table-driven test patterns when appropriate31- Achieve >85% coverage for business logic packages32</requirements>3334## Testing Requirements3536<requirements type="mandatory">37- **ALL tests MUST use `t.Run("Should...")` pattern** - no direct test implementation without t.Run wrapper38- Test function names: `func TestModuleName_MethodName(t *testing.T)`39- Each test case within t.Run with descriptive "Should..." names40- MUST use `stretchr/testify` for assertions and mocks41- **STANDARDIZE ON TESTIFY MOCK:** Replace existing custom mocks with `testify/mock` implementations42</requirements>4344## Anti-Patterns to Avoid4546<anti_patterns type="prohibited_patterns">47**NEVER USE TESTIFY SUITE PATTERNS:**48- ❌ **PROHIBITED:** `suite.Suite` embedding or any suite-based test structures49- ❌ **PROHIBITED:** Suite methods like `s.Equal()`, `s.NoError()`, `s.True()`, `s.False()`, `s.T()`50- ❌ **PROHIBITED:** `testsuite.WorkflowTestSuite` or similar suite embeddings51- ❌ **PROHIBITED:** Suite lifecycle methods like `SetupTest()`, `TearDownTest()`, `AfterTest()`5253**USE DIRECT ASSERTIONS INSTEAD:**54- ✅ **REQUIRED:** `assert.Equal(t, expected, actual)`55- ✅ **REQUIRED:** `require.NoError(t, err)`56- ✅ **REQUIRED:** `assert.True(t, condition)`57- ✅ **REQUIRED:** Individual test functions with `*testing.T` parameter58</anti_patterns>5960<anti_patterns type="bad_examples">61```go62// ❌ NEVER DO THIS - Suite pattern is prohibited63type MyTestSuite struct {64 suite.Suite65 // other fields66}6768func (s *MyTestSuite) TestSomething() {69 s.Equal("expected", "actual") // ❌ WRONG70 s.NoError(err) // ❌ WRONG71 s.T().Run("test", func(t *testing.T) { ... }) // ❌ WRONG72}7374// ✅ DO THIS INSTEAD - Direct test functions75func TestSomething_Method(t *testing.T) {76 t.Run("Should behave correctly", func(t *testing.T) {77 assert.Equal(t, "expected", "actual") // ✅ CORRECT78 require.NoError(t, err) // ✅ CORRECT79 })80}81```82</anti_patterns>8384## Table-Driven Tests8586<guidelines type="table_tests">87- AVOID table-driven tests for 2-3 cases88- ONLY use when 5+ similar variations exist89- Each table test case must still use "Should..." naming90</guidelines>9192## Test Organization9394<organization_rules>95- Place `*_test.go` files alongside implementation files96- Each test MUST be independent and repeatable97- Mock external dependencies **only when necessary** using `testify/mock`98- Use project test helpers: `utils.SetupTest()`, `utils.SetupFixture()`99- Test both success and error paths100- Ensure test coverage for all exported functions101</organization_rules>102103## Mock Standards104105<when_to_mock>106**WHEN TO USE MOCKS:**107- External services (HTTP clients, databases, file systems)108- Dependencies that are slow, unreliable, or have side effects109- Complex interfaces that would make tests brittle or slow110- **NOT REQUIRED** for simple functions, pure logic, or internal utilities111</when_to_mock>112113<pattern type="mock_implementation">114```go115// Define mock interface116type MockService struct {117 mock.Mock118}119120func (m *MockService) DoSomething(ctx context.Context, param string) error {121 args := m.Called(ctx, param)122 return args.Error(0)123}124125// Usage in tests126func TestComponent_Method(t *testing.T) {127 t.Run("Should use mocked service", func(t *testing.T) {128 mockService := new(MockService)129 mockService.On("DoSomething", mock.Anything, "test").Return(nil)130131 component := NewComponent(mockService)132 err := component.Method("test")133134 assert.NoError(t, err)135 mockService.AssertExpectations(t)136 })137}138```139</pattern>140141<refactoring_priorities>142- Replace custom mocks with testify/mock implementations143- Migrate interface-based mocks to use `mock.Mock` embedding144- Standardize mock setup and assertion patterns across the codebase145</refactoring_priorities>146147<example type="test_structure">148```go149func TestService_Method(t *testing.T) {150 t.Run("Should succeed with valid input", func(t *testing.T) {151 // arrange, act, assert152 })153154 t.Run("Should handle error cases", func(t *testing.T) {155 // test implementation156 })157}158```159</example>160161## Test Patterns162163<patterns type="testing_best_practices">164- **Arrange-Act-Assert:** Structure all tests with clear setup, execution, and verification phases165- **Independent Tests:** Each test should be able to run in isolation166- **Descriptive Names:** Use "Should..." pattern to describe expected behavior167- **Mock When Necessary:** Use testify/mock only for external dependencies or complex interfaces168- **Context Propagation:** Pass context to functions that require it, even in tests169- **Mock Assertions:** When using mocks, always call `mockService.AssertExpectations(t)` to verify all expected calls were made170- **Mock Cleanup:** Use `mock.AnythingOfType()` and `mock.Anything` for flexible parameter matching171</patterns>172173## Test Coverage Requirements174175<coverage_requirements type="unified">176**Unified Coverage Standard:**177- **Business Logic Packages**: All code in `engine/{agent,task,tool,workflow}/` must achieve ≥80% test coverage178- **Exported Functions**: All exported functions across the codebase must have meaningful tests (not just presence tests)179- **Coverage Focus**: Prioritize testing business logic paths over trivial getters/setters180- **Quality Gate**: Use coverage reports to identify gaps in business logic, not just check for test existence181</coverage_requirements>182183## Architectural Testing184185<architectural_testing type="mandatory">186**MANDATORY: Architecture Constraint Validation**187- **Dependency Direction**: Test that dependencies flow inward toward domain188- **Layer Violations**: Prevent direct dependencies between Infrastructure and Domain layers189- **Circular Dependencies**: Automated detection of package cycles190- **Interface Compliance**: Verify adapters properly implement port interfaces191192**Implementation Pattern:**193```go194func TestArchitecturalConstraints(t *testing.T) {195 t.Run("Should enforce dependency direction", func(t *testing.T) {196 // Test that engine/infra doesn't import engine/core directly197 // Test that engine/core doesn't import any other engine packages198 })199200 t.Run("Should prevent circular dependencies", func(t *testing.T) {201 // Use go list or similar to detect cycles202 })203}204```205</architectural_testing>206
Also in compozy/gograph
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| compozy/gograph.cursor/rules/architecture.mdc · 9 | Cursor rules | styletesting-strategydependenciesdo-not | 57/100 | 3 days ago | |
| compozy/gograph.cursor/rules/api-standards.mdc · 9 | Cursor rules | lint-formatapidocs | 54/100 | 3 days ago | |
| compozy/gograph.cursor/rules/backwards-compatibility.mdc · 9 | Cursor rules | do-notagent-behaviour | 32/100 | 3 days ago | |
| compozy/gograph.cursor/rules/compozy-agent-config.mdc · 9 | Cursor rules | agent-behaviour | 45/100 | 3 days ago | |
| compozy/gograph.cursor/rules/compozy-examples.mdc · 9 | Cursor rules | stylearchtypesagent-behaviour | 58/100 | 3 days ago | |
| compozy/gograph.cursor/rules/compozy-project-config.mdc · 9 | Cursor rules | setupstyle | 54/100 | 3 days ago | |
| compozy/gograph.cursor/rules/cursor_rules.mdc · 9 | Cursor rules | no sections | 40/100 | 3 days ago | |
| compozy/gograph.cursor/rules/compozy-shared-patterns.mdc · 9 | Cursor rules | styleagent-behaviour | 54/100 | 3 days ago | |
| compozy/gograph.cursor/rules/compozy-task-patterns.mdc · 9 | Cursor rules | stylearchagent-behaviour | 70/100 | 3 days ago | |
| compozy/gograph.cursor/rules/core-libraries.mdc · 9 | Cursor rules | testing-strategydependenciesdo-not | 60/100 | 3 days ago | |
| compozy/gograph.cursor/rules/critical-validation.mdc · 9 | Cursor rules | no sections | 24/100 | 3 days ago | |
| compozy/gograph.cursor/rules/go-coding-standards.mdc · 9 | Cursor rules | stylearchdependencies | 62/100 | 3 days ago | |
| compozy/gograph.cursor/rules/go-patterns.mdc · 9 | Cursor rules | style | 66/100 | 3 days ago | |
| compozy/gograph.cursor/rules/no_linebreaks.mdc · 9 | Cursor rules | no sections | 31/100 | 3 days ago | |
| compozy/gograph.cursor/rules/prd-create.mdc · 9 | Cursor rules | stylearchagent-behaviour | 48/100 | 3 days ago | |
| compozy/gograph.cursor/rules/prd-tech-spec.mdc · 9 | Cursor rules | setuptestarchagent-behaviour | 56/100 | 3 days ago | |
| compozy/gograph.cursor/rules/quality-security.mdc · 9 | Cursor rules | securityperformancedo-not | 46/100 | 3 days ago | |
| compozy/gograph.cursor/rules/review-checklist.mdc · 9 | Cursor rules | testing-strategygit | 52/100 | 3 days ago | |
| compozy/gograph.cursor/rules/section_comments.mdc · 9 | Cursor rules | no sections | 31/100 | 3 days ago | |
| compozy/gograph.cursor/rules/task-developing.mdc · 9 | Cursor rules | agent-behaviour | 47/100 | 3 days ago |
Diff against .cursor/rules/architecture.mdc Diff against .cursor/rules/api-standards.mdc Diff against .cursor/rules/backwards-compatibility.mdc Diff against .cursor/rules/compozy-agent-config.mdc Diff against .cursor/rules/compozy-examples.mdc Diff against .cursor/rules/compozy-project-config.mdc Diff against .cursor/rules/cursor_rules.mdc Diff against .cursor/rules/compozy-shared-patterns.mdc Diff against .cursor/rules/compozy-task-patterns.mdc Diff against .cursor/rules/core-libraries.mdc Diff against .cursor/rules/critical-validation.mdc Diff against .cursor/rules/go-coding-standards.mdc Diff against .cursor/rules/go-patterns.mdc Diff against .cursor/rules/no_linebreaks.mdc Diff against .cursor/rules/prd-create.mdc Diff against .cursor/rules/prd-tech-spec.mdc Diff against .cursor/rules/quality-security.mdc Diff against .cursor/rules/review-checklist.mdc Diff against .cursor/rules/section_comments.mdc Diff against .cursor/rules/task-developing.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
