Bench
A test bench for Dart, available under the MIT license.
Usage
Declare Test Libraries.
// The TestGroup annotation is optional.
@TestGroup('Console', runs: const ['a', 'b'])
library bench.example.console;
Declare Setup and Teardown Functions.
// The @Setup function is optional; there may be 0 or 1 per test library.
@Setup
// The TestRun argument is optional; it carries context based on @TestGroup.
setup(TestRun run) {
if (run.id == 'a') {
print('Setup is invoked one time before each test.');
} else {
print('And it can do different work each time the test group runs!');
}
}
// The @Teardown function is optional; there may be 0 or 1 per test library.
@Teardown
// The optional TestRun argument may also be received here.
teardown() => print('Teardown is invoked one time after each test');
Declare Test Functions.
@Test('An example test case that passes.')
void testPass() {
expect(true, isTrue);
}
@Test()
@ExpectError(isStateError)
void testError() {
throw new StateError('snarf');
}
@Test()
@ExpectError(isUnimplementedError)
testAsyncError() {
return new Future.delayed(const Duration(milliseconds: 100), () {
throw new UnimplementedError();
});
}
@Test('Known to fail.')
@Skip('http://issue/42')
testSkipKnownFailure() {
expect(false, isTrue);
}
Reflect and Run Tests.
import 'package:bench/bench.dart';
// TODO: import your test libraries here so that reflection can find them.
// You may also add a `main` to a test library so that it may be run standalone!
void main() => reflectTests();