Flutter unit test failed
2,667
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
Author by
TaylorR
I am in China, often blocked by GFW. But I long for free talks and free thoughts! Develop with PHP, MySQL, Vue.js, dart. Learning Flutter, Dart now.
Updated on December 01, 2022Comments
-
TaylorR over 1 year
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
undertest
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?
-
TaylorR over 7 yearsTried the above method, when running
flutter packages get
, it gets these errors:Incompatible dependencies on flutter... pub get failed
-
Alexandre Ardhuin over 7 yearsIt works on my project. Could you post your pubspec.yaml ?
-
Günter Zöchbauer over 7 yearsI also tried it in my flutter project and this fixed it for me.
-
TaylorR over 7 yearsThe
pubspec.yaml
is the default one created byflutter create
. Added the lines above per Alex's input only. -
Alexandre Ardhuin over 7 yearsReally strange because I did
flutter create
, created a filetest/my_test.dart
with your test content and ranflutter test
to see the same error you faced. After putting only the dependency mention in my answer the error went away and the test was run. -
TaylorR over 7 yearsLet me try later today and revert.
-
Ian Hickson over 7 yearsOh man, that explains why I keep seeing people do
expects(42, 42)
! -
TaylorR over 7 yearsTried again today and seems working with Alex's method.