Unit testing 颤振单元测试:无效参数(字符串):包含无效字符

Unit testing 颤振单元测试:无效参数(字符串):包含无效字符,unit-testing,flutter,Unit Testing,Flutter,我正在尝试在flutter上对http客户机进行单元测试。在模拟http和my repository类之后: void main() { MockHttpCLient mockHttpCLient; FoursquareRepositoryImpl foursquareRepositoryImpl; setUp(() { mockHttpCLient = MockHttpCLient(); foursquareRepositoryImpl = FoursquareR

我正在尝试在flutter上对http客户机进行单元测试。在模拟http和my repository类之后:

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));
  }
@覆盖
未来getVenuesDetails(字符串venueId)异步{
等待客户(
'https://api.foursquare.com/v2/venues/$venueId?客户端id={{client_id}}和客户端密码={{{client_secret}}}&v={{v}},
标题:{
“内容类型”:“应用程序/json;字符集=utf-8”
}).超时(持续时间(秒:10));
}

但测试失败了,我得到了这个错误:

这个错误很可能是由非英语字符引起的。Dart的
json.decode
方法默认使用拉丁编码器()

在您从
vironments\u details.json
返回响应的地方,将以下标题添加到该响应中

(41; async=>http.Response(
fixture('vironments_details.json'),
200,
标题:{
HttpHeaders.contentTypeHeader:'application/json;charset=utf-8',
}
)