Flutter 위젯 테스트에서 Image.network 응답을 모킹하기 위한 유틸리티 패키지입니다. 실제 HTTP 요청 없이 네트워크 이미지 로딩을 시뮬레이션할 수 있어 일관되고 신뢰할 수 있는 테스트 결과를 보장합니다. 원격 소스에서 이미지를 표시하는 UI 컴포넌트 테스트에 이상적이며, 테스트 중에 플레이스홀더 이미지 또는 사전 정의된 자산을 반환하는 간단한 방법을 제공합니다. 이 패키지는 가볍고 Flutter 테스트 프레임워크와 원활하게 통합됩니다.
사용 사례
원격 이미지를 표시하는 위젯 테스트
이미지 로딩 상태 시뮬레이션
단위 테스트에서 네트워크 호출 회피하기
이미지 자리 표시자 검증
테스트 일관성 보장
주요 기능
Image.network 응답 모킹
플레이스홀더 이미지 지원
외부 네트워크 종속성 없음
테스트 파일과의 간편한 통합
모든 플러터 플랫폼에서 작동합니다
적합한 대상
Flutter 개발자가 위젯 테스트 작성
안정적인 테스트 환경이 필요한 팀
이미지가 포함된 빈번한 UI 변경을 하는 프로젝트
테스트 자동화 엔지니어
CI/CD 파이프라인
고려 사항
생산 사용을 위한 것이 아님
테스트 파일에서 수동 설정이 필요합니다
이미지 모킹 시나리오에 한정
이미지 캐싱을 처리하지 않습니다
생산 종속성에서 제거되어야 합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Network Image Mock
A utility for providing mocked response to Image.network in Flutter widget tests.
Introduction
Since you are here you probably already know that calling Image.network results in 400
response in Flutter widget tests. The reason for this is that default HTTP client in tests
always return a 400.
So, what can we do about it? Instead of copying the whole code over and over again for mocking
the HTTP client, I created this package. It is heavily inspired by roughike/image_test_utils, however that package is not being maintained despite multiple pull requests
asking for bumping the mockito version and making the package usable again.
Installing
Null safety
This package should be installed under dev_dependencies with
dev_dependencies:network_image_mock:^2.0.1
Without null safety (deprecated)
If you have legacy unmigrated code that does not use Null safety, install under dev_dependencies with
dev_dependencies:network_image_mock:1.1.0
Example
The package is quite straightforward to use. All you have to do is include it in your test
file and wrap widget testing functions that require proper Image.network response in
mockNetworkImagesFor() function provided by this package. A full test example could look like this.
This is actually an example taken from tests for this package.
Contributing
There is not much to contribute since the package serves its purpose, however, in chance of needing to bump or adjust some version, or any other suggestion for that matter, please read CONTRIBUTING.