Skip to Content

Test Quality

Let’s look at how to suggest improvements for test quality in code reviews. We’ll show you a simple example and explain why the feedback matters.

The Scenario

A developer has written tests for user functionality. The tests work but could be more maintainable and readable.

user.test.ts
// Before describe('User', () => { it('should work', () => { const user = { name: 'John', age: 30, email: 'john@example.com', } const result = processUser(user) expect(result).toBeDefined() }) })

PR Comment

Choose the comment that you think is the most constructive and helpful.

// After describe('User Processing', () => { it('should process valid user data correctly', () => { // Arrange const user = createTestUser({ name: 'John', age: 30, email: 'john@example.com', }) // Act const result = processUser(user) // Assert expect(result).toBeDefined() expect(result.name).toBe('John') expect(result.age).toBe(30) expect(result.email).toBe('john@example.com') }) })

Click here to learn more

Improvements

1. Test Structure

  • Clear Arrange-Act-Assert pattern
  • Descriptive test names
  • Better test organization

2. Test Data

  • Reusable test data builders
  • Consistent test data
  • Easier test maintenance

3. Test Quality

  • More specific assertions
  • Better test coverage
  • Clearer test intent

Tips

1. Start Positive

  • Acknowledge the working code
  • Show you understand the current approach
  • Example: “Great work on the user tests!“

2. Explain the Benefits

  • Why do better tests matter?
  • How do they help?
  • Example: “This makes the tests more maintainable”

3. Be Specific

  • Suggest concrete improvements
  • Explain why they matter
  • Example: “Using the Arrange-Act-Assert pattern helps with readability”

4. Keep It Friendly

  • Focus on improvement, not criticism
  • Use encouraging language
  • Example: “Thanks for considering test quality!”

Common Pitfalls to Avoid

1. Being Too Critical

  • ❌ “These tests are terrible.”
  • ✅ “Good work! Here’s how we can make them even better.”

2. Not Explaining Why

  • ❌ “Write better tests.”
  • ✅ “Using test data builders helps with maintainability.”

3. Ignoring the Positive

  • ❌ “This needs better tests.”
  • ✅ “Great work! Here’s how we can make them even more maintainable.”

Remember: The goal is to help your teammate write better code while maintaining a positive and collaborative environment!

Last updated on
Logging