Browse Mobile App Development Section 8: Testing

Write Unit Tests for a View Model / Business Logic

2 fill-in slots · from The AI Prompt Handbook for Mobile App Development

Your details

0/2 filled

Write Unit Tests for a View Model / Business Logic

Background: Native [iOS / Android] app. Here's the view model / use case
I want tested, plus the dependencies it takes:
[paste the code and its dependency interfaces]

Use case: Write thorough unit tests for this logic in isolation, with its
dependencies mocked.

Implementation details:
- iOS: XCTest (or Swift Testing if I'm on it); mock dependencies behind
  their protocols. Android: JUnit + a mocking approach (fakes or
  MockK); inject test doubles.
- Cover: happy path, every error path, empty/boundary inputs, and the
  state transitions the view model exposes (loading → loaded/error)
- Assert on the observable state the UI would see, not internals
- Each test independent, deterministic, and fast (no real network/db)
- Clear Arrange / Act / Assert structure and descriptive test names

Layer & dependencies: Pure logic tests—no UI, no simulator/emulator
needed.

Deliverable: The test suite with fakes/mocks for the dependencies, tests
for happy/error/boundary paths and state transitions, and a note on any
behavior that's hard to test (and what refactor would fix that).

Highlighted [slots] are still empty. Downloads are plain .txt — paste into any AI assistant.