34
CoastNerds June 2011 So What Do Cucumbers Have To Do With Testing? Presented By Robert Dyball & Shannon Marsh

So What Do Cucumbers Have To Do With Testing

  • Upload
    sjmarsh

  • View
    5.743

  • Download
    1

Embed Size (px)

DESCRIPTION

All about Behaviour Driven Development (BDD) and some oddly named tools you can use to make it work.Presented by Robert Dyball and Shannon Marsh

Citation preview

Page 1: So What Do Cucumbers Have To Do With Testing

CoastNerds June 2011

So What Do Cucumbers Have To Do With Testing?

Presented By Robert Dyball & Shannon Marsh

Page 2: So What Do Cucumbers Have To Do With Testing

Behaviour Driven Development (BDD) BDD Tools StoryQ Demonstration How we use BDD & StoryQ in our Process

CoastNerds Retrospective

What are we going to talk

about?

Page 3: So What Do Cucumbers Have To Do With Testing
Page 4: So What Do Cucumbers Have To Do With Testing

Behaviour Driven Development

Page 5: So What Do Cucumbers Have To Do With Testing

BDD = Behaviour Driven Development BDD

Page 6: So What Do Cucumbers Have To Do With Testing

so a test case that looks like this:

public class CustomerLookupTest extends TestCase{

testFindsCustomerById(){

...}

testFailsForDuplicateCustomers(){

...}...

}

rendered to something like this:

CustomerLookup- finds customer by id- fails for duplicate customers- ...

Page 7: So What Do Cucumbers Have To Do With Testing

Eric Evans: DDD – Domain Driven Design.

Page 8: So What Do Cucumbers Have To Do With Testing

A User Story says:

As a [X] I want [Y] so that [Z]

Page 9: So What Do Cucumbers Have To Do With Testing

A User Story says:

As a [X] I want [Y] so that [Z]

BDD says:

Given some initial context (the givens), When an event occurs, then ensure some outcomes.

Page 10: So What Do Cucumbers Have To Do With Testing

Given, When, Then

Ubiquitous Language:

Page 11: So What Do Cucumbers Have To Do With Testing

TDD versus BDD

So what do you do with TDD

now?

Page 12: So What Do Cucumbers Have To Do With Testing

BDD Tools

Page 13: So What Do Cucumbers Have To Do With Testing

Cucumber is Aslak Hellesøy’s rewrite of RSpec’s “Story runner”, which was originally written by Dan North.

Is a Ruby tool but can be used with Java, .Net, Flex (Adobe) or web based applications in written in any language.

Tests are written in plain text using the Gherkin syntax.

Cucumber only requires minimal use of Ruby programming.

Cucumber

Ref: http://cukes.info/

Ref: https://github.com/cucumber/cucumber/wiki/

Page 14: So What Do Cucumbers Have To Do With Testing

Gherkin Syntax

Ref: https://github.com/cucumber/cucumber/wiki/Gherkin

Page 15: So What Do Cucumbers Have To Do With Testing

Cucumber Example

More Examples:http://blog.adyax.com/2009/03/ruby-cucumber/http://blog.spritecloud.com/2010/03/web-testing-with-cucumber/https://github.com/cucumber/cucumber/tree/master/examples/i18n

Page 16: So What Do Cucumbers Have To Do With Testing

Java based tool for BDD created by Dan North, et al.

Uses plain text “Gherkin” syntax

Java programming required

Maps to Java based test using annotations

Can integrate into a number of Java testing frameworks including JUnit.

JBehave

Ref: http://jbehave.org/reference/stable/index.html

Page 17: So What Do Cucumbers Have To Do With Testing

JBehave Example

Page 18: So What Do Cucumbers Have To Do With Testing

JBehave Example

Page 19: So What Do Cucumbers Have To Do With Testing

JBehave Example

Ref: http://jbehave.org/reference/stable/index.html

Page 20: So What Do Cucumbers Have To Do With Testing

BDD testing framework for .Net

Configurable to work with NUnit, MSTest, XUnit.

Scenarios (specs) are defined in Gherkin syntax in a separate file.

SpecFlow takes the scenarios and turns them into code stubs for tests to be created. (via command line utility)

Scenarios can be data driven using a <placeholder> syntax.

Provides HTML report with summary of all tests as well as details of each scenario.

SpecFlow

Ref: http://www.specflow.org/home.aspx

Page 21: So What Do Cucumbers Have To Do With Testing

SpecFlow Example

Ref: http://www.codeproject.com/KB/architecture/BddWithSpecFlow.aspx

Page 22: So What Do Cucumbers Have To Do With Testing

SpecFlow Example

Ref: http://www.specflow.org/home.aspx

Page 23: So What Do Cucumbers Have To Do With Testing

BDD for JavaScript

“JSpec is a extremely small, yet very powerful testing framework”

Uses its own custom grammar and pre-processor (ie. Not Gherkin).

Eg. Before_each, describe, it, should_have, end.

Check-out the screen cast for a great demo of how it works and how to setup your tests http://content.screencast.com/users/tjholowaychuk/folders/Jing/media/816a8baa-0175-491a-a138-c889fff99f2d/00000077.swf

JSpec

Ref: http://visionmedia.github.com/jspec/

Page 24: So What Do Cucumbers Have To Do With Testing

JSpec Example

Ref: http://visionmedia.github.com/jspec/

Page 25: So What Do Cucumbers Have To Do With Testing

JSpec Example

Ref: http://visionmedia.github.com/jspec/

Page 26: So What Do Cucumbers Have To Do With Testing

Puppet is an enterprise system management platform.

Allows you automate system management activities through code.

Cucumber-Puppet has been developed to enable BDD for Puppet.

Similarly Chef is an open-source system integration framework for automating the cloud.

Cucumber-Puppet is a library of tools to enable TDD with Chef and lends it self to BDD.

BDD for System Administrators

Ref:

http://www.cucumber-chef.org/

http://blog.nistu.de/cucumber_puppet_0_0_3_released.html

https://github.com/jtimberman/chef-bdd

http://projects.puppetlabs.com/projects/cucumber-puppet

Page 27: So What Do Cucumbers Have To Do With Testing

“Cucumber-chef begins with a very simple premise. If we are framing our infrastructure as code - if we’re writing cookbooks, recipes and other pieces of automation in a high level programming language, such as Ruby, then it makes sense to follow the current wisdom across the software development world to maximise the quality, maintainability and reusability of our code, providing maximum chance that we’ll deliver value with it….”

Ref: http://www.cucumber-chef.org/

Why use BDD for System

Administration?

Page 28: So What Do Cucumbers Have To Do With Testing

Cucumber-Puppet Example

Setup the fact/s

Create the Test

Page 29: So What Do Cucumbers Have To Do With Testing

StoryQ is a portable (single dll), embedded BDD framework for .NET 3.5

It runs within your existing test runner and helps produce human-friendly test output (html or text).

StoryQ's fluent interface adds strong typing, intellisense and documentation to your BDD grammar.

Report in plain text, test results or formated XML

C# coding required.

Featured in tonight’s Demo

StoryQ

Ref: http://storyq.codeplex.com/

http://storyq.codeplex.com/wikipage?title=write%20your%20first%20StoryQ%20testhttp://www.codeproject.com/KB/testing/bddintro.aspx

Page 30: So What Do Cucumbers Have To Do With Testing

StoryQ Example

Page 31: So What Do Cucumbers Have To Do With Testing

StoryQ Example

Page 32: So What Do Cucumbers Have To Do With Testing

RSpec – Ruby - http://rspec.info/

CSpec – C - https://github.com/arnaudbrejeon/cspec/wiki

easyb – Java - http://easyb.org/

storEvil – C# - https://github.com/davidmfoley/storevil/wiki/Why-StorEvil

behat – PHP - http://behat.org/

Kiwi – Apple Objective C - http://www.kiwi-lib.info/

Lettuce – Python - http://packages.python.org/lettuce/tutorial/simple.html

Others…

Ref:

Page 33: So What Do Cucumbers Have To Do With Testing

DemonstrationBDD using StoryQ

Page 34: So What Do Cucumbers Have To Do With Testing

Discussion: how we use BDD and StoryQ in our process BDD in use