Software design and testing lesson plan
How teams keep firmware right as it grows: readable code, modules behind narrow interfaces, fakes, tests on boot, test-first fixes, safe refactors and code review. Ends with a messy sketch refactored under test.
Objectives and materials
By the end, students can
- Names, one job per function, and modules behind a narrow interface.
- A harness in twenty lines, then bugs fixed test first.
- Refactors under test, and the review and git habits of a team.
- A messy dice sketch, fixed test first and refactored under its own self-test.
Materials for the whole unit
- Arduino Uno R3
- Fan module, L9110
- Full-size breadboard
- Half breadboard
- LED x 3
- Pushbutton
- Resistor x 3
- Seven segment display
- Temperature sensor
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Code people can read
Names, one job per function, and modules behind a narrow interface.
| Lesson | Time | What students do |
|---|---|---|
| Clean functions and namingA thermostat sketch that works and lies: one-letter names, magic numbers that drifted apart, one loop doing four jobs. Name the numbers, give each job a function, and read loop() like a table of contents. | 60 min |
|
| Modules and interfacesA thermostat that only knows a TempSensor interface: a real TMP36 and a fake behind the same door, a rehearsal with the fake on boot, a move into sensor.h, and a calibration added without touching the thermostat. | 55 min |
|
Materials
- Arduino Uno R3
- Fan module, L9110
- Half breadboard
- Temperature sensor
Check for understanding
Each student finishes "Modules and interfaces" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A third sensor, and no change to the thermostat".
Tests that run themselves
A harness in twenty lines, then bugs fixed test first.
| Lesson | Time | What students do |
|---|---|---|
| Unit tests with plain assertsA test harness in twenty lines: a CHECK macro that prints PASS or FAIL with the line and the condition, a summary line and a red or green lamp. Test the edges, meet a real failure, fix it, and switch the tests off for a release. | 60 min |
|
| Test-driven fixesA bug report against a countdown that passes all its tests: reproduce it on the hardware, pin it to one pure function, write the test that fails, fix it, triangulate the edges, and close the report. | 60 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Test-driven fixes" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Close the report".
Changing code safely
Refactors under test, and the review and git habits of a team.
| Lesson | Time | What students do |
|---|---|---|
| RefactoringA Beaufort wind scale as an if chain and a switch, reshaped into two tables with its tests green after every step: replace a conditional with a table, prove the net catches a slip, extract a function, and add a feature in one line. | 60 min |
|
| Code review and git, explainedCommits, branches, diffs and pull requests explained properly, then a real review: a teammate's pull request with a millis() rollover, an off-by-one and an int overflow, each caught by a checklist question and proven fixed by the self-test. | 55 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Code review and git, explained" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Your checklist, your commit".
Boss
A messy dice sketch, fixed test first and refactored under its own self-test.
| Lesson | Time | What students do |
|---|---|---|
| Boss: refactor the dice, tests greenThe gallery's electronic dice after a game night of quick fixes: one-letter names, an if chain, pasted code and a bug report. Fix the bug test first, then refactor it clean, one step at a time, with the self-test saying all pass after every run. | 70 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- Pushbutton
- Resistor
- Seven segment display
Check for understanding
Each student finishes "Boss: refactor the dice, tests green" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Finish it your way".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.