How to find if we are running unit test in Dart (Flutter)

Issue

While calling a function from unit test in Flutter (Dart), how can I find if I am running unit test or real application?
I want to pass different data if it’s in unit test.

Solution

You can use the following to check if you’re running a test.

Platform.environment.containsKey('FLUTTER_TEST')

Answered By – Ovidiu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published