given_when_then_unit_test
0.2.1, released 3 years ago by devcraft.ninja
BDD-style helpers for writing readable Dart unit tests
WASM-ready
What it does
Provides `given`, `when`, `then`, `and`, `but` functions to structure test code in natural language. It automatically composes test descriptions and supports async tests, fixtures, and test case generators.
AI-written summary of version 0.2.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- writing unit tests that benefit from clear BDD structure
- integrating with `shouldly` for expressive assertions
- creating parameterized test cases with `testCases` helpers
Skip it when
- projects that already use a different BDD framework or prefer traditional `group`/`test` syntax
- tests requiring complex mocking where the package conflicts with mocktail or mockito
Strengths
- improves test readability and documentation
- auto-generates descriptive test names
- supports async tests and fixtures
- provides generic test case helpers
Weaknesses
- conflicts with mocktail/mockito due to `when` keyword
- limited to unit tests, not integration or widget tests
- no code generation or advanced features
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
Add dependency and import `package:given_when_then_unit_test/given_when_then_unit_test.dart`
```dart
import 'package:given_when_then_unit_test/given_when_then_unit_test.dart';
given('empty calculator', () {
late Calculator calc;
before(() => calc = Calculator());
when('add 1', () => calc.add(1), then: () {
then('result should be 1', () {
calc.res.should.be(1);
});
});
});
```Alternatives
Packages that do the same job and could replace given_when_then_unit_test.
Works with
Packages commonly used together with given_when_then_unit_test: ones it builds on, ones built on it, and its own family.