https://github.com/groue/grdbsnapshottesting
The snapshot testing library for GRDB
https://github.com/groue/grdbsnapshottesting
database grdb snapshot-testing sqlite testing
Last synced: 3 months ago
JSON representation
The snapshot testing library for GRDB
- Host: GitHub
- URL: https://github.com/groue/grdbsnapshottesting
- Owner: groue
- License: mit
- Created: 2023-10-12T20:19:16.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-29T15:29:05.000Z (9 months ago)
- Last Synced: 2025-02-27T23:05:12.061Z (4 months ago)
- Topics: database, grdb, snapshot-testing, sqlite, testing
- Language: Swift
- Homepage:
- Size: 46.9 KB
- Stars: 34
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# GRDBSnapshotTesting
**The snapshot testing library for GRDB**
**Requirements**: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ • Swift 6+ / Xcode 16+
📖 **[Documentation]**
---
This package makes it possible to test [GRDB] databases with [SnapshotTesting].
See the [Documentation] for usage tips and case studies (testing a fresh install, testing a specific migration, etc).
## Usage
```swift
import GRDB
import GRDBSnapshotTesting
import InlineSnapshotTesting
import XCTestclass MyDatabaseTests: XCTestCase {
func test_full_database_content() throws {
let dbQueue = try makeMyDatabase()
assertInlineSnapshot(of: dbQueue, as: .dumpContent()) {
"""
sqlite_master
CREATE TABLE player (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
score INTEGER NOT NULL);player
- id: 1
name: 'Arthur'
score: 500
- id: 2
name: 'Barbara'
score: 1000
"""
}
}
func test_tables() throws {
let dbQueue = try makeMyDatabase()
assertSnapshot(of: dbQueue, as: .dumpTables(["player", "team"]))
}
func test_request() throws {
let dbQueue = try makeMyDatabase()
try dbQueue.read { db in
assertSnapshot(of: Player.all(), as: .dump(db))
}
}
func test_sql() throws {
let dbQueue = try makeMyDatabase()
try dbQueue.read { db in
assertSnapshot(of: "SELECT * FROM player ORDER BY id", as: .dump(db))
}
}
}
```[GRDB]: http://github.com/groue/GRDB.swift
[SnapshotTesting]: https://github.com/pointfreeco/swift-snapshot-testing
[Documentation]: https://swiftpackageindex.com/groue/GRDBSnapshotTesting/documentation