Integration test `enterText` method not working on profile or release mode

Issue

Test passes in debug mode but not in profile or release mode. It does not enter text when calling enterText even if the input has focus. In debug mode it enters the text without problems.

Solution

This is an issue, or more exactly a difference between how integration-tests work in debug vs profile or release.

TLDR

Basically if you’re not in debug mode you have to call binding.testTextInput.register() in order for tester.enterText to work.

  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;

// Necessary for being able to enterText when not in debug mode 
  binding.testTextInput.register();

This will permit to call enterText during integration testing.
As a caveat this will disable the use of real keyboards during the test, but most of the times that is not the case.

Why does that happens?

Because in debug mode this is permitted via an assert which don’t work on profile or release modes. See source code

Answered By – croxx5f

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *