automated acceptance testing in plain english

16
Acceptance Testing Executable Requirements with Concordion http://www.concordion.org n. con-cord (kŏn'kôrd, kŏng –)

Upload: talios

Post on 09-May-2015

1.933 views

Category:

Technology


3 download

DESCRIPTION

Using Concordion to write automated acceptance tests

TRANSCRIPT

Page 1: Automated Acceptance Testing In Plain English

Acceptance TestingExecutable Requirements with Concordion

http://www.concordion.org

n. con-cord (kŏn'kôrd, kŏng–)

Page 2: Automated Acceptance Testing In Plain English

The tests are the spec, right?

• Source code is complicated

• Tests mix intent, implementation, and scaffold

• “the code” is meaningless to a customer

• “the code” is also meaningless to new developers

Page 3: Automated Acceptance Testing In Plain English

Requirement

When bad credentials are used to login, the response code should be 501, with a message of “Bad Password or Username”.

Page 4: Automated Acceptance Testing In Plain English

Pseudo Code test

def testLogin() { var username = “John” var password = “badpassword” var postMethod = new PostMethod(“http://localhost/login.do”) postMethod.setProperty(“username”, username) postMethod.setProperty(“password”, password) var return = new HttpClient().executeMethod(postMethod)

try { assertThat(return.responseCode).isEqualTo(501) assertThat(return.bodyText).isEqualTo(“Bad password or username.”) } finally { postMethod.releaseConnection() }}

Page 5: Automated Acceptance Testing In Plain English

So whats wrong?

• Hard coded values

• HTTP Client support code

• “the code” is meaningless to the customer

• “the code” is also meaningless to new developers (without a bit of groking)

Page 6: Automated Acceptance Testing In Plain English

ConcordionConcordion is an open source framework for Java that lets you turn a plain English description of a requirement into an automated test— an active specification.

• Developed by David Peterson in 2007

• Licensed under Apache v2.0

• Java Based

Page 7: Automated Acceptance Testing In Plain English

Identify Your Requirements?

• Abstract Parameters

• Common Actions

• Expected Results

Page 8: Automated Acceptance Testing In Plain English

Requirement

When bad credentials are used to login, the response code should be 501, with a message of “Bad Password or Username”.

Page 9: Automated Acceptance Testing In Plain English

HTML Markup

<p>When <span concordion:execute=”#credentials = getBadCredentials”>bad credentials</span> are used <span concordion:execute=”#result = tryLoginWith(#credentials)”>to login</span>, the response code should be <span concordion:assertEquals=”#result.responseCode”>501</span>, with a message of “<span concordion:assertEquals=”#result.bodyText”>Bad Password or Username</span>”.</p>

Page 10: Automated Acceptance Testing In Plain English

Pseudo Code Fixture

def getBadCredentials() = new Credentials(“John”,“badpassword”)

def tryLoginWith(cred: Credentials) = { var postMethod = new PostMethod(“http://localhost/login.do”) postMethod.setProperty(“username”, cred.username) postMethod.setProperty(“password”, cred.password) var return = new HttpClient().executeMethod(postMethod) return new Result(return.responseCode, return.bodyText);}

Page 11: Automated Acceptance Testing In Plain English

Result

When bad credentials are used to login, the response code should be 501, with a message of “Bad assword or UsernameBad Password or Username”.

Page 12: Automated Acceptance Testing In Plain English

There’s still something wrong!

• Fixture leaks state and code into specification

Page 13: Automated Acceptance Testing In Plain English

Stateless HTML Markup

<p>When <span concordion:execute=”useBadCredentials()”>bad credentials</span> are used <span concordion:execute=”tryLogin()”>to login</span>, the response code should be <span concordion:assertEquals=”getResponseCode()”>501</span>, with a message of “<span concordion:assertEquals=”getBodyText()”>Bad Password or Username</span>”.</p>

Page 14: Automated Acceptance Testing In Plain English

Stateless Pseudo Code Fixture

var cred = new Credentials(null, null)var result = new ReturnDetails(-1, “”)

def useBadCredentials() = { cred = new Credentials(“John”,“badpassword”)}

def tryLogin = { var postMethod = new PostMethod(“http://localhost/login.do”) postMethod.setProperty(“username”, cred.username) postMethod.setProperty(“password”, cred.password) var return = new HttpClient().executeMethod(postMethod)}

def getResponseCode() = result.responseCodedef getBodyText() = result.bodyText

Page 15: Automated Acceptance Testing In Plain English

Benefits

• Requirement doesn’t need to know HOW the requirement is exercised

• Implementation language could change without changing the specification.

• Pluggable specification fixtures( i.e. HTTP Client REST API and Selenium based WEB UI testing)

• Plain english requirement is easy to understand

Page 16: Automated Acceptance Testing In Plain English

More Information

• http://www.concordion.org

• http://tech.groups.yahoo.com/group/concordion/join

• http://www.talios.com

• http://www.twitter.com/talios