Repository navigation
Fix non-independant tests in binding_test.dart - #188963
auto-submit[bot] merged 4 commits into
Conversation
| setUp(() { | ||
| expect(binding.testTextInput, isNotNull); | ||
| expect(binding.testTextInput.isRegistered, isFalse); | ||
| expect(HttpOverrides.current, isNotNull); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
flutter/packages/flutter_test/lib/src/_binding_io.dart
Lines 25 to 28 in f9cc6b0
So I had to split the tests into 2 files:
packages/flutter_test/test/http_overrides/test_test.dartpackages/flutter_test/test/http_overrides/test_widgets_test.dart
Let me know what you think about it
There was a problem hiding this comment.
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);
});
});
There was a problem hiding this comment.
Noted, I moved it back in Move back test in bindings_test.dart :)
There was a problem hiding this comment.
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.
| group('testTextInput', () { | ||
| setUp(() { | ||
| expect(binding.testTextInput, isNotNull); | ||
| expect(binding.testTextInput.isRegistered, isFalse); | ||
| expect(HttpOverrides.current, isNotNull); | ||
| }); |
There was a problem hiding this comment.
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.
| 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); | |
| }); |
3d9cd62 to
c6e1f6f
Compare
| setUp(() { | ||
| expect(binding.testTextInput, isNotNull); | ||
| expect(binding.testTextInput.isRegistered, isFalse); | ||
| expect(HttpOverrides.current, isNotNull); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Sure, I changed it in Move http overrides tests to its own file :)
|
Thanks for taking this on! |
c6e1f6f to
aa33a47
Compare
aa33a47 to
9610475
Compare
elliette
left a comment
There was a problem hiding this comment.
Looks good with one more change! My apologies for all the confusion over HttpOverrides
| expect(responded, true); | ||
| }); | ||
|
|
||
| group('HttpOverrides', () { |
There was a problem hiding this comment.
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
AutomatedTestWidgetsFlutterBindingand usestestWidgets(matching (commit) - another one inside the
AutomatedTestWidgetsFlutterBindinggroup which usestest(matching test case in original "Initializes httpOverrides and testTextInput" case)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- Re-apply this commit Move http overrides tests to its own file and verify
testdoes NOT registerHttpOverrides(it needs to be in its own file) - 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?
There was a problem hiding this comment.
Ah you're right, sorry about that! Re-applying Move http overrides tests to its own file sounds good!
There was a problem hiding this comment.
No worries, I re-applied it in Move back http override tests to there own files
justinmc
left a comment
There was a problem hiding this comment.
LGTM minus @elliette's comment #188963 (comment)
| }); | ||
| }); | ||
|
|
||
| // The next three tests must run in order -- first using `test`, then `testWidgets`, then `test` again. |
There was a problem hiding this comment.
Definitely a red flag for non-independent tests.
| expect(HttpOverrides.current, isNull); | ||
| }); | ||
|
|
||
| test('testWidgets does not register HttpOverrides.current', () { |
There was a problem hiding this comment.
nit: this should be "test does not register..."
There was a problem hiding this comment.
Good catch, I fixed it in Move back http override tests to there own files
| expect(responded, true); | ||
| }); | ||
|
|
||
| group('HttpOverrides', () { |
There was a problem hiding this comment.
Ah you're right, sorry about that! Re-applying Move http overrides tests to its own file sounds good!
9610475 to
677f558
Compare
elliette
left a comment
There was a problem hiding this comment.
LGTM, thank you! Apologies for all the back and forth
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-assistbot 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.