Lab: Test and harden your app
Add a test suite, deliberately break something to watch a test catch it, and audit your app for unsafe force-unwraps.
A passing test suite plus a codebase with the obvious crash risks removed — the difference between 'works on my simulator' and 'ready for other people.'
Step 1 — Add and run tests
- 1Open the test file Xcode created with your project (or add a Unit Testing target).
- 2Paste the tests from the lesson and generate a couple more with the prompt.
- 3Press ⌘U. Fix anything red until the suite is green.
Step 2 — Watch a test do its job
- 1Temporarily change
firstLineto return the last line instead of the first. - 2Run ⌘U and watch the test fail with a clear message.
- 3Revert the change; the test passes again. This is the safety net you now have on every future edit.
Step 3 — Hunt down force-unwraps
Review these files for force-unwraps (!) and force-tries (try!) that could crash at runtime. For each, tell me whether it's actually safe or should become optional handling, and show the safer version. Files: [paste your view + service files].
Apply the fixes that are real risks. A single ! on a value that's usually-but-not-always present is the most common crash in shipped indie apps — spending 15 minutes here meaningfully raises your app's reliability.
If you have an iPhone, run the app on it (Module 8 covers signing). Real devices surface issues the simulator hides: slower networks, smaller screens, permission prompts. Even one run on hardware catches bugs testers would otherwise find for you.
git add .
git commit -m "Add test suite and remove unsafe force-unwraps"