Comment 3 for bug 1137814

Revision history for this message
Dan Lyons (dan-lyons) wrote :

The most recent examples have been tests written for UI components (done with the MVP pattern). In general, with UI presenters, most of my use-case scenarios I test share common setup steps, and at least a few of the steps have to occur in a particular order.

As a hypothetical example, let's say I have a dialog which allows a user to manage a list of work items in a queue. Let's say I want to test a scenario where a user attempts to delete an item.

The setup required for the presenter's test must include the following:
*set up the mock queue repository to return the current list of work items
*set up the mock view to raise an event for item selection
*set up the mock view to raise an event for a button/menu click to delete the item

Those events have to occur in that particular order in any stateful implementation.

Sure, if both events pass the selected object or objects in their entirety, then order doesn't matter. In fact, the test really only needs the last event. However, depending on the objects involved and the expected use cases of the dialog, it may be prohibitively expensive to pass the full selection list for every item-centric operation.

There may be many different item-centric operations available in the dialog - delete, move up/down in the queue, viewing additional details, etc. The first two steps are going to be required for any of these operations, so doing the set-up with the action attributes would be quite useful, e.g.:

[PerformSearch(order: 1)]
[SelectItem(order: 2, index: 1)]
[ClickDelete(order: 3)]
[Test]
public void it_should_remove_the_item_when_delete_is_clicked()
{
   _repo.Received().DeleteItem(_expectedItem);
}

[PerformSearch(order: 1)]
[SelectItem(order: 2, index: 1)]
[ClickDetails(order: 3)]
[Test]
public void it_should_display_details_when_details_is_clicked()
{
   _detailView.Receved().Show(_expectedItem);
}

There could even be more complex activities thrown in which require order-specific setup. For example, the dialog may have user preferences which must be loaded before the initial search, because there is a preference for default search criteria. As such, the delete test now needs to look as follows:

[GetPreferences(order: 1)]
[PerformSearch(order: 2)]
[SelectItem(order: 3, index: 1)]
[ClickDelete(order: 4)]
[Test]
public void it_should_remove_the_item_when_delete_is_clicked()
{
   _repo.Received().DeleteItem(_expectedItem);
}