Lesson 18 — Programming Primer: The Code Under the Tests · Practical QA
LESSON VIEW
LAB-P · AUTOMATION PRACTICE LAB · PRACTICAL QA

Lesson 18 — Programming Primer: The Code Under the Tests

Objective: Read and write the four mechanics every FreshNest test is built from — variables, conditionals, loops over data rows, and functions with private parts — by predicting, completing, and debugging real test code before you run it.

⏱ ≈1.5 h practice unit · Code: predict, edit, run · Interactive unit — every exercise answers back · English edition

🧽 The practice business: FreshNest Home Cleaning — a fictional local cleaning company (owner: Maya Torres) invented for this course. Every example and exercise uses FreshNest, so you learn on a complete, realistic business without ever touching a real one.

⚡ Key Points

  • const seals a box; let refills it; the type decides what a value may do.
  • Branches must cover the world: name an input for every branch, including the refusal.
  • Loops are obedient, not wise — a wrong row or an off-by-one silently deletes coverage.
  • A function packages a rule once; callers obey its return contract (number | null means handle the null).
  • private keeps a page object's workshop locked; public is its promise; readonly fixes a fact at construction.

📖 Read

This unit is the floor under the whole Automation Practice Lab. LAB-0 showed you what a class is; the F-track modules (F-01…F-04) named the mechanics. Here you USE them, in the only order that teaches: predict first, run second. Every exercise in this unit follows the Code Studio pattern — you commit to an answer (a prediction, a completion, a bug verdict) and the unit answers back immediately, including when you are wrong. A wrong prediction you made on purpose, with the correction explained, teaches more than ten pages read passively.

The examples are not exercises about programming; they are the FreshNest lab's own material, arrived early. The price table you loop over here is the data LAB-3 will generate tests from. The phone branch is case VAL-003 written as code. The private locator you complete here is QuotePage.ts's real shape — the file LAB-0's worked example reads line by line. Nothing in this unit is throwaway: each snippet returns later, wearing its lab number.

How to work it: for PREDICT exercises, say the answer out loud (or write it) BEFORE opening the reveal — the interaction only works if the prediction is real. For RUN-EDIT, actually change the value and re-run; watching a different number come out is the lesson. For SPOT-BUG, the bug is always one small thing with a large consequence — that ratio is the profession.