goose_test 0.1.0
goose_test: ^0.1.0 copied to clipboard
A testing library which makes it easy to test migrations. Built to be used with the Goose migration package.
🧪🪿 Goose Test
A testing library which makes it easy to test migrations. Built to be used with the Goose migration package.
Installation #
Add goose_test
as a dev dependency to your pubspec.yaml file (what?).
You can then import Goose Test in your test file:
import 'package:goose_test/goose_test.dart';
Using testMigration
#
testMigration
creates a new migration
-specific test case with the given description
. testMigration
will handle running the migration's up and down methods. testMigration
also ensures that the migration will always happen in the order of up
first and then try revert through the down
method to ensure that the migration can be reverted.
Parameter | Description |
---|---|
create |
Should create and return the migration that is to be tested. |
setupUp |
An optional callback which is invoked before the migration 's up is called and can be used for setting up the migration's required data for the up migration. For common set up code, prefer to use setUp from package:test/test.dart . |
verifyUp |
An optional callback which is invoked after the migration 's up was called and can be used for additional verification/assertions. verifyUp is called with the migration returned by create . |
setupDown |
An optional callback which is invoked before the migration 's down is called and can be used for setting up the migration's required data for the down migration. For common set up code, prefer to use setUp from package:test/test.dart . |
verifyDown |
An optional callback which is invoked after the migration 's down was called and can be used for additional verification/assertions. verifyDown is called with the migration returned by create . |
tags |
An optional argument and if it is passed, it declares user-defined tags that are applied to the test. These tags can be used to select or skip the test on the command line, or to do bulk test configuration. |
import 'package:goose/goose.dart';
import 'package:goose_test/goose_test.dart';
import 'package:test/test.dart';
class MyMigration extends Migration {
MyMigration(this.storage)
: super('my_migration', description: 'A simple migration');
final Map<String, dynamic> storage;
@override
Future<void> down() async => storage.clear();
@override
Future<void> up() async => storage['migrated'] = true;
}
void main() {
group('MyMigration', () {
late Map<String, dynamic> storage;
setUp(() => storage = {});
testMigration(
'executes correctly',
create: () => MyMigration(storage),
verifyUp: (_) => expect(storage['migrated'], isTrue),
verifyDown: (_) => expect(storage.isEmpty, isTrue),
);
});
}