-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be clearer about when and why we override HttpClient in tests #49844
Conversation
@override | ||
HttpClient createHttpClient(SecurityContext _) { | ||
if (!warningPrinted) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would output the message for any widget test which incidentally built a network image. It doesn't seem desirable if their test was otherwise working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to just do this on a test failure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could try to use test_package.printOnFailure, but I'm not sure how to test that anymore - hah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can put it in a new test file and run it under a harness that asserts the test fails and greps the message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - now it should only print the warning if a test fails and the HttpClient was created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if LG to everyone else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
The bot fell asleep on the job! |
Description
Outside of browser contexts, we override the HttpClient implementation to one that always returns 400 - this helps make tests more hermetic and prevent users from making mistakes in tests by introduce real life network calls into a unit test.
This can be confusing for users, particularly if they're mixing both
testWidgets
andtest
tests in the same suite, and it's unclear that the binding has taken over the whole suite. This adds new functionality to print out a warning message if a failing test has created our special HttpClient, and updates docs on the TestFlutterWidgetsBinding class.Related Issues
fixes #35318
Tests
I added the following tests:
Test that checks that we print out the message, and that we only do it once per suite.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.