Closed MickaelHrndz closed 10 months ago
Thanks for raising this. I've been away from home and off the tools for the end of last year. Just a note to say I'm getting back into it and on the tools from this week.
I didn't try injecting variables directly (like fileInput: '''FOO=foo'''
) until now because I have a lot of them so it's not a viable solution for me. But trying it helped me realize that the GetIt
error came from my project, and so the regular dotenv.load()
is working in integration tests. It's my bad, I forgot that #63 mentions it. I didn't think it'd be a viable solution at the time since it seemed to say that you can't access the env values. However, it turns out that you can. Everything seem to work fine.
TL;DR : Use dotenv.load()
in integration tests
@java-james you might want to edit the README to make a distinction between unit/widget and integration tests.
This issue is a continuation of #63
I'm trying to read env variables in an integration test. I've successfully read the .env file when running the app in debug and release mode using
await dotenv.load(fileName: ".env");
. However, I can't make it work for integrations tests. Here are the ways I'm trying to initialize the plugin and the subsequent errors I'm getting :dotenv.testLoad(fileInput: File('.env').readAsStringSync());
: PathNotFoundException: Cannot open file, path = '.env' (OS Error: No such file or directory, errno = 2)dotenv.testLoad(fileInput: '.env');
: The following StateError was thrown building SubApp(dirty): Bad state: GetIt: Object/factory with type InternetCheckerBloc is not registered inside GetItawait DotEnv().load();
: The following NotInitializedError was thrown building NewApp(dirty): Instance of 'NotInitializedError'await dotenv.load(fileName: ".env");
: Bad state: GetIt: Object/factory with type InternetCheckerBloc is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?)