Integration Testing Lesson

Integration testing checks whether different parts of a program work correctly together. A function can work alone but fail when connected to the user interface, storage, an API, or another module.

Demo

Code Runner Challenge

Integration Testing Lesson

View IPYNB Source
%%js

// CODE_RUNNER: Integration Testing Lesson

function saveScore(storage, player) {
  storage.setItem("score", String(player.score));
}

function loadScore(storage) {
  return Number(storage.getItem("score"));
}

const player = { score: 120 };
saveScore(localStorage, player);
console.log(loadScore(localStorage));
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

The important part is the connection point. The test should confirm that the right data moves from one part to another in the right format.

Integration tests are useful after features are combined. They catch problems that do not appear when each piece is tested separately.