Almost anyone agrees about what is a Unit Test. QA engineers and developers usually give Integration Test different meanings. Extreme Programming defines the Programmer Test concept, whose objective is to create more useful tests. This article outlines the properties of each type of test and creates a common ground to speak about them.
You get the headlamp, place a sensor as a lightbulb, and connect the headlamp to a power source. The test passes if the sensor receives power.
Unit test: the lamp.
The test is: does the headlamp powers the lightbulb outlet when it receives power? Complete the Use Case with additional tests for the lightbulb, the switch, the battery, and the wire.
Unit tests have no business value. Probably you are a car factory company, not a headlamp factory company. If you read all the tests, you know which parts you need to build a car, but no idea how to make a car. Changes are hard; if you change any piece, you have to rebuild your tests for that piece, and you do not know how it affects other parts.
Confidence is low. You are not checking if the headlamp socket is compatible with the lightbulb, or if the headlamp glass is black, and it does not allow light to pass; just to name a few.
You get the headlamp, a light bulb, a battery, a light switch, interconnect them. Turn the switch on. The test passes if the light bulb emits light.
Programmer test: the lamp lights.
The test is: does turning the switch on lighting the lamp?
Programmer tests have business value. You know what the headlamp does and how it works. Each test becomes a small manual about how to build a car part. You can switch lightbulbs, headlamps, and other pieces, and the test still passes if it works.
Confidence is high. You are not checking each part and also that everything is working well together.
You build a car and place it in a dark street. Unlock the door, turn the key, and turn on the light switch. The test passes if it illumines the street correctly.
Integration test: the car lights the street.
The test is: does turning the switch on making the car light the road?
These tests are real business value. You know what the car must do. You can change any part and still check if everything works. The problem is that if something fails, you have to debug the full car.
Confidence is the highest. You have a real car. It is also slow because you need to build a new car for each test.
#testing #integration-testing #unit-testing