Top Banner
DESCRIPTIVE TESTING USING CUCUMBER squeeze until the juice comes out… Ernst Naezer - github.com/enix
20

Cucumber Driven Web API Calculator

Dec 05, 2014

Download

Software

ernstnaezer

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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cucumber Driven Web API Calculator

DESCRIPTIVE TESTING USING CUCUMBERsqueeze until the juice comes out…

Ernst Naezer - github.com/enix

Page 2: Cucumber Driven Web API Calculator

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

Page 3: Cucumber Driven Web API Calculator

YEAH YEAH• to promote designing

customer value

• to ensure stuff (APIs) keep working

• to include all team members in the design process

Page 4: Cucumber Driven Web API Calculator

• cucumber

• some extensions

• a bit of luck

TO THE RESQUE

Page 5: Cucumber Driven Web API Calculator

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

Page 6: Cucumber Driven Web API Calculator

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

Page 7: Cucumber Driven Web API Calculator

COFFEE ANYBODY?

var bla = function(r){

return "hello " + r ;

}

bla = (r) ->

"hello #{r}”equals

Page 8: Cucumber Driven Web API Calculator

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

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

Page 9: Cucumber Driven Web API Calculator

PROMISES, PROMISES ALWAYS THOSE PROMISES

Page 10: Cucumber Driven Web API Calculator

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

Page 11: Cucumber Driven Web API Calculator

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

Page 12: Cucumber Driven Web API Calculator

ANATOMY OF A CUCUMBER

Page 13: Cucumber Driven Web API Calculator

– 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

Page 14: Cucumber Driven Web API Calculator

HAL: I’M SORRY DAVE

Page 15: Cucumber Driven Web API Calculator

DEMO TIMElet’s slice & dice

Page 16: Cucumber Driven Web API Calculator
Page 17: Cucumber Driven Web API Calculator
Page 18: Cucumber Driven Web API Calculator

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

Page 19: Cucumber Driven Web API Calculator
Page 20: Cucumber Driven Web API Calculator

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/