我正在尝试从颤振小部件测试中发出 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 请求?我怎样才能防止它这样做?