So What Do Cucumbers Have To Do With Testing

Post on 12-May-2015

5,742 views 1 download

Tags:

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

transcript

CoastNerds June 2011

So What Do Cucumbers Have To Do With Testing?

Presented By Robert Dyball & Shannon Marsh

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?

Behaviour Driven Development

BDD = Behaviour Driven Development BDD

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- ...

Eric Evans: DDD – Domain Driven Design.

A User Story says:

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

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.

Given, When, Then

Ubiquitous Language:

TDD versus BDD

So what do you do with TDD

now?

BDD Tools

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/

Gherkin Syntax

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

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

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

JBehave Example

JBehave Example

JBehave Example

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

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

SpecFlow Example

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

SpecFlow Example

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

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/

JSpec Example

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

JSpec Example

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

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

“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?

Cucumber-Puppet Example

Setup the fact/s

Create the Test

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

StoryQ Example

StoryQ Example

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:

DemonstrationBDD using StoryQ

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