An introduction to Unit Tests (UT), Mocks, Integration Tests (IT), End-to-end Tests (E2E).
Say that you want to learn how to drive. π
[1/9]
At home, you have a car simulator.
Your Unit Tests will be:
πΈhow to turn on the car
πΈhow to speed up
πΈhow to slow down
πΈwhat to do with a red light
You are not using a real car, but a simulator. This is your *mock*.
[2/9]
UTs: test the behaviors in a controlled environment with mocks.
They are fast: you can stay at home with your simulator. In a minute you'll be able to redo your tests and add more (eg: turn on the lights)
[3/9]
Now it's time to try a real car, in a parking lot. π Ώ
Do the same actions you've seen work with a real car?
Those are Integration Tests: use real stuff, do better tests;
ITs are slower than UTs - you need a real environment, with a parking lot and a real car
[4/9]
What more do ITs add that you can't find with UTs?
For example, that the simulator used a car with automatic shift, but the real car has manual shift.
Or that you have to turn on the car before accelerating.
[5/9]
The actions you've tried with UT were all correct if performed in a "sandbox"! With ITs you put those tests together, into the real world.
[6/9]
But you're still in a parking lot.
With E2Es you put everything in practice, but this time for real.
Use a real car, on a real road, with real semaphores and other factors (traffic jams, blocked roads...)
[7/9]
E2Es are way slower than UTs, but provide you more info about a real scenario.
You will not run them for every new small thing you learn about driving. But you focus on a real scenario (eg: go to the nearest Walmart)
[8/9]
All those kinds of tests are useful in different ways. UTs are faster but in a sandboxed env. E2Es are slower but focused on real scenarios.
π’Slow β‘Fast
----------------------->
E2E IT UT
----------------------->
πWide πNarrow
[9/9]
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh