Contract tests


"Integration Tests are a Scam" Joe Rainsberger






Topalov Alex @sharkzp


Problem:


  1. The larger application the larger amount of time you need to test it.
  2. The more integration(end-to-end) test you wrote the more duplication you involve.
  3. When integration test fails who knows what part of code is broken. 


Object under test



Object under test diagram, by Sandi Metz


What does it mean?




 

Goals of unit tests

  1. Thorough: must prove completely that the single object under test is behaving correctly
  2. Stable: must not break with an implementation detail change
  3. Fast: minimize development feedback loop
  4. Few: Each test should prove one unitary behaviour of public interface

If Unit test intend to test only one object, and integration tests does not provide great feedback what we should do?


Testing Pyramid





Solution: Contact test



Goal of contract test:

1. Thorough: you must prove that contract between two objects behaving correctly
2. Stable: should not say how objects should behave, should expect correct answer instead.
3. Fast: minimize development feedback loop
4. FewEach test should prove one unitary behaviour of public interface



Example




Credits:

  1. J. B. (Joe) Rainsberger - Integration Tests Are a Scam
  2. Ruby Conf 12 - Boundaries by Gary Bernhardt
  3. destroyallsoftware.com
  4. Clean code - Robert C. Martin
  5. Bogus

Contract tests

By Alex Topalov

Contract tests

  • 2,589