我试图在一个颤动小部件测试中发出一个HTTP请求,但由于某种原因,小部件测试总是在5秒后超时,而它在单元测试中完全正常。
import 'package:flutter_test/flutter_test.dart';
import 'dart:io';
import 'dart:convert';
void main() {
test('http unit-test works', () async {
var httpClient = new HttpClient();
var request = await httpClient.getUrl(Uri.parse('https://api.ipify.org/'));
var response = await request.close();
var responseBody = await response.transform(UTF8.decoder).join();
print('BODY: $responseBody');
});
testWidgets('http widget-test does not work', (WidgetTester tester) async {
var httpClient = new HttpClient();
var request = await httpClient.getUrl(Uri.parse('https://api.ipify.org/'));
var response = await request.close();
var responseBody = await response.transform(UTF8.decoder).join();
print('BODY: $responseBody');
});
}
flutter测试环境是否在这里吃掉我的HTTP请求?我怎样才能阻止它这样做呢?