When writing unit tests I need some objects with sample data. For example suppose I have an Order object. One needs to write code like this -
Order o = new Order();
o.setId(3);
o.setAmount(2830.9);
List<Item> items = new ArrayList<Item>();
Item i = new Item();
i.setId(3);
i.setCost(34);
items.add(i);
o.setItems(items);
It is a lot more frustrating and redundant than it looks here because a real object is likely to have lot more attributes and nested objects.
And if one needs multiple orders ...
What is the best way to create mock data objects for testing?
Off the top of my head I'm thinking about deserializing my objects from Json. Is there a standard, efficient way to do this?