在我的代码中,我有一个名为
lookup
的方法:
lookup.dart
Future<http.Response> httpLookup(String address) {
return kIsWeb
? _httpClient.get(address)
: _httpClient.get(
Uri.https(address, ''),
);
}
我如何在单元测试中测试kIsWeb
常量?以下是我尝试过的内容,但代码覆盖率不够。
lookup_test.dart
@TestOn('browser')
void main (){
test('shoud test lookup', () {
InternetLookup lookup = InternetLookup();
when(mockInternetLookup.httpLookup(any))
.thenAnswer((realInvocation) async => http.Response('success', 200));
lookup.httpLookup('www.google.com');
});
}