Write test assertions that are resilient to implementation changes by focusing on behavior rather than implementation details. Avoid exact matches when partial or behavioral assertions would suffice.
Write test assertions that are resilient to implementation changes by focusing on behavior rather than implementation details. Avoid exact matches when partial or behavioral assertions would suffice.
Key practices:
Example - Instead of brittle exact matching:
// ❌ Brittle - breaks if new options are added
expect(options).toEqual({
preview: false,
viewColumn: vscode.ViewColumn.Active
})
// ✅ Resilient - verifies required properties
expect(options).toEqual(expect.objectContaining({
preview: false,
viewColumn: vscode.ViewColumn.Active
}))
For token counting or similar approximate values:
// ❌ Brittle - breaks if tokenizer changes slightly
expect(tokenCount).toBe(14)
// ✅ Resilient - verifies reasonable range
expect(tokenCount).toBeGreaterThan(12)
expect(tokenCount).toBeLessThan(16)
This approach:
Enter the URL of a public GitHub repository