Sitelet https://github.com/flutter/flutter/pull/188963
Skip to content

Fix non-independant tests in binding_test.dart - #188963

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
ValentinVignal:flutter-test/Fix-independant-in-binding-test
Aug 8, 2026
Merged

auto-submit[bot] merged 4 commits into
flutter:masterfrom
ValentinVignal:flutter-test/Fix-independant-in-binding-test

Conversation

@ValentinVignal

Copy link
Copy Markdown
Contributor

Part of #85160

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jul 4, 2026
@github-actions github-actions Bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Jul 4, 2026
setUp(() {
expect(binding.testTextInput, isNotNull);
expect(binding.testTextInput.isRegistered, isFalse);
expect(HttpOverrides.current, isNotNull);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what HttpOverrides.current has to do with this test. But it was there before, so I left it there. Let me know if you want me to remove it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it looks like it was added to verify that httpOverrides is initialized in TestWidgetsFlutterBinding. Could we pull expect(HttpOverrides.current, isNotNull) out of the testTextInput group and into its own test case to make sure we don't lose it? Because I agree, I don't think this is the right place for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move things around a little bit.

HttpOverrides.current is being set by the first testWidgets if the file when it runs TestWidgetsFlutterBinding.ensureInitialized()

final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();

/// Setup mocking of the global [HttpClient].
void setupHttpOverrides() {
HttpOverrides.global = _MockHttpOverrides();
}

So I had to split the tests into 2 files:

  • packages/flutter_test/test/http_overrides/test_test.dart
  • packages/flutter_test/test/http_overrides/test_widgets_test.dart

Let me know what you think about it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looking at when the check was added (commit), I think we really just need to check that TestWidgetsFlutterBinding.ensureInitialized() registers the HttpOverrides. So I think instead of splitting the test cases out into separate files, we can probably add the following to bindings_test.dart and that should be sufficient to ensure we are not regressing on our test coverage:

  group('HttpOverrides', () {
    testWidgets('testWidgets registers HttpOverrides', (WidgetTester tester) async {
      expect(HttpOverrides.current, isNotNull);
    });
  });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, I moved it back in Move back test in bindings_test.dart :)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the no-shuffle tag from bindings_test.dart and refactors sequential tests into a structured testTextInput group with setUp and tearDown blocks. Feedback suggests separating the unrelated HttpOverrides.current assertion from the testTextInput group's setup into its own independent test case to avoid coupling unrelated behaviors.

Comment on lines +40 to +45
group('testTextInput', () {
setUp(() {
expect(binding.testTextInput, isNotNull);
expect(binding.testTextInput.isRegistered, isFalse);
expect(HttpOverrides.current, isNotNull);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The assertion expect(HttpOverrides.current, isNotNull); is unrelated to the testTextInput group. Including it in the setUp block of this group couples unrelated behaviors and means that any failure in HttpOverrides initialization will incorrectly cause all testTextInput tests to fail.

It is cleaner and more maintainable to separate this check into its own independent test case.

Suggested change
group('testTextInput', () {
setUp(() {
expect(binding.testTextInput, isNotNull);
expect(binding.testTextInput.isRegistered, isFalse);
expect(HttpOverrides.current, isNotNull);
});
test('Initializes httpOverrides', () {
expect(HttpOverrides.current, isNotNull);
});
group('testTextInput', () {
setUp(() {
expect(binding.testTextInput, isNotNull);
expect(binding.testTextInput.isRegistered, isFalse);
});

@Piinks Piinks added the c: tech-debt Technical debt, code quality, testing, etc. label Jul 7, 2026
@Piinks
Piinks requested review from elliette and justinmc July 7, 2026 22:12
@ValentinVignal
ValentinVignal force-pushed the flutter-test/Fix-independant-in-binding-test branch from 3d9cd62 to c6e1f6f Compare July 9, 2026 08:53
@github-actions github-actions Bot removed the c: tech-debt Technical debt, code quality, testing, etc. label Jul 9, 2026
setUp(() {
expect(binding.testTextInput, isNotNull);
expect(binding.testTextInput.isRegistered, isFalse);
expect(HttpOverrides.current, isNotNull);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it looks like it was added to verify that httpOverrides is initialized in TestWidgetsFlutterBinding. Could we pull expect(HttpOverrides.current, isNotNull) out of the testTextInput group and into its own test case to make sure we don't lose it? Because I agree, I don't think this is the right place for it.

expect(tester.testTextInput.isRegistered, isTrue);
order += 1;
});
testWidgets('Registers testTextInput', (WidgetTester tester) async {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this matches what we already had here, but could we change the test description to "testWidgets registers testTextInput" and "test does not register testTextInput" below? I think that helps make it clearer what is being tested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elliette

Copy link
Copy Markdown
Member

Thanks for taking this on!

@ValentinVignal
ValentinVignal force-pushed the flutter-test/Fix-independant-in-binding-test branch from c6e1f6f to aa33a47 Compare July 11, 2026 02:56
@ValentinVignal
ValentinVignal requested a review from elliette July 11, 2026 03:00
@ValentinVignal
ValentinVignal force-pushed the flutter-test/Fix-independant-in-binding-test branch from aa33a47 to 9610475 Compare July 16, 2026 10:01
elliette
elliette previously approved these changes Jul 17, 2026

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with one more change! My apologies for all the confusion over HttpOverrides

expect(responded, true);
});

group('HttpOverrides', () {

@elliette elliette Jul 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the back and forth here, realizing the pre-existing test was actually checking that the AutomatedTestWidgetsFlutterBinding was registering httpOverrides. So maybe we should actually have 2 test cases for httpOverrides:

  • this current one which will be outside of the AutomatedTestWidgetsFlutterBinding and uses testWidgets (matching (commit)
  • another one inside the AutomatedTestWidgetsFlutterBinding group which uses test (matching test case in original "Initializes httpOverrides and testTextInput" case)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understood this comment fully. Do you want me to re-apply this comment? Move http overrides tests to its own file

I cannot add a test like this

 test('testWidgets does not register HttpOverrides.current', () {
    expect(HttpOverrides.current, isNull);
  });

in the current file. As soon as a test binding is instantiated (by the current or another test), HttpOverrides.current will be non-null. That's because we are working with static methods here. And those are not cleaned up/unregistered at the end of the tests.

That's why I split them into different test files in Move http overrides tests to its own file

Having said that, does that change your comment? If not, could you rephrase it to help me understand it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant we should add the following test case:

group(AutomatedTestWidgetsFlutterBinding, () {
 test('test registers HttpOverrides', () async {
   expect(HttpOverrides.current, isNotNull);
  });
    
   // more test cases...
})

Since there was a test case checking that before ("Initializes httpOverrides and testTextInput"). Does that make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand,test does not register HttpOverrides.current. TestWidgetsFlutterBinding.ensureInitialized() does it.

testWidgets registers HttpOverrides.current because it calls TestWidgetsFlutterBinding.ensureInitialized() under the hood.

So I can either:

  1. Re-apply this commit Move http overrides tests to its own file and verify test does NOT register HttpOverrides (it needs to be in its own file)
  2. Add a test like so
  test('TestWidgetsFlutterBinding.ensureInitialized Initializes httpOverrides', () async {
    TestWidgetsFlutterBinding.ensureInitialized();
    expect(HttpOverrides.current, isNotNull);

and it would ideally be in its own file too.


Which option do you prefer?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right, sorry about that! Re-applying Move http overrides tests to its own file sounds good!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I re-applied it in Move back http override tests to there own files

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM minus @elliette's comment #188963 (comment)

});
});

// The next three tests must run in order -- first using `test`, then `testWidgets`, then `test` again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a red flag for non-independent tests.

expect(HttpOverrides.current, isNull);
});

test('testWidgets does not register HttpOverrides.current', () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should be "test does not register..."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(responded, true);
});

group('HttpOverrides', () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right, sorry about that! Re-applying Move http overrides tests to its own file sounds good!

@ValentinVignal
ValentinVignal force-pushed the flutter-test/Fix-independant-in-binding-test branch from 9610475 to 677f558 Compare August 7, 2026 03:30

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! Apologies for all the back and forth

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 7, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants