Post on 21-Apr-2017
Lars Thorup
● Software developer/architect● JavaScript, C#● Test Driven Development
● Coach● Agile engineering practices
and tools
● Founder● BestBrains● ZeaLake
● @larsthorup
Agenda● What's so bad about end-to-end tests?
● Why are unit tests not sufficient?
● Getting the best of both worlds
● Demo!
End-to-end tests give poor feedback● End-to-end tests: "something went wrong"
● Unit tests: the problem is "in this method in this class"
End-to-end tests are complicated● Load specific set of test data into the database
● Run the application on a web server
● Start a browser
● Writing the test ● Depend on test data loaded elsewhere● Ignore side-effects of other tests
Why are unit tests not sufficient?● They test code in isolation
● Dependencies are mocked
● So what happens when a dependency changes interface?
● The application may break, while all unit tests pass!
● Because...
● Mocks lie to you!
The problem with unit tests: mocks lie to you!● How can mocks lie to us?
● ...because we hand-write them
● ...we copy assumptions that can change
● Can we automatically generate correct mocks?
Demonstration of a sample implementation● Node.JS
● Back-end: a REST-ful API
● Front-end: HTML + JavaScript
● Almost 100 end-to-end tests per second
● github.com/larsthorup/http-auto-mock-demo