Skip to content

Cannot find .env file when running tests #58

Answered by revosw
revosw asked this question in Q&A
Discussion options

You must be logged in to vote

If I had just READ THE DOCUMENTATION, I would have seen the section about testing.

https://pub.dev/packages/flutter_dotenv#using-in-tests

My test now looks like this, and it works

import 'package:user_app/main.dart' as app;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  group('end-to-end test', () {
    testWidgets('reads mailing list', (WidgetTester tester) async {
      IntegrationTestWidgetsFlutterBinding.ensureInitialized();
      // Now I can access environment variables from dotenv.env[]
      dotenv.testLoad(fileInput: File("./.env").readAsStringSync());
      await app.main();
      await tester.pumpAndSettle();
    });
  });
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by java-james
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant