Why you need it
Two people change the same app on the same day. Each change works on its own laptop. Put together in main, they break the app, and nobody finds out until much later, when it is hard to tell whose change did it.
Think of it like this
Two cooks each taste their own sauce and say it is fine. Mixed in one pot, it is too salty. So every new spoonful is tasted in the pot, right away, before the next one goes in.
Where you’ll find it
- GitHub: GitHub Actions runs the tests on every change, and its merge queue tests each change with the newest main before it goes in.
- GitLab: GitLab CI/CD starts a test run for every push, and a failing run can block the merge.
- Google: Its TAP system tests changes from tens of thousands of engineers against one shared main, all day.
What to know first
Main. The one shared copy of the code that everyone adds their changes to. What is in main is what ships.
Change. A small set of edits one person wants to add to main, like Ana's or Ben's card in the animation.
Test. A small program that runs the app's code and checks the answer. It passes or it fails, with no person needed.
How it works
- Alone is not enough. Ana renames
pricetocost. Ben's new line still usesprice. Both pass on their own. Together, Ben's line calls a name that no longer exists. This is the break in the animation. - Test with main first. Before a change goes in, a machine puts it together with the newest main and runs all the tests. This is the card touching main in the animation.
- A fail stays out. If the tests fail, the change goes back to its author and main is not touched. Everyone else keeps working on a main that works.
- Small and often. Add small changes at least once a day. A small change that fails is quick to fix, and there is little to search through to find the cause.
- Main keeps moving. While Ben's tests run, someone else's change may go in. So the test must be on the main as it will be, not as it was this morning. A merge queue does this in order, one change at a time.
An example
A team of 8 adds about 30 changes a day. Without testing together, they merge on Friday and find 3 breaks among 150 changes.
With continuous integration, each change is tested with main in about 10 minutes before it goes in.
A break is caught the moment it appears, with one change to look at instead of 150.
Further reading
- Continuous Integration, Martin Fowler. The classic explanation, from one of the people who named it. Start with this one.
- Continuous integration, DORA. What years of research say good teams do, and common mistakes.
- Trunk-based development, DORA. Why short-lived changes into one main beat long branches.