sinew_testing 1.0.0
sinew_testing: ^1.0.0 copied to clipboard
Fakes and test helpers for apps built on Sinew. A dev dependency only.
sinew_testing #
Fakes and test helpers for apps built on Sinew. A dev dependency only.
A fake for every Sinew interface, so a test of your repository or notifier runs without a device, a network or a platform plugin, and fails the way the real thing fails.
Features #
mockHttp: a realDioon a mock adapter, with routes and recorded requestsControlledFetch: answer a pager's calls by hand, to test loading, retry and refresh in orderFakeKeyValueStore,FakeSecureStore,FakeFieldCipher,FakeBiometricVault,FakeTokenSource,FakeRefreshTokenStore,FakeNetworkCheckerandFakeLocalizerRecordingCrashReporterandinstallRecordingReporter, to assert what was reportedfixtureto load a JSON fixture, anddiskFullErrorandplatformStorageErrorfor storage failures
Getting started #
flutter pub add --dev sinew_testing
Usage #
Test a repository against a mock backend:
test('orders load', () async {
final http = mockHttp((routes) => routes
.on('GET', '/v1/orders').respond(200, body: fixture('orders_page.json')));
final result = await OrderRepository(OrderApi(http.dio)).page(1);
expect(http.requests.single.uri.path, '/v1/orders');
});
Hold a pager's calls open to test every state of a list:
final fetch = controlledFetch<Order>();
final pager = Pager<Order>.offset(fetch.call);
Related packages #
Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.
Documentation #
- Usage docs: sinew.srctool.com
- API reference: pub.dev/documentation/sinew_testing
- Source and issues: srctool/sinew-dart
- Design and decisions: the Guide
License #
Apache 2.0, see LICENSE.