Flutter unit test failed

I was trying to do a unit test in Flutter.

In pubspec.yaml the dependency is included:

test: any

Running flutter analyze shows no warnings.

Created a unit_test.dart under test folder in my project:

import 'package:test/test.dart';

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


Running flutter test shows me the following error:

➜ 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.


Any hint?

You have to use the following dependency to use flutter test :

dev_dependencies:
flutter_test:
sdk: flutter


The actual test you posted looks like a regular "test" test, as opposed to a "flutter_test" test. So you probably just want to run it using regular dart rather than via flutter's test harness.

The diagnostics we give in these situations are horrific. That's being tracked at: https://github.com/flutter/flutter/issues/6187

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue