RefreshDatabase class

Laravel's RefreshDatabase, for package:test: a fresh in-memory SQLite database migrated once, emptied after every test so no row leaks into the next one. The schema is migrated once, not per test.

It hands the hooks back instead of registering them, so this package needs no dependency on a test runner — wire them in your main():

void main() {
  final db = RefreshDatabase(migrations: [CreateWidgetsTable()]);
  setUpAll(db.migrate);
  tearDown(db.truncate);
  tearDownAll(db.close); // optional

  test('inserts a widget', () async {
    await DB.table('widgets').insert({'name': 'wrench'});
    expect(await DB.table('widgets').count(), 1);
  });
}

Constructors

RefreshDatabase({List<Migration> migrations = const []})

Properties

hashCode int
The hash code for this object.
no setterinherited
migrations List<Migration>
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() Future<void>
Closes the database and forgets it as the default connection. Wire into tearDownAll when a suite shares its isolate with other database tests.
migrate() Future<void>
Opens the database, makes it the default connection and migrates it. Wire into setUpAll.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
truncate() Future<void>
Deletes every row from every table except the migrator's own bookkeeping, keeping the schema, and resets autoincrement counters so ids restart at 1. Wire into tearDown.

Operators

operator ==(Object other) bool
The equality operator.
inherited