我已经浏览了一段时间,一切都很好。
但是我在为flutter_web组件创建单元测试(例如StatelessWidget测试)时遇到了问题。
我发现有一个名为flutter_web_test的软件包,但似乎工作不正常。
测试代码如下:
我已经安装了flutter_web演示项目使用的测试包:flutter_web_test
// import fluter
import 'package:flutter_web_test/flutter_web_test.dart';
// a stateless widget is imported
import 'package:ies2.pms/views/main.dart';
void main() {
testWidgets(
'test whether ',
(WidgetTester tester) async {
// very simple code, create widget in test
await tester.pumpWidget(CYFCustomView(name: 'aaa'));
print('aaa');
},
);
}
然后我开始使用flutter test
然后我收到以下错误:
Failed to load test harness. Are you missing a dependency on flutter_test?
00:05 +0: loading /Users/yifan.chen/ByteDanceIES/pms/test/main_test.dart Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Aflutter_test%2Fflutter_test.dart; message=StandardFileSystem only supports file:* and
data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1 asFileUri (package:vm/kernel_front_end.dart:601:37)
<asynchronous suspension>
#2 FrontendCompiler._outputDependenciesDelta (package:vm/frontend_server.dart:401:39)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:vm/frontend_server.dart:375:13)
<asynchronous suspension>
#4 _FlutterFrontendCompiler.compile (package:frontend_server/server.dart:31:22)
<asynchronous suspension>
#5 listenAndCompile.<anonymous closure> (package:vm/frontend_server.dart:736:26)
<asynchronous suspension>
#6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#8 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#9 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#10 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#11 _StringAdapterSink.add (dart:convert/string_conversion.dart:236:11)
#12 _LineSplitterSink._addLines (dart:convert/line_splitter.dart:150:13)
#13 _LineSplitterSink.addSlice (dart:convert/line_splitter.dart:125:5)
#14 StringConversionSinkMixin.add (dart:convert/string_conversion.dart:163:5)
#15 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#16 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#17 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#18 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#19 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#20 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#21 _StringAdapterSink.add (dart:convert/string_conversion.dart:236:11)
#22 _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:241:7)
#23 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:312:20)
#24 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:305:5)
#25 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
#26 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#27 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#28 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#29 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#30 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#31 _StreamController._add (dart:async/stream_controller.dart:640:7)
#32 _StreamController.add (dart:async/stream_controller.dart:586:5)
#33 _Socket._onData (dart:io-patch/socket_patch.dart:1786:41)
#34 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#35 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#36 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#37 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#38 _StreamController._add (dart:async/stream_controller.dart:640:7)
#39 _StreamController.add (dart:async/stream_controller.dart:586:5)
#40 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1335:33)
#41 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:856:14)
#42 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#43 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#44 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#45 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
00:05 +0 -1: loading /Users/yifan.chen/ByteDanceIES/pms/test/main_test.dart [E]
我在Stackoverflow中找不到任何解决方案。而且flutter_web当前尚未公开问题。我只在flutter中发现了一个问题,说flutter_web项目不支持flutter测试。
如何在flutter_web项目上运行单元测试?他们已经构建了flutter_web_test软件包,因此应该可以使用。
答案 0 :(得分:1)
您应将Flutter移至1.9,将flutter_web弃用https://flutter.dev/web,较短的方法是将flutter更新为1.9,创建一个新的新项目并在其上激活Web:flutter run -d chrome
现在,您可以使用{ {1}}。我希望它能解决您的问题。