You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
When I want to write a test for MyWidget, I need to generate data to pass as an input. I can think of several solutions:
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);
awaitWidgetTestHelper.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.
But it gets really tedious when there are nested object in the response.
Ex:
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?
The text was updated successfully, but these errors were encountered:
In my work, for unit tests, we're doing your second example. Although kinda boring to write, it is surely safer than the first option.
One of the teams is working on a code generator solution to mock those classes generated by Artemis, though. I'll reach them to see if they plan to ship it as opensource.
Often, in my code, I have something like this:
When I want to write a test for
MyWidget
, I need to generate data to pass as an input. I can think of several solutions:The first one is to manually create a json and do something like:
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:
This is slightly better because the editor will catch typos or attributes that do no exist.
But it gets really tedious when there are nested object in the response.
Ex:
Do you guys have a better way of doing this?
The text was updated successfully, but these errors were encountered: