Back to course overview
Module 6Testing & debugging with AI 30 min

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.

Outcome of this lab

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

  1. 1Open the test file Xcode created with your project (or add a Unit Testing target).
  2. 2Paste the tests from the lesson and generate a couple more with the prompt.
  3. 3Press ⌘U. Fix anything red until the suite is green.

Step 2 — Watch a test do its job

  1. 1Temporarily change firstLine to return the last line instead of the first.
  2. 2Run ⌘U and watch the test fail with a clear message.
  3. 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

Prompt to try

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.

Test on a real device now

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.

bashbash
git add .
git commit -m "Add test suite and remove unsafe force-unwraps"