The document introduces acceptance test driven development (ATDD) and behavior driven development (BDD). It discusses how ATDD/BDD tools work using specifications, fixtures/steps, and frameworks. Common challenges around what to test and accessing systems under test are addressed. Finally, the document outlines strategies for dependencies, non-code verifiable resources, and reducing testing time.
How to Troubleshoot Apps for the Modern Connected Worker
Agile Days Twin Cities 2011
1. Introduction and Strategies
for Effective ATDD
Agile Day – Twin Cities
Nov 11, 2011
Brian Repko
brian.repko@learnthinkcode.com
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
2. Agenda
●
Introduction to ATDD
●
What it is
●
How it works
●
Tools
●
Agile and ATDD
●
Three Challenges / Strategies
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
3. Introduction to ATDD/BDD
●
Acceptance Test Driven Development
●
Pioneered with FIT/Fitnesse
●
System or Solution (multi-system)
●
Readable and Executable Specifications
●
Requires “Fixture” code
●
Behavior Driven Development
●
Introduced by Dan North (2003)
●
Early on, referred to as “TDD done well”
●
Business language / Given-When-Then
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
4. How ATDD/BDD Tools Work
●
Typically 4 pieces
●
A system to test!
●
An ATDD/BDD framework/tool
●
Specifications/stories/tests (text/html)
●
Fixtures/steps (code)
●
Accessible to the framework
●
Manipulates/verifies the system to test
●
Framework parses the story, calls methods in the
steps code which manipulates/verifies the system
●
Most tools use regex matching to connect story text
to steps methods and support befores/afters
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
5. An example
Scenario: Authentication within the @Given("an organization named $orgNames")
timeframe
@Alias("organizations named $orgNames")
Given an organization named Cisco
public void
createOrganizationWithName(List<String>
And authentication policy for Cisco: orgNames) {
|passwordAutoExpire|passwordExpiryDays| ...
|true|30| }
And the users for Cisco:
|username|passwordCleartext| @Given("authentication policy for $orgName:
$authPolicyTable")
lastPasswordResetDate|
public void
|lenbosack|password|t-15| updateOrganizationWithDefaultAuthPolicy(String
orgName, ExamplesTable table) {
|sandylerner|password|t-45|
…
When current organization is Cisco
}
And user lenbosack authenticates with
password password
Then user should be authenticated
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
6. Common Challenges
●
What to test – Unit vs System Testing
●
Unit/Mock for exception handling
●
Unit Testing – fast feedback
●
System Testing – full functionality
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
7. Common Challenges
●
How to Setup, Access and Verify the SUT
●
Access different from Setup/Verify
●
Need the System to support configuration
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
8. ATDD/BDD Testing Tools
●
Open Source Frameworks/Tools
●
FIT, Cucumber (ruby), JBehave (java), Lettuce (python),
Behat (php), Spock (groovy), SpecFlow (.NET), EasyB
(groovy), Concordian (java), *Spec, Thucydides
●
Gherkin language for specifications
●
Cucumber, Lettuce, SpecFlow, Behat - JBehave is close
●
Integration (invoking) Technologies
●
Browser – Selenium, Wati*, iMacros, WebAii
●
Java UI – UISpec4J, java.awt.Robot
●
Web Services – curl, Jersey, CXF, SoapUI, HTTP Client
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
9. ATDD/BDD Testing Tools
●
Resource / System Stubs
●
In-Memory, Lightweight Databases
●
H2, HSQLDB, OracleXE
●
DbUnit, DbFIT (setup and verify)
●
Messaging - ActiveMQ
●
SMTP – DevNull
●
System Stubs
●
Custom / Groovy-Grails
●
Environments
●
SauceLabs
●
Puppet / Chef / Vagrant
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
10. Agile and ATDD
●
Defines (and Proves!) “Done“
●
Understood by everyone
●
Serves as documentation
●
Test-first as part of story prep
●
Add the specification but its not “on”
●
Can run it without steps – PENDING
●
System and solution (multi-system)
●
Test a configured system or set of systems
●
Part of Continuous Deployment pipeline
●
Define stage gates in your pipeline
●
Do varying types / amounts of tests
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
11. Challenges / Strategies (1)
●
My system depends on another system
●
Just call it
●
Can you reuse step classes?
●
Just stub it out
●
Can you setup a mock in your system?
●
Can you stub out the system?
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
12. Challenges / Strategies (2)
●
I have a resource (printed receipt) that I
can't verify with code
●
Take the API that access the resource
●
Write/Create a “delegating wrapper”
●
The wrapper will record all method calls
●
Connect with the wrapper to verify
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
13. Challenges / Strategies (3)
●
Testing everything takes too much time
●
Run the same story with different steps
●
Step classes that drive the UI (slow)
●
Step classes that run in the JVM / services
●
80/20 rule (change vs nightly)
●
Fail-Fast strategy
●
Parallelization
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
14. References
●
Gojko Adzic
●
“Bridging the Communication Gap”
●
“Specification by Example”
●
FIT - http://fit.c2.com
●
Fitnesse - http://fitnesse.org
●
Cucumber - http://cukes.info
●
JBehave – http://jbehave.org
●
SpecFlow - http://specflow.org/
●
Spock - http://code.google.com/p/spock/
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
15. Q/A – Thank You!
Copyright 2011 LearnThinkCode, Inc.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License