User Tools

Site Tools


test_doubles

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
test_doubles [2025/09/09 18:57] plidatest_doubles [2025/09/09 19:02] (current) plida
Line 51: Line 51:
 When a test knows too much about the inner workings of the class (what methods are called and in what order). The slightest refactoring can break such a test. When a test knows too much about the inner workings of the class (what methods are called and in what order). The slightest refactoring can break such a test.
  
 +==== Best practices ====
  
 +  - Choose a correct test double.
 +  - Give preference to fake where it's appropriate, as it's easier to maintain than mocks.
 +  - Limit the amount of mocks. If a test requires more than 2-3 mocks, something went wrong.
 +  - A test must fixate the business-result, not the inner details.
 +  - Take out the creation of doubles into factories or test data builders. This improves readability.
 +  - Use mocks/fakes for unit-tests, for integration -- real services.
 +  - Use clear names (SpyEmail, FakeRepo).
  
  
test_doubles.1757444237.txt.gz · Last modified: by plida