GRDBSnapshotTesting

0.3.0

The snapshot testing library for GRDB
groue/GRDBSnapshotTesting

What's New

2023-10-29T11:54:30Z
  • New Minimum GRDB version is now 6.21.0.
  • New The dumpTables snapshotting is now able to handle database views.
  • New The Testing Database Content documentation article better addresses the testing strategies for modifications to the latest migration.

GRDBSnapshotTesting

The snapshot testing library for GRDB

Requirements: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ • Swift 5.7+ / Xcode 14+

📖 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

import GRDB
import GRDBSnapshotTesting
import InlineSnapshotTesting
import XCTest

class 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))
        }
    }
}

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Wed Jun 19 2024 02:07:17 GMT-0900 (Hawaii-Aleutian Daylight Time)