gpt4 book ai didi

unit-testing - flutter 单元测试失败

转载 作者:IT老高 更新时间:2023-10-28 12:42:09 25 4
gpt4 key购买 nike

我试图在 Flutter 中进行单元测试。

pubspec.yaml 中包含依赖项:

测试:任意

运行 flutter analyze 不会显示任何警告。

在我的项目的test文件夹下创建了一个unit_test.dart:

import 'package:test/test.dart';

void main()
{
test('this is a test', (){
expect(42, equals(42));
//expect(42,42);
});
}

运行 flutter test 显示以下错误:

➜  HelloFlutter flutter test test/unit_test.dart
00:00 +0: loading /home/tr/programs/HelloFlutter/test/unit_test.dart 00:00 +0 -1: loading /home/tr/programs/HelloFlutter/test/unit_test.dart 00:00 +0 -1: loading /home/tr/programs/HelloFlutter/test/unit_test.dart
Failed to load "/home/tr/programs/HelloFlutter/test/unit_test.dart": Failed assertion: boolean expression must not be null
package:test test
test/unit_test.dart 6:2 main
dart:async _StreamController.add
websocket_impl.dart 1111 _WebSocketImpl._WebSocketImpl._fromSocket.<fn>
dart:async _EventSinkWrapper.add
websocket_impl.dart 333 _WebSocketProtocolTransformer._messageFrameEnd
websocket_impl.dart 228 _WebSocketProtocolTransformer.add

00:00 +0 -1: Some tests failed.

有什么提示吗?

最佳答案

您发布的实际测试看起来像常规的“测试”测试,而不是“flutter_test”测试。因此,您可能只想使用常规 dart 而不是通过 Flutter 的测试工具来运行它。

我们在这些情况下给出的诊断是可怕的。正在跟踪:https://github.com/flutter/flutter/issues/6187

关于unit-testing - flutter 单元测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40969166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com