I was also looking for a solution but the line:
Platform.environment.containsKey('FLUTTER_TEST')
or the line:
Get.testMode
do not seem to work during integration testing, for example. So I just created a singleton class that holds a variable isTest set to false as default.
class TestController {
static final _testController = TestController._internal();
TestController._internal();
factory TestController() {
return _testController;
}
bool isTest = false;
}
And i change it to true at the start of the integration test:
void main() {
enableFlutterDriverExtension();
TestController().isTest = true;
app.main();
}
Maybe is not that elegant as a solution, I know, but it works in my case at least. That way I can successfully inject the appropriate dependencies I need for test and production environments.
void _setWindowAndInjectDependencies() {
final isTest = TestController().isTest;
DesktopWindow.setWindowSize(const Size(1060, 960));
DesktopWindow.setMinWindowSize(const Size(1060, 960));
_loadCommonDependencies();
if (!isTest) {
print("Not Test Mode");
_loadMacDependencies();
} else {
_loadTestDependencies();
}
}
I hope this provides some help.