颤振单元测试失败

时间:2016-12-05 07:27:23

标签: unit-testing dart flutter

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

pubspec.yaml中包含依赖项:

test: any

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

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

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.     

任何提示?

2 个答案:

答案 0 :(得分:1)

您必须使用以下依赖项才能使用flutter test

dev_dependencies:
  flutter_test:
    sdk: flutter

答案 1 :(得分:0)

您发布的实际测试看起来像是常规&#34;测试&#34;测试,而不是&#34; flutter_test&#34;测试。所以你可能只想用普通的飞镖运行它,而不是通过颤振的测试工具。

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