Dart/Flutter: Share common setUp/tearDown methods among test suites Dart/Flutter: Share common setUp/tearDown methods among test suites dart dart

Dart/Flutter: Share common setUp/tearDown methods among test suites


Create a file called flutter_test_config.dart in the same directory as your test (or at a higher level, it'll affect all tests in that directory and below).

In that file, you can then call the setUp and tearDown methods before your test file's main method runs:

import 'dart:async';import 'package:flutter_test/flutter_test.dart';Future<void> main(FutureOr<void> Function() testMain) async {  setUp(() {    print('Shared setUp');  });  tearDown(() {    print('Shared tearDown');  });  await testMain();}

Documentation: https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html