Posts

Showing posts with the label unit-testing

How can I assert hasProperty with a Java Record?

11 3 I have a piece of code in a test that checks that a list of results contains certain properties, using Hamcrest 2.2: assertThat(result.getUsers(), hasItem( hasProperty("name", equalTo(user1.getName())) )); assertThat(result.getUsers(), hasItem( hasProperty("name", equalTo(user2.getName())) )); This worked perfectly fine when NameDto was a normal class. But after I changed it to a Record , Hamcrest's hasProperty complains about there being no property named name : java.lang.AssertionError: Expected: a collection containing hasProperty("name", "Test Name") but: mismatches were: [No property "name", No property "name"] Is there some other matcher I can use to achieve the same matching a...

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