java-james / flutter_dotenv

Loads environment variables from `.env`.
https://pub.dartlang.org/packages/flutter_dotenv
MIT License
220 stars 47 forks source link

Issues using testLoad() in integration tests #94

Closed MickaelHrndz closed 10 months ago

MickaelHrndz commented 11 months ago

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 :

java-james commented 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.

MickaelHrndz commented 10 months ago

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

MickaelHrndz commented 10 months ago

@java-james you might want to edit the README to make a distinction between unit/widget and integration tests.