I have an integration test file with 3 test cases. I want to be sure that the third test case is always executed last (otherwise other test cases will fail) – how can I accomplish this?
Are the test cases always executed in the order in which they're defined?
I know that test cases depending on one another is a bad pattern, but let's forget it for the matter of this discussion (I need to define 3 test cases in a single
.dart
file becauseflutter test integration_test
takes quite a long time to run a single Dart test file).
Here's the code:
// integration_test/login_test.dart
import 'package:flutter_test/flutter_test.dart';
void main() {
group('login screen', () {
testWidgets(
'shows proper error message when email has incorrect format',
(tester) async {
// test code
},
);
testWidgets(
'shows error message when password is incorrect',
(tester) async {
// test code
},
);
testWidgets(
'logs in with correct credentials',
(tester) async {
// test code
},
);
});
}
If the third test case ("logs in with correct credentials") gets executed as the first or second, then the other test case(s) will fail because the app will already be in the logged-in state.
Is there a way to enforce the order in which tests are executed?
The
flutter test
(anddart test
) have the--test-randomize-ordering-seed
argument. By default, it is not set, which means that test run in the order in which they're defined.The below is copied from
flutter test --help
: