This document contains instructions for adding the unit test target to the Xcode project.
The unit tests have been created in:
BulletJournalTodos/BulletJournalTodosTests/ModelTests.swift
This file contains comprehensive tests for:
- Adding/Removing tasks updates
week.tasks: Tests that the relationship between Task and Week works correctly - Week creation with Monday start date: Tests that weeks are created with proper Monday-based start dates
- Task sorting by
sortOrderdescending: Tests that tasks can be sorted correctly by their sortOrder property
Since test targets need to be properly configured in the Xcode project, follow these steps:
-
Open the project in Xcode:
open BulletJournalTodos/BulletJournalTodos.xcodeproj
-
In Xcode, go to File → New → Target...
-
Select iOS → Unit Testing Bundle and click Next
-
Configure the test target:
- Product Name:
BulletJournalTodosTests - Team: Select your development team
- Organization Identifier:
com.vivqu - Bundle Identifier:
com.vivqu.BulletJournalTodosTests - Project:
BulletJournalTodos - Target to be Tested:
BulletJournalTodos - Click Finish
- Product Name:
-
Delete the default test file that Xcode creates (it will be named something like
BulletJournalTodosTests.swift) -
Add our existing
ModelTests.swiftfile to the project:- Right-click on the
BulletJournalTodosTestsfolder in Xcode - Select Add Files to "BulletJournalTodos"...
- Navigate to
BulletJournalTodos/BulletJournalTodosTests/ModelTests.swift - Make sure "BulletJournalTodosTests" target is checked
- Click Add
- Right-click on the
-
Ensure the test target has access to the main app's code:
- Select the
BulletJournalTodostarget - Go to Build Settings
- Search for "Enable Testing Search Paths"
- Ensure Enable Testability is set to Yes (it already is)
- Select the
- In Xcode, go to Product → Scheme → Edit Scheme...
- Select Test in the left sidebar
- Click the + button under "Test" if
BulletJournalTodosTestsis not listed - Add
BulletJournalTodosTeststo the test action
Once the test target is configured:
- Press Cmd+U to run all tests
- Click the diamond icon next to individual test methods to run specific tests
cd BulletJournalTodos
xcodebuild test -scheme BulletJournalTodos \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 17'The ModelTests.swift file includes:
testAddingTaskToWeekUpdatesTasksArray: Verifies adding a task updates the week's tasks arraytestRemovingTaskFromWeekUpdatesTasksArray: Verifies removing a task updates the week's tasks arraytestAddingMultipleTasksToWeek: Tests adding multiple tasks to a single week
testWeekCreationWithMondayStartDate: Ensures week start dates are always MondaytestWeekStartDateIsSetAtMidnight: Verifies start dates are at midnighttestMultipleWeeksWithDifferentMondays: Tests creating multiple weeks with correct Monday spacing
testTasksSortedBySortOrderDescending: Verifies tasks sort correctly by sortOrder (highest first)testTasksSortWithMixedFocusAreas: Tests sorting works correctly when filtering by focus areatestTasksSortWithEqualSortOrders: Edge case test for tasks with identical sortOrder values
testTaskInitializationWithDefaults: Verifies default values for Task initializationtestWeekInitializationWithDefaults: Verifies default values for Week initializationtestTaskCompletionToggle: Tests toggling task completion statetestFocusAreaEnumValues: Validates FocusArea enum values
- All tests use an in-memory SwiftData model container for isolation
- Tests are marked with
@MainActorfor SwiftData compatibility - The tests follow the Given-When-Then pattern for clarity