Understand the Single-binding rule
mainFlutter allows only one WidgetsBinding per process. Since MarionetteBinding is a binding, calling MarionetteBinding.ensureInitialized() while another binding (like AutomatedTestWidgetsFlutterBinding or IntegrationTestWidgetsFlutterBinding) is already active will throw an error.
Avoiding conflicts during flutter test
If your tests run in debug mode, they might trigger the Marionette initialization. Use one of these two strategies:
Option A: Skip Marionette when running tests
Check for the FLUTTER_TEST environment variable:
import 'dart:io' show Platform;
final isFlutterTest = Platform.environment.containsKey('FLUTTER_TEST');
if (kDebugMode && !isFlutterTest) {
MarionetteBinding.ensureInitialized();
} else {
WidgetsFlutterBinding.ensureInitialized();
}Option B: Use a separate test entrypoint
Keep MarionetteBinding in your production lib/main.dart and create a separate file (e.g., lib/main_test.dart) for tests that does not initialize MarionetteBinding.