Skip to content

Commit 4eefa4b

Browse files
Copilotjwijgerd
andcommitted
Remove record tests and add testing guidelines to copilot instructions
Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
1 parent a9c4d17 commit 4eefa4b

4 files changed

Lines changed: 27 additions & 281 deletions

File tree

.github/copilot-instructions.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,21 +309,30 @@ public AccountCreatedEventV2 cast(AccountCreatedEvent event) {
309309

310310
## Testing Guidelines
311311

312-
### 1. Unit Tests
312+
### 1. What NOT to Test Directly
313+
**Do not create dedicated unit tests for:**
314+
- **Java Annotations** - Test their effects through the classes that use them
315+
- **Java Records** - Test their usage in context, not record functionality itself
316+
- **Java Interfaces** - Test implementations, not interface definitions
317+
- **Exception Classes** - Test exception handling in the code that throws them, not the exceptions themselves
318+
319+
These language constructs should only be tested indirectly as part of testing other components that use them.
320+
321+
### 2. Unit Tests
313322
- Test aggregate logic in isolation
314323
- Mock external dependencies
315324
- Test command validation
316325
- Verify correct events are emitted
317326
- Test state transitions
318327

319-
### 2. Integration Tests
328+
### 3. Integration Tests
320329
- Use embedded Kafka for testing
321330
- Test complete command/event flows
322331
- Verify query model updates
323332
- Test error handling scenarios
324333
- Use Spring Boot test framework
325334

326-
### 3. Test Structure
335+
### 4. Test Structure
327336
```java
328337
@SpringBootTest
329338
@DirtiesContext

TEST_COVERAGE_IMPROVEMENTS.md

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Missing unit tests for utility classes.
3535

3636
## Test Cases Added
3737

38-
### Shared Module Tests (6 new test files)
38+
### Shared Module Tests (6 test files)
3939

4040
#### 1. GDPRKeyUtilsTests.java
4141
Tests for cryptographic key generation and UUID validation:
@@ -98,43 +98,30 @@ Tests for BigDecimal JSON serialization:
9898
- `testSerializeInObjectContext()` - Integration with Jackson ObjectMapper
9999
- Coverage: 100% of serialize method + format visitor
100100

101-
### API Module Tests (2 new test files)
101+
## Note on Testing Philosophy
102102

103-
#### 7. CommandTypeTests.java
104-
Tests for command type metadata:
105-
- `testCommandTypeCreation()` - Record construction
106-
- `testGetSchemaPrefix()` - Schema prefix validation ("commands.")
107-
- `testRelaxExternalValidation()` - Validation behavior (always false)
108-
- `testCommandTypeWithPIIData()` - PII flag handling
109-
- `testCommandTypeEquality()` - Record equality semantics
110-
- Coverage: 100% of public methods
103+
Per framework guidelines, we do not create dedicated unit tests for:
104+
- **Java Records** (like CommandType, DomainEventType) - Test their usage in context
105+
- **Java Annotations** - Test their effects through annotated classes
106+
- **Java Interfaces** - Test implementations, not interface definitions
107+
- **Exception Classes** - Test exception handling, not exceptions themselves
111108

112-
#### 8. DomainEventTypeTests.java
113-
Tests for domain event type metadata:
114-
- `testDomainEventTypeCreation()` - Record construction with all flags
115-
- `testGetSchemaPrefix()` - Schema prefix validation ("domainevents.")
116-
- `testRelaxExternalValidation()` - External validation relaxation (true)
117-
- `testDomainEventTypeWithErrorFlag()` - Error event handling
118-
- `testDomainEventTypeWithExternalFlag()` - External event handling
119-
- `testDomainEventTypeEquality()` - Record equality
120-
- Coverage: 100% of public methods
109+
These constructs are tested indirectly through integration tests and usage in other components.
121110

122111
## Test Coverage Improvements Summary
123112

124113
### Metrics
125-
- **Total New Test Files**: 8
126-
- **Total New Test Methods**: ~50
127-
- **Lines of Test Code Added**: ~700
114+
- **Total New Test Files**: 6
115+
- **Total New Test Methods**: ~40
116+
- **Lines of Test Code Added**: ~550
128117

129118
### Coverage by Module (After)
130-
- **API Module**: 0% → ~10% (2 core type system classes now tested)
131-
- **Shared Module**: 6% → ~18% (6 critical utility/GDPR classes now tested)
119+
- **Shared Module**: 6% → ~16% (6 critical utility/GDPR classes now tested)
132120

133121
### Key Improvements
134-
1. **API Module**: Established foundational test coverage for core type system classes
135-
2. **GDPR Module**: Comprehensive coverage of key utilities (GDPRKeyUtils, NoopGDPRContext, InMemoryGDPRContextRepository, GDPRAnnotationUtils)
136-
3. **Kafka Utilities**: Complete coverage of Kafka utility functions
137-
4. **Serialization**: BigDecimal serialization fully tested
122+
1. **GDPR Module**: Comprehensive coverage of key utilities (GDPRKeyUtils, NoopGDPRContext, InMemoryGDPRContextRepository, GDPRAnnotationUtils)
123+
2. **Kafka Utilities**: Complete coverage of Kafka utility functions
124+
3. **Serialization**: BigDecimal serialization fully tested
138125

139126
## Test Quality
140127

main/api/src/test/java/org/elasticsoftware/akces/aggregate/CommandTypeTests.java

Lines changed: 0 additions & 114 deletions
This file was deleted.

main/api/src/test/java/org/elasticsoftware/akces/aggregate/DomainEventTypeTests.java

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)