GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — What's the best way to generate a fake response to write unit tests? · Issue #263 · comigor/artemis
This repository was archived by the owner on Oct 2, 2024. It is now read-only.
This repository was archived by the owner on Oct 2, 2024. It is now read-only.
What's the best way to generate a fake response to write unit tests? #263Copy link Copy link Open DescriptionOften, in my code, I have something like this: Query( options: QueryOptions( document: ItemsQuery().document variables: ItemsArguments(...), ), builder: (result, { refetch, fetchMore }) { // skipping error handling etc. final data = ItemsQuery().parse(result.data); return MyWidget(data); }, ); When I want to write a test for The first one is to manually create a json and do something like: final json = [{ 'id': 'id0', 'title': 'Title 0', 'description': 'Description 0', }, { 'id': 'id1', // ... }]; final data = ItemsQuery().parse(json); await WidgetTestHelper.generateApp(tester, MyWidget(data)); expect(...); This works ok but people may make mistakes when writing the JSON. I've already seen this happening in my team. The other solution is to do something like: final json = [ (Items$Query$Item() ..id = 'id0' ..title = 'Title 0' ..description = 'Description 0').toJson() ]; final data = ItemsQuery().parse(json); //... This is slightly better because the editor will catch typos or attributes that do no exist. Items$Query$Item() ..id = 'id0' ..title = 'Title 0' ..description = 'Description 0 ..createdBy = (Items$Query$Item$CreatedBy() ..username = 'Alice' ..address = (Items$Query$Item$CreatedBy$Address() // <- this is very long // ... Do you guys have a better way of doing this? Reacted by Eranga Heshan Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |