Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

swiftdata-testing

/swiftdata-testing

Pisze i przegląda testy aplikacji opartych na SwiftData: kontenery w pamięci, atrapy repozytoriów, izolację actorów i asercje wartości pieniężnych.

Licencja
MIT
Ostatnia zmiana repozytorium
28.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
7
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 28.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pisze i przegląda testy aplikacji opartych na SwiftData: kontenery w pamięci, atrapy repozytoriów, izolację actorów i asercje wartości pieniężnych.

Oryginalny opis (EN)

Use when writing or reviewing unit/integration tests for a SwiftData-backed app. Writes and reviews SwiftData test code — in-memory ModelContainer fixtures, mock repository patterns, @ModelActor test isolation, Decimal money-value assertions, and content-hash dedup testing.

Jak działa

  1. Core Instructions
  2. Output Format
  3. Known Gotcha: migrationPlan + isStoredInMemoryOnly don't mix
Sekcje z nagłówków SKILL.md, w oryginale · 54 linii, 509 słów
Podgląd SKILL.md
---
name: swiftdata-testing
description: Use when writing or reviewing unit/integration tests for a SwiftData-backed app. Writes and reviews SwiftData test code — in-memory ModelContainer fixtures, mock repository patterns, @ModelActor test isolation, Decimal money-value assertions, and content-hash dedup testing.
license: MIT
metadata:
  author: Akshay Pimprikar
  version: '1.0'
---

Write and review SwiftData test code so it runs in isolation, never touches the device's persistent store, and catches the failure modes specific to `@Model`, `@ModelActor`, and money-typed data. Report only genuine problems — do not nitpick or invent issues.

Test-writing process:

1. For repository/integration tests, use `references/model-container-fixtures.md` for the in-memory `ModelContainer` setup.
1. For ViewModel unit tests, use `references/mock-repositories.md` — never construct a real `ModelContainer` just to unit test a ViewModel.
1. If the code under test uses `@ModelActor`, use `references/model-actor-testing.md` for actor-isolation-safe test patterns.
1. If the model stores currency/money values, use `references/decimal-money-values.md` — `Decimal` requires different assertion patterns than `Double`.
1. If the code deduplicates records via a content hash (e.g. CSV/API import), use `references/import-hash-dedup.md`.

If doing partial work, load only the relevant reference files.

## Core Instructions

- Target Swift 6.2+ with the `Testing` framework (`@Suite`, `@Test`, `#expect`, `#require`) — not XCTest, for unit and integration tests.
- Every test that touches SwiftData must use `isStoredInMemoryOnly: true`. A test that writes to the real persistent store is not a unit test — it's a device-state mutation with a `#Test` label on it.
- Never share a `ModelContext` or `ModelContainer` instance across tests. Build a fresh one per `@Test` — SwiftData containers are cheap, and cross-test state leakage produces the kind of intermittent failure that looks like flakiness but is actually a fixture bug.
- Domain/business-logic tests should not need a `ModelContainer` at all. If a test imports `SwiftData` just to instantiate a value it never persists or fetches, that's a sign business logic isn't cleanly separated from the persistence layer yet — flag it rather than writing around it.
- Never move a `@Model` instance across an actor boundary — not even in test code. Pass `PersistentIdentifier` or a value-type DTO and re-fetch inside the target actor.

## Output Format

If the user asks for a review, organize findings by file. For each issue:

1. State the file and relevant line(s).
2. Name the rule being violated.
3. Show a brief before/after code fix.

Skip files with no issues. End with a prioritized summary of the most impactful fixes.

If the user asks you to write or fix tests, follow the same rules above but make the changes directly instead of returning a findings report.

## Known Gotcha: `migrationPlan` + `isStoredInMemoryOnly` don't mix

Applying a `SchemaMigrationPlan` to an in-memory-only `ModelConfiguration` causes `save()` to fail — sometimes silently, sometimes non-deterministically depending on device load, which makes it look flaky rather than broken. An in-memory store starts fresh on every launch, so there is nothing to migrate.

```swift
// Before — breaks intermittently under isStoredInMemoryOnly
let container = try ModelContainer(
    for: schema,
    migrationPlan: AppMigrationPlan.self,
    configurations: [config]
)

// After — branch on isStoredInMemoryOnly before applying the migration plan
if config.isStoredInMemoryOnly {
    return try ModelContainer(for: schema, configurations: [config])
}
return try ModelContainer(for: schema, migrationPlan: AppMigrationPlan.self, configurations: [config])
```

This applies to both `@main` app-launch code (for UI test targets) and any test helper that happens to reuse the app's production container builder instead of a dedicated in-memory one.
Pliki w paczce (7)
  • LICENSE 1 KB
  • SKILL.md 4 KB
  • references/decimal-money-values.md 3 KB
  • references/import-hash-dedup.md 4 KB
  • references/mock-repositories.md 2 KB
  • references/model-actor-testing.md 3 KB
  • references/model-container-fixtures.md 3 KB

Wersje

W bazie nie ma innych skilli o nazwie swiftdata-testing.

Migawka bazy z 13.11.2026 · wersja paczki 09a0323c26b1 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 90swiftdata-code-review
    Przegląda kod SwiftData pod kątem projektu modeli, zapytań, współbieżności i migracji w plikach z import SwiftData, @Model, @Query, @ModelActor lub VersionedSchema.
  • 100swiftdata-pro
    Pisze, przegląda i ulepsza kod SwiftData, korzystając z nowoczesnych API i dobrych praktyk.
  • 100axiom-audit-swiftdata
    Przegląda użycie SwiftData: problemy z @Model, bezpieczeństwo migracji i wydajność.
  • 100swiftdata-pro
    Modeluje dane w SwiftData: klasy @Model, zapytania @Query, ModelContainer, migracje i synchronizację CloudKit na iOS 17+.
  • 100swiftdata-architecture
    Omawia wzorce projektowe SwiftData: projekt schematu, zapytania, wzorzec repozytorium i optymalizację wydajności przy projektowaniu modeli danych.
  • 100swiftdata-expert-skill
    Pomaga przy schematach SwiftData: relacjach, zapytaniach, konfiguracji kontenera, synchronizacji CloudKit, migracjach i przejściu z Core Data.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.