Important! All test files must end with _test.dart
to be caught by the flutter test
commandline tool.
- A test description must conform to the GIVEN, WHEN, THEN syntax. Example: GIVEN no token in SecureStorage WHEN calling onRequest THEN no Authorization Header is added to the request.
- A test should be limited to only test one case
The Mockito package is used for mocking classes in unit tests.
A class which should be mocked, is declared in the @GenerateMocks([Type])
annotation. Then a Mock
of the class is generated by code generation.
// Annotation which generates the secure_storage.mocks.dart library and the MockSecureStorage class.
@GenerateMocks([SecureStorage])
void main() {
// Create mock object.
var cat = MockSecureStorage();
}
Golden files for UI tests are auto-generated. This is doing by first implementing the test (Pump widget, compare to golden file), then generating the file using
flutter test --update-goldens [path/to/test.dart]
If no path is given, all goldens will be updated.
Due to OS specific rendering, golden tests will fail in the pipeline if not generated using a linux distro.
(TODO: Make dockerfile for golden generation)