flutter_cache_manager icon indicating copy to clipboard operation
flutter_cache_manager copied to clipboard

Would be awesome to have a Widget Testing recipe in the readme!

Open mattalbr opened this issue 1 year ago • 1 comments

💬 Questions and Help

I was trying to follow on old medium article linked in a stack overflow question to figure out how to write a widget test for a component that relies on CacheManager.

Unfortunately, it seems like a new version significantly changed the API and the recipe provided there is all kinds of broken. I wonder if it would be possible for someone to link from the readme a recipe for how to write such a test (possibly by implementing https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/example/test/widget_test.dart and linking to it?)

mattalbr avatar Aug 15 '24 13:08 mattalbr

Same here.

There's no mention anywhere in this repo or in cached_network_image about how to test widgets that use them.

My guess is that, as the 5 years old Medium article suggests, there needs to be some kind of TestCacheManager passed down to cached_network_image during testing. I don't mind giving a go at implementing it and sending a PR, but I'd appreciate some guidance. As of [email protected] an implementation of BaseCacheManager requires implementing 11 methods.

For the record, the warning and error thrown during testing (Flutter 3.29.1):

Warning: At least one test in this suite creates an HttpClient. When running a test suite that uses
TestWidgetsFlutterBinding, all HTTP requests will return status code 400, and no network request
will actually be made. Any test expecting a real network connection and status code will fail.
To test code that needs an HttpClient, provide your own HttpClient implementation to the code under
test, so that your test can consistently provide a testable response to the code under test.
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following MissingPluginException was thrown running a test (but after the test had completed):
MissingPluginException(No implementation found for method getApplicationSupportDirectory on channel
plugins.flutter.io/path_provider)

juandelgado avatar Mar 12 '25 20:03 juandelgado