DatabaseSnapshot

class DatabaseSnapshot(snapshotDbName: String) : AutoCloseable(source)

A frozen copy of a test database that can be used as a PostgreSQL TEMPLATE.

Obtain an instance via TestDataSource.createSnapshot.

Typical usage:

@BeforeAll
fun setupOnce() {
runExpensiveSetup(dataSource)
snapshot = dataSource.createSnapshot() // dataSource is now closed
}

@BeforeEach
override fun resetDatabase() {
dataSource = snapshot.newDataSource()
}

@AfterAll
fun teardownSnapshot() {
snapshot.close()
}

Constructors

Link copied to clipboard
constructor(snapshotDbName: String)

Functions

Link copied to clipboard
open override fun close()

Drops the underlying snapshot database.

Link copied to clipboard

Creates a fresh independent copy of the snapshot database. Each call returns a distinct HikariDataSource backed by its own database.