Professional Documents
Culture Documents
Gerard Meszaros
Agile2012ATAS@gerardm.com
Features Money
Minimize
Maximize
Product Owner
Quality
Time
Functionality
Functionality
Initial NF
Concept
Version 1.0
Evolved
Concept NF
Version 1.x
• Type NF bugs: New Func. is wrong Version 1.0
• Type RB bugs: New bugs in old func. RB
(Regression Bugs)
Much Ado About Agile 2011 9 Copyright 2011 Gerard Meszaros
Exercise 1
• Time to test our little application
Requirements
Development
Testing
Requirements
Development
Testing
Requirements
Development
Testing
Requirements
Development
Testing
Requirements
Development
Testing
Requirements
Development
Testing
Requirements
Development
Testing
interpreted Test
Inputs
SUT
Runner
by the test Expected
runner.
Inputs
Outputs
Expected
Outputs
Test
Test Script Repository Results
Software
Design
Prevent
anticipatable Find non-
defects from anticipatable
happening Defects, ASAP!
Software
Design For effective prevention:
1. Tests must be available before
development
2. Developers must be able to run tests
before check-in
Much Ado About Agile 2011 Quadrants courtesy of Brian
28 Marrick and Mary Poppendieck
Copyright 2011 Gerard Meszaros
Reducing the Cost to Fix Defects
Cost to understand
and fix a defect goes
up with the time it
takes to discover it.
• Why?
• We can remember where we put the newly
inserted defect because
1. We know what code we were working on
2. The design of the code is still fresh in our minds
• We may have to change less code
– Because we wrote less code
Much Ado About Agile 2011 29 based on the defect
Copyright 2011 Gerard Meszaros
Continuous Acceptance Testing!
• Defines what “Done Looks Like”
– Several to many tests per User Story / Feature
30
31
• How do we eliminate
the waste caused by
building the wrong
product?
– Missed requirements?
– Misunderstood
requirements?
– Unneeded functionality?
• How do we eliminate
the waste caused by
building the wrong
product?
– Missed requirements?
– Misunderstood
requirements?
• A.K.A.
– Acceptance Test Driven Development
– Behaviour-Driven Development
– Executable Specification
– StoryTest-Driven Development
Satisfied
Examples
System
Tests
Transactions Make examples /
Detail
tests easy to
Component
Business understand and
Tests
Rules easy to write
High
Too vague
Unit Tests Unit
Tests
Broad Narrow
Much Ado About Agile 2011 Scope 39 Copyright 2011 Gerard Meszaros
Example: Mega Bank Requirements
• Notify user of transactions against their
accounts.
• User can configure threshold amount for
notification based on any/all of account,
transaction type or region, charge category
• Notification can be sent via e-mail, voice-mail
or SMS/IM
• User can suspend notifications indefinitely or
for a defined period of time.
Configure Notification
Threshold
Suspend Notification
Account
Holder
Resume Notification
Process Transaction
Transaction
Settlement
Much Ado About Agile 2011 41 Copyright 2011 Gerard Meszaros
Example:
Specifying Notification Workflow
Use Case:
Manage
Notification
Thresholds
Use Case:
Process
Transaction
Check output
of Use Case:
Broad Scope; Minimum Detail; Process
No mention of User Interface! Transaction
Much Ado About Agile 2011 42 Copyright 2011 Gerard Meszaros
Alternate form of Workflow Test:
Given Bobma has account 1003592877
And BobMa sets notification threshold to
$10,000 for all transactions
When the bank processes debit for 15,000 to
account 1003592877
And the bank processes debit for 9,000 to
account 1003592877
And the bank processes debit for 11,000 to
account 1003592877
Then bobma receives notification for debit
15,000 to account 1003592877
And bobma receives notification for debit 11,000
to account 1003592877
Much Ado About Agile 2011 43 Copyright 2011 Gerard Meszaros
Example:
Specifying Suspension Workflow
Use Case:
Manage
Notification
Thresholds
Use Case:
Process
Transaction
Use Case:
Suspend
Notification
Use Case:
Resume
Notification
Use Case:
View
Notifications
Data to be shown on
Manage Accounts Tab
Data to be shown
on Manage
Medium Detail; Medium Scope Notifications Tab
Still no mention of User Interface!
Much Ado About Agile 2011 46 Copyright 2011 Gerard Meszaros
Example:
Business Rule Specs
Threshold per Charge Type
Configuration Process Transaction
Too vague
(Rarely Happens!)
Workflow
Detail
Transactions
Business
High
• Better Approach:
–Choose automation approach to achieve goals
–Then, select tools to support it
Legacy
•GotoWindowNamed: name Business Rules X
•SelectFieldNamed: name Component X
•EnterText: text Unit X
•(Not the same as true Keyword-Driven testing) Workflow X
# Most COTS Tools operate at UI or HTTP System X
interface; many open-source tools do so as well New Component X
Business Rules X
Unit X
Much Ado About Agile 2011 52 Copyright 2011 Gerard Meszaros
Keyword-Driven Tests
• The tests are expressed in domain-specific vocabulary.
• The tests are read & executed by a test interpreter written
by techies.
definition execution
Legacy
Business Rules X
against the Raw UI, it is better to delegate Component X
to an adapter if no API is available. Unit X
Workflow X
System X
New
Component X
Business Rules x
Unit x
Much Ado About Agile 2011 54 Copyright 2011 Gerard Meszaros
Sample Keyword-Driven Test
(e.g. Cucumber, JBehave, or Fit)
SUT
Scenario Invoice Generation
Component
-New Customer Cucumber Scenario Under Test
----------------------------- Runner
Given: Logged in as Clerk
Results
And: Item1, Item2 exist
----------------------------- Document
1. CreateCustomer “Acme” CreateCustomer Interpreter
Result
2. CreateAccount NewCust
3. AddPurchase Item1
of step
4. AddPurchase Item2 AddPurchase Interpreter
5. GenerateInvoice NewAcct Result
6. …. of step
Cucumber Library
Place Yes No
Over
Order $1000
Authorise
Order
Note: Can assume an input queue exists for each role if that helps checking.
Much Ado About Agile 2011 56 Copyright 2011 Gerard Meszaros
Data-Driven Tests
• The tests are expressed as tabular data by users.
• The tests are read & executed by a test interpreter written
by techies.
definition execution
Runs the same test
script many times;
once per set of data.
Legacy
scenarios (input values and expected outputs) Business Rules X
Component X
are almost always prepared by hand. Unit X
# The inputs/outputs are per test (per row) but Workflow X
there may be global or per-run data used as System X
New
reference data by the underlying script. Component x
Business Rules x
Unit x
Much Ado About Agile 2011 58 Copyright 2011 Gerard Meszaros
Sample Data-Driven Test in FIT
PayrolFixtures.WeeklyCompensation
SUT
Standard Holiday Hourly Pay( )
Hours Hours Wage Component
40 0 10 $400 Fit Test Under Test
40 0 20 $800 Runner
41 0 20 $830 Results
Table Document
40 1 20 $840
Interpreter Marked up
Table
41 1 20 $870 Fit
Library
---Inputs--- Outputs
41 0 20 $830 Results
Table Document
40 1 20 $840 expected
Interpreter Marked up
$800 actual Table
41 1 20 $870 expected Fit
Library
$830 actual
---Inputs--- Outputs
User
• Adapters can be tacked on Interface
– Single place to adjust when UI changes
– But may be complex and error prone
66
Adapter
Much Ado About Agile 2011 Copyright 2011 Gerard Meszaros
Test - After Architecture
• Must test through User Interface
Configuration Configure
User Notification Notification
Workflow
Interface Threshold Rules
Test
Should we
Transaction Process Notify?
Interface Transaction Do
Notification.
Notification
Log
Configuration Configure
User Notification Notification
Workflow
Interface Threshold Rules
Test
Should we
Transaction Process Notify?
Interface Transaction Do
Notification.
Notification
Log
Configuration
Configuration Configure
User Notification Notification
TX Test
Interface Threshold Rules
Should we
Transaction Process Notify?
Interface Transaction Do
Notification.
Notification
Log
Configuration Configure
User Notification Notification
Interface Threshold Rules
Notification Should we
Rule Test
Transaction Process Notify?
Interface
Notification Transaction Do
Method Test Notification.
Notification
Log
GoToPage(“MaintainTaxonomy”)
SelectTerm("[A]-Top Level“)
GoToPage(“MaintainTaxonomy”)
SelectTerm("[A]-Top Level“)
Legacy
Business Rules X
between the test script and the SUT’s UI. Component X
Unit X
Workflow X
System X
New
Component X
Business Rules X
Unit X
Much Ado About Agile 2011 76 Copyright 2011 Gerard Meszaros
Built-In Record&Playback
• User executes tests manually; SUT records as tests
• Tool replays tests later without user intervention
definition
Test
The tests are Recorder
data Test
SUT
interpreted Runner
by the test Inputs Inputs
execution
runner.
Expected Actual
Outputs Expected
Outputs Results
Legacy
• Can sometimes be retrofitted to legacy systems Business Rules X
Component X
Unit X
Workflow x
Most appropriate with legacy systems System x
New
when playing “automation catch-up” Component
Business Rules
x
x
Unit x
Much Ado About Agile 2011 78 Copyright 2011 Gerard Meszaros
Sample Built-in R&PB Test Recording
2. Supply Create
Recording
<expected>
<value>DIRECTIONAL</value>
<value>WORK</value> Previously
<value>PSGR</value>
<value>PLOW</value> recorded
<value>PLOW WORK</value> choices
<value>ENG</value>
</expected>
<actual>
<value status="ok">DIRECTIONAL</value>
Playback
<value status="ok">WORK</value>
<value status="ok">ENG</value> Actual choices
<value status="ok">PSGR</value> plus
<value status="surplus">MIXED</value> test results
<value status="ok">PLOW</value>
<value status="ok">PLOW WORK</value>
</actual>
</field>
if (recording_is_on()) {
record_choice(dialog_id, choice_list,
choice, key);
}
if (recording_is_on()) {
record_choice(dialog_id, choice_list,
choice, key);
}
if (recording_is_on()) {
record_choice(dialog_id, choice_list,
choice, key);
}
Legacy
Business Rules X
• API preferred but can script browser-based Component X
(UI) tests. Unit X
• Code can be primitive or abstract therefore... Workflow X
System X
• Developers need training on writing clear
New
Component X
tests! Business Rules X
Unit X
Much Ado About Agile 2011 84 Copyright 2011 Gerard Meszaros
Changing the Role of Testing
Report
Requirements Card
Define Product Critique Product Functionality B
Usability C
Business Acceptance Tests Usability Tests Scalability A
Response B
Facing Regression Tests Exploratory Tests Availability C
Software
Design For effective prevention:
1. Tests must be available before
development
2. Developers must be able to run tests
before check-in
Much Ado About Agile 2011 Thanks to Brian Marrick
85 and Mary Poppendieck Copyright 2011 Gerard Meszaros
Preventing Coding Defects
(Building the Product Right)
Prevent defects in
new code
Much Ado About Agile 2011 88 Copyright 2011 Gerard Meszaros
Hand-Coded Test – w/ Primitive Obsession
public void testAddItemQuantity_severalQuantity () {
// Setup Fixture
final int QUANTITY = 5;
Address billingAddress = new Address("1222 1st St SW", "Calgary",
"Alberta", "T2N 2V2", "Canada");
Address shippingAddress = new Address("1333 1st St SW", "Calgary",
"Alberta", "T2N 2V2", "Canada");
Customer customer = new Customer(99, "John", "Doe", new
BigDecimal("30"), billingAddress, shippingAddress);
Product product = new Product(88, "SomeWidget", new
BigDecimal("19.99"));
Invoice invoice = new Invoice(customer);
// Exercise SUT
invoice.addItemQuantity(product, QUANTITY);
// Verify Outcome
List lineItems = invoice.getLineItems();
if (lineItems.size() == 1) {
LineItem actualLineItem = (LineItem)lineItems.get(0);
assertEquals(invoice, actualLineItem.getInvoice());
assertEquals(product, actualLineItem.getProduct());
assertEquals(quantity, actualLineItem.getQuantity());
assertEquals(new BigDecimal("30"),
actualLineItem.getPercentDiscount());
assertEquals(new BigDecimal("19.99"),
actualLineItem.getUnitPrice());
assertEquals(new BigDecimal(“69.96"),
actualLineItem.getExtendedPrice());
} else {
assertTrue(“Invoice should have
Much Ado About Agile 2011 89
exactly one line item“, false);
Copyright 2011 Gerard Meszaros
}
}
Hand-Coded Test – Appropriately Abstracted
public void testAddItemQuantity_severalQuantity () {
// Exercise SUT
invoice.addItemQuantity(product, QUANTITY);
// Verify
LineItem expectedLineItem = newLineItem( invoice,
product, QUANTITY, product.getPrice()*QUANTITY );
Much Ado About Agile 2011 100 Copyright 2011 Gerard Meszaros
Collaborative Automation based on ROI
A.K.A. Pragmatic Approach
Summary:
–Goal: Just Enough Automation
–Apply Agile Principles to Implementation of
Automation
Issues:
– Won’t Have Complete Test Coverage
– Can Lead to Automation Being Dropped in
Favour of More Functionality
– Requires a Disciplined Product Owner, or,
– A Fixed Budget for the Automation
Much Ado About Agile 2011 101 Copyright 2011 Gerard Meszaros
What if Automation is Really Hard?
• Apply the 80/20 rule Story
Example
User Make Concrete
Goal Add Data Formalization
Story Automation
• Define the tests first Scenarios
• Automation is Define Executable
Acceptance Example
optional Criteria
Feature
Story
Narrative Product
Development
Story
Title Satisfied
Significant Value in Providing Example
Slides:
http://Agile2011ATAS.xunitpatterns.comJolt Productivity Award
winner - Technical Books
Call me when you:
• Want to transition to Agile or Lean Coming Soon:
• Want to do Agile or Lean better
• Want to teach developers how to test
• Need help with test automation strategy
• Want to improve your test automation
Much Ado About Agile 2011 104 Copyright 2011 Gerard Meszaros
References
• For Success, Build Record/Playback into Your
Application - StarEast 2008 Class
– http://strategy.testAutomationPatterns.com
Much Ado About Agile 2011 105 Copyright 2011 Gerard Meszaros