Why off the board
To try a change on the board you compile, upload over USB, then watch the serial monitor. A cold room is hard to make on demand. And nothing checks the old cases again for you.
Find the seam
Split the code. tempC and needHeat are plain C: no pins. Only read_raw() touches hardware, and on the Uno it calls analogRead(A0). That one thin function is the seam where hardware plugs in.
The laptop's own compiler, such as gcc, turns temp.c into an ordinary program for the laptop. Same source file, different processor. A program built to run where it was compiled is called native.
The test build links a fake read_raw() instead. It just returns fake_raw, a variable the test sets. Now any temperature is one line away, with no board and no sensor. A stand-in like this is called a test double.
One test
test_cold arranges: fake_raw = 141. Then it acts: needHeat() reads 141 from the fake, tempC turns it into 18 degrees, and 18 < 20, so it returns true.
TEST_ASSERT_TRUE(on) is the assert step. Unity, a C test framework built for embedded code, checks the value and reports PASS. Had needHeat() returned false, Unity would report FAIL for test_cold.
Bugs hide at edges. test_edge sets fake_raw = 144, which is exactly 20 degrees. 20 is not below 20, so it expects false. A real room would almost never sit there on cue.
Someone edits line 5 to say <= instead of <. Now needHeat() returns true at 20 degrees. test_edge fails on the laptop seconds later, before any firmware reaches the board.
Because the tests are native, the whole set reruns after every edit, and a build server can run them on each commit too. Old cases stay checked, so a change that breaks one shows up straight away.
Limits
On the Uno an int is 16 bits; on the laptop, 32. Drop the L from 500L and raw*500 overflows on the board for raw above 65, yet every laptop test still passes. So run some tests on the board too.
What happens
;; step 1/10 · slow edit -> compile -> upload -> watch serial output every try needs the board, the cable and the sensor cold, hot, the exact set point: hard to make for real
The cards show only the logic and one test. The test file also includes unity.h and temp.c's header, and has a main() that calls UNITY_BEGIN(), RUN_TEST for each test and UNITY_END(). Unity also wants setUp() and tearDown() functions, which may be empty. bool comes from stdbool.h. Signed int overflow is undefined behaviour in C, and the Arduino reference says the result "is unpredictable". With raw = 66, raw*500 = 33,000 does not fit in 32,767, so writing 500L (a long constant) makes the multiply a long: at least 32 bits on both machines (32 on the Uno, usually 64 on a 64-bit macOS or Linux laptop), so it fits on both.