Я пытаюсь выполнить модульное тестирование http-клиента на флаттере. После смоделированного http и моего класса репозитория:
void main() {
MockHttpCLient mockHttpCLient;
FoursquareRepositoryImpl foursquareRepositoryImpl;
setUp(() {
mockHttpCLient = MockHttpCLient();
foursquareRepositoryImpl = FoursquareRepositoryImpl(client: mockHttpCLient);
});
Я запускаю этот тест:
test(
'should perform a get request on a url with application/json header',
() async {
//arrange
when(mockHttpCLient.get(any, headers: anyNamed('headers'))).thenAnswer(
(_) async => http.Response(fixture('venues_details.json'), 200));
//act
foursquareRepositoryImpl.getVenuesDetails(venueId);
//assert
verify(mockHttpCLient.get(
'https://api.foursquare.com/v2/venues/$venueId?client_id={{client_id}}&client_secret={{client_secret}}&v={{v}}',
headers: {'Content-Type': 'application/json; charset=utf-8'},
));
},
);
Это реализация foursquareRepositoryImpl.getVenuesDetails
:
@override
Future<VenuesDetails> getVenuesDetails(String venueId) async {
await client.get(
'https://api.foursquare.com/v2/venues/$venueId?client_id={{client_id}}&client_secret={{client_secret}}&v={{v}}',
headers: {
'Content-Type': 'application/json; charset=utf-8'
}).timeout(Duration(seconds: 10));
}
Но тест сбой, и я получил эту ошибку: https://paste.ubuntu.com/p/Ppy3ZhnyHB/