Back to all reviewers

Write deterministic test assertions

docker/compose
Based on 4 comments
Go

Tests should be deterministic and explicit in their assertions to ensure reliability and maintainability. Follow these guidelines: 1. Use explicit assertions instead of ambiguous string matching

Testing Go

Reviewer Prompt

Tests should be deterministic and explicit in their assertions to ensure reliability and maintainability. Follow these guidelines:

  1. Use explicit assertions instead of ambiguous string matching
  2. Leverage testing utilities provided by the testing framework
  3. Test both expected and edge cases
  4. Use controlled test data instead of production-like values

Example - Instead of:

assert.Assert(t, strings.Contains(output, "Skipped"))
w.Write([]byte("hello"))

Better approach:

// Use explicit assertions
assert.DeepEqual(t, lines, []string{"hello", "world!"})

// Use testing utilities
dirName := t.TempDir()

// Use controlled test data
internal.Version = "v9.9.9-test"

// Test both success and edge cases
w.Write([]byte("hello\n"))
w.Write([]byte("world"))  // Test without EOL

This approach makes tests more maintainable, easier to debug, and less prone to flaky failures.

4
Comments Analyzed
Go
Primary Language
Testing
Category

Source Discussions