Test Persona is a software pattern for acceptance tests. The use of this pattern leads to a de-coupling of test motivation from test implementation. Using test personas in acceptance tests is part of building a rich test domain. This pattern is complementary to other patterns that focus on the test domain, such as the page object pattern.
A test persona has knowledge of the actions and information available to a particular actor in a system under test. Acceptance tests interact with the test persons to accomplish activities that would normally be performed
Here is a typical gherkin acceptance test
Given I am a customer When I am about to purchase an item that can be sourced in my country Then the cheapest price should include 'free delivery' as a delivery option
Most natural language based test harnesses will require a developer to implement a mapping into structured code. For instance, using page objects and some implicit web steps
/I am a customer/ visit CustomerHomePage
/I am about to purchase an item that can be sourced in my country/ @item = find_item :stock_location => 'australia' visit url_for item :action => :purchase
/I should see 'free delivery' as an available delivery option/ on_page(PurchasePage).delivery_options. should.contain :text => 'free delivery'
Once the persona pattern is applied, we see that the actual user is more explicit, but interactions with data are less so.
before_scenario do attr i Alias_method me, my, :i
/I am a customer/ me= create_customer
/I am about to purchase an item that can be sourced from my country/ my.desired_item = find_item :stock_location => my.location i.start_to_purchase_item
/I should see 'free delivery' as an available delivery option/ my.purchase_page.delivery_options. should contain :text => 'free delivery'
In this refactored example, the persona (returned using
create_customer) holds many of the methods that were previously implicit in the world class.
In my next post, I’ll discuss some of the patterns of use in persona-focussed acceptance testing