Cucumber Driven Web API Calculator

Post on 05-Dec-2014

120 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Presentation test and design a Web API using Cucumber, NodeJS & express. The code for this presentation can be found on Github: https://github.com/enix/cucumber-driven-calculator

Transcript

DESCRIPTIVE TESTING USING CUCUMBERsqueeze until the juice comes out…

Ernst Naezer - github.com/enix

IT’S NOT ME, IT’S YOU• a way to develop a

common language between the people in your team

• a way to test software a little bit more readable

• a way to reason about design without the technical clutter

YEAH YEAH• to promote designing

customer value

• to ensure stuff (APIs) keep working

• to include all team members in the design process

• cucumber

• some extensions

• a bit of luck

TO THE RESQUE

WHAT TO DESIGN AND TEST

Simple Calculation API that can be explored using a HAL+JSON* like syntax

*yeah, that’s just me trying to look smart

QUICK BOOT INTO NODE-JS NINJA MODE• coffee anybody?

• Express(o) please

• promises, promises always those promises

• anatomy of a cucumber

• I expect you to do better next time

• HAL: I’m sorry Dave

COFFEE ANYBODY?

var bla = function(r){

return "hello " + r ;

}

bla = (r) ->

"hello #{r}”equals

EXPRESS(O) PLEASEapp.get (req, res) -> res.send { succes: “yes it works!” }

app.options (req, res) -> res.send { succes: “yes it still works!” }

PROMISES, PROMISES ALWAYS THOSE PROMISES

ANATOMY OF A CUCUMBERFeature: Calculator API

In order to avoid silly mistakes

As a math idiot

I want to be told the sum of two numbers

!

Scenario: calculate the sum, only nicer

When I "add" the numbers 1 and 2

Then the result should equal 3

ANATOMY OF A CUCUMBERFeature: Calculator API

In order to avoid silly mistakes

As a math idiot

I want to be told the sum of two numbers

!

Scenario: calculate the sum, only nicer

When I "add" the numbers 1 and 2

Then the result should equal 3

ANATOMY OF A CUCUMBER

– http://chaijs.com/api/bdd/

expect('test').to.be.a('string'); expect([1,2,3]).to.include(2); expect(10).to.be.above(5); expect(1.5).to.be.closeTo(1, 0.5);

I EXPECT YOU TO DO BETTER NEXT TIME

HAL: I’M SORRY DAVE

DEMO TIMElet’s slice & dice

https://github.com/balanced/balanced-api/

MORE INFORMATION• code & slides

https://github.com/enix

• cucumber http://cukes.info/ https://github.com/cucumber/

• expect libraryhttp://chaijs.com/

• JSON+hal http://stateless.co/hal_specification.html

• Server code http://expressjs.com http://brunch.io/ http://livescript.net/ & http://coffeescript.org/

• Balanced APIhttps://github.com/balanced/balanced-api/

top related