单元测试 – 颤振单元测试失败

我试图在Flutter进行单元测试.

在pubspec.yaml中包含依赖项:

测试:任何

运行颤振分析显示没有警告.

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

import 'package:test/test.dart';

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

运行颤振测试显示以下错误:

➜  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测试:

dev_dependencies:
  flutter_test:
    sdk: flutter
点赞