Testing firmware lesson plan
A thermostat tested the way firmware teams do it, every test running on the Uno and printing PASS or FAIL: pure logic first, fake pins and a fake clock, tests on target for the DS18B20 and the relay contact, a second Uno as a hardware-in-the-loop rig, a regression caught and fixed, TAP reports, and a thermostat that tests itself at every boot.
Objectives and materials
By the end, students can
- Pure functions, then fakes for the sensor, the relay and the clock.
- On the target itself, and from a second board in the loop.
- Regressions caught and fixed, and reports a machine can read.
- A thermostat that proves itself at every boot.
Materials for the whole unit
- Arduino Uno R3 x 2
- Relay module
- Temperature sensor, DS18B20
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.
Tests without hardware
Pure functions, then fakes for the sensor, the relay and the clock.
| Lesson | Time | What students do |
|---|---|---|
| Pure logic firstThe thermostat’s judgment as one function with no pins in it, five tests that run on the board at boot and print PASS or FAIL, and the same function then driving a real DS18B20 and relay. | 60 min |
|
| Fake pinsThe thermostat talks to its sensor, relay and clock through three function pointers, so tests swap in fakes: scripted temperatures, a recorded relay, and a clock that runs twelve minutes of thermostat life in a fraction of a second. | 60 min |
|
Materials
- Arduino Uno R3
- Relay module
- Temperature sensor, DS18B20
Check for understanding
Each student finishes "Fake pins" 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: "Designing for test".
Tests with hardware
On the target itself, and from a second board in the loop.
| Lesson | Time | What students do |
|---|---|---|
| Tests on targetTests that only the real board can run: the DS18B20 answers with family code 0x28, converts inside the datasheet time and reads a plausible value, and the relay contact really closes and opens. Then a missing pull-up, and a test that passes for the wrong reason. | 70 min |
|
| Hardware in the loopA second Uno tests the thermostat from outside, as a production test station would: it sends setpoints over the serial link and times the relay contact, never looking inside. Then a warmer room breaks a test that assumed 22 C. | 60 min |
|
Materials
- Arduino Uno R3 x 2
- Relay module
- Temperature sensor, DS18B20
Check for understanding
Each student finishes "Hardware in the loop" 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: "What HIL is for".
Tests that keep working
Regressions caught and fixed, and reports a machine can read.
| Lesson | Time | What students do |
|---|---|---|
| RegressionsA one-line change that worked on someone’s desk, "tighter temperature control", fails a test written weeks earlier: the relay would switch 16 times in ten noisy minutes. Read the failure, find the change, fix it, and keep the test. | 60 min |
|
| Test reportsThe thermostat’s self-test reported two ways: lines a person reads, or TAP, the Test Anything Protocol a CI server parses, with a firmware version, a plan line, diagnostics and a to-do test for a feature not built yet. | 50 min |
|
Materials
- Arduino Uno R3
- Relay module
- Temperature sensor, DS18B20
Check for understanding
Each student finishes "Test reports" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Reports people trust".
Boss project
A thermostat that proves itself at every boot.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a tested thermostatA thermostat that proves itself at every boot (logic tests, then on-target checks of its DS18B20 and relay contact) and refuses to heat if anything fails, then runs with a rest time and fails safe on a lost sensor. | 60 min |
|
Materials
- Arduino Uno R3
- Relay module
- Temperature sensor, DS18B20
Check for understanding
Each student finishes "Boss: a tested thermostat" 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 test plan".
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.