Behavior Driven Development by Mark Menard Vita Rara, Inc.
Test Driven Development TDD is a development process where tests for code are written before the writing of implementation code. Has been primarily focused on unit testing. In recent years functional and integration testing have become more common. Some examples of unit testing tools: Java: JUnit C#: NUnit Ruby: Test::Unit Many languages have xUnit frameworks
xUnit Testing xUnit frameworks focus on creating tests for code. There is little opportunity to involve the consumers of the software in the process. The language and style speak directly to software developers, not stake holders. Is very code centric Tests are typically organized in classes. Very few domain experts can read xUnit tests.
JUnit Test Example @ Test   public   void  simpleAdd() { Money  m12CHF =   new   Money ( 12 ,  "CHF" );  Money  m14CHF =   new   Money ( 14 ,  "CHF" );  Money  expected =   new   Money ( 26 ,  "CHF" );  Money  result =  m12CHF . add(m14CHF);  assertTrue(expected . equals(result)); }
JUnit Test Fixture Setup public   class  MoneyTest {  private   Money  f12CHF;  private   Money  f14CHF;  private   Money  f28USD;  @Before   public   void   setUp () {  f12CHF =   new   Money ( 12 ,  "CHF" );  f14CHF =   new   Money ( 14 ,  "CHF" );  f28USD =   new   Money ( 28 ,  "USD" );  } }
Behavior Driven Development Focus on what something should do. Encourages a literate style. Supports extraction of the specification in a readable format. Specs should be readable by domain experts. Specs should be executable. Should support testing code in isolation, integrated and full stack. When the spec runs you’re done.
My BDD Tool Kit Cucumber Specify what the user should see and be able to do. RSpec Specify what code should do. Mocha Mocking and stubbing library. FactoryGirl Automated setup of database fixtures. Integrates with Rails ActiveRecord Implementation of the Fixture Factory pattern.
Cucumber Cucumber lets software development teams describe how software should behave in plain text. Cucumber features are written in a business-readable domain-specific language and serve as: Documentation Automated tests Development aid Cucumber works with Ruby, Java, .Net, Flex, or web apps in any language. It has been translated into over 30 spoken languages, including lolz.
Cucumber Example Feature: Contact Us As an anonymous user I want to be able to send a message So that I can receive support or get an answer to a question Scenario: Load Form Given I am on "home page" When I follow "Contact Us" Then I should see "Please use the following form" Scenario: Submitting form Given I am on the "contact us page" When I fill in "contact_handler[email]" with "me@example.com" And I fill in "contact_handler[subject]" with "Help" And I fill in "contact_handler[body]" with "Content" And I press "send" Then I should see "Thanks for your message."
Why Cucumber? Your clients can help you create the feature specifications. When it’s green you’re done. Stop the dithering. You have an agreed on deliverable. If the deliverable request changes then the spec changes. Makes clients aware they’re moving the goal post. In Rails it is very easy to test the complete app stack. Can be used with any web application. .Net, ASP, Java, PHP, Python. Django, etc.
RSpec RSpec provides a domain specific language with which you can express executable examples of the expected behavior of your code. RSpec is code centric. RSpec includes support for mocking and stubbing. I use it as a replacement for unit and integration testing. Models and controllers
An RSpec Example You:  Describe an account when it is first created. Customer: It should have a balance of $0. describe Account, "when first created" do it "should have a balance of $0" do ... end end When you run this example, RSpec can provide a report like this: Account when first created - should have a balance of $0
Why RSpec? Extremely expressive Supports building of test contexts in steps. Built in support for mocking and stubbing to support testing in isolation. I personally use Mocha, but starting with RSpec is fine. They both work. Easily produce specifications for client approval. Has a literate style accessible to domain experts. Has excellent support for Rails.
Mocha A mocking and stubbing library for Ruby. Uses a syntax similar to JMock. Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking. Commonly used to isolate layers in an application to isolate tests. Can also be used to test expected collaborations between classes.
The Example Application A simple check book ledger.

More Related Content

PPT
Agile Development With Hobo
PPTX
Switch case looping
PPT
PPTX
A Web Developer's Journey across different versions of ASP.NET
DOCX
Javascript
PPTX
php 7.4 for word press developers
PPT
IT Club @ NCP - PHP Workshop May 10, 2011
PPTX
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Agile Development With Hobo
Switch case looping
A Web Developer's Journey across different versions of ASP.NET
Javascript
php 7.4 for word press developers
IT Club @ NCP - PHP Workshop May 10, 2011
Joomla! Day Chicago 2011 Presentation - Steven Pignataro

What's hot (20)

PPTX
Software Design
ODP
Coder Presentation
PDF
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PDF
Introduction to php exception and error management
PDF
TypeScript: Angular's Secret Weapon
PDF
Csharp_Chap01
PDF
php_tizag_tutorial
PPT
TDD, BDD, RSpec
PPTX
Clean Code
DOC
Php tutorial
PDF
TDD with PhpSpec - Lone Star PHP 2016
PDF
The PHP Way Of TDD - Think First, Code Later
PDF
Advanced PHP: Design Patterns - Dennis-Jan Broerse
 
PDF
Php tutorial
PPTX
Welcome to computer programmer 2
PDF
C plus plus for hackers it security
PPTX
Cordovilla
DOCX
PHP Lesson
Software Design
Coder Presentation
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
Introduction to php exception and error management
TypeScript: Angular's Secret Weapon
Csharp_Chap01
php_tizag_tutorial
TDD, BDD, RSpec
Clean Code
Php tutorial
TDD with PhpSpec - Lone Star PHP 2016
The PHP Way Of TDD - Think First, Code Later
Advanced PHP: Design Patterns - Dennis-Jan Broerse
 
Php tutorial
Welcome to computer programmer 2
C plus plus for hackers it security
Cordovilla
PHP Lesson

Viewers also liked (20)

PPTX
Calabash
PDF
Beyond Testing: Specs and Behavior Driven Development
PDF
BDD training v5.0.1
PPTX
Effective Testing using Behavior-Driven Development
PPTX
Behavior Driven Testing for Multichannel Enterprise Applications
PDF
Startup Institute: JS Testing & Behavior Driven Development
PDF
Behavior Driven GUI Testing
PPTX
Behavior Driven Testing of Web Services
PDF
Behavior Driven Testing goes Mobile!
PDF
German Testing Day 2015 - How behavior-driven development fuses developers an...
PDF
Behavior driven development. Testing drupal using behat
PPTX
Behavior Driven Development
PDF
Building the "right" regression suite using Behavior Driven Testing (BDT)
PDF
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
KEY
Behavior driven development
PDF
Behavior Driven Testing - A paradigm shift
PPTX
BDD / cucumber /Capybara
KEY
Natural Language UI Testing using Behavior Driven Development with Pavlov and...
PPTX
[Agile Testing Day] Behavior Driven Development (BDD)
PPTX
Behavior Driven Development Testing (BDD)
Calabash
Beyond Testing: Specs and Behavior Driven Development
BDD training v5.0.1
Effective Testing using Behavior-Driven Development
Behavior Driven Testing for Multichannel Enterprise Applications
Startup Institute: JS Testing & Behavior Driven Development
Behavior Driven GUI Testing
Behavior Driven Testing of Web Services
Behavior Driven Testing goes Mobile!
German Testing Day 2015 - How behavior-driven development fuses developers an...
Behavior driven development. Testing drupal using behat
Behavior Driven Development
Building the "right" regression suite using Behavior Driven Testing (BDT)
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Behavior driven development
Behavior Driven Testing - A paradigm shift
BDD / cucumber /Capybara
Natural Language UI Testing using Behavior Driven Development with Pavlov and...
[Agile Testing Day] Behavior Driven Development (BDD)
Behavior Driven Development Testing (BDD)

Similar to Behavior Driven Development with Rails (20)

PPTX
SD Ruby BDD Talk
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
PPTX
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
PPTX
Behaviour Driven Development
KEY
Ruby on Rails Training - Module 2
PPTX
TDD with RSpec
PPTX
Behavior Driven Development - TdT@Cluj #15
PDF
10 things about BDD, Cucumber and SpecFlow - Long Version 2016
PDF
Rethinking Testing
PPTX
RSpec: What, How and Why
PPTX
BDD Selenium for Agile Teams - User Stories
KEY
TorontoRb Intro to BDD
KEY
Test Driven Development
PDF
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
KEY
WTF TDD?
PDF
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
PDF
Behavior Driven Development with Cucumber
PPTX
Bdd with Cucumber and Mocha
PDF
Automated Testing with Ruby
SD Ruby BDD Talk
Rspec and Capybara Intro Tutorial at RailsConf 2013
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behaviour Driven Development
Ruby on Rails Training - Module 2
TDD with RSpec
Behavior Driven Development - TdT@Cluj #15
10 things about BDD, Cucumber and SpecFlow - Long Version 2016
Rethinking Testing
RSpec: What, How and Why
BDD Selenium for Agile Teams - User Stories
TorontoRb Intro to BDD
Test Driven Development
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
WTF TDD?
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Behavior Driven Development with Cucumber
Bdd with Cucumber and Mocha
Automated Testing with Ruby

More from Mark Menard (14)

PDF
Let's Do Some Upfront Design - WindyCityRails 2014
PDF
A Tour of Wyriki
PDF
Small Code - RailsConf 2014
PDF
Small Code - Ruby on Ales 2014
PDF
Write Small Things (Code)
PDF
JRuby 6 Years in Production
PDF
Conference of Grand Masters Tech Talk 2013
KEY
Startup Lessons Learned
PDF
Mobile Platforms and App Development
KEY
Ruby on Rails Training - Module 1
KEY
Introduction to Ruby
PPT
Intro to Rails ActiveRecord
PPT
Intro to Ruby on Rails
PPT
JRuby in a Java World
Let's Do Some Upfront Design - WindyCityRails 2014
A Tour of Wyriki
Small Code - RailsConf 2014
Small Code - Ruby on Ales 2014
Write Small Things (Code)
JRuby 6 Years in Production
Conference of Grand Masters Tech Talk 2013
Startup Lessons Learned
Mobile Platforms and App Development
Ruby on Rails Training - Module 1
Introduction to Ruby
Intro to Rails ActiveRecord
Intro to Ruby on Rails
JRuby in a Java World

Behavior Driven Development with Rails

  • 1. Behavior Driven Development by Mark Menard Vita Rara, Inc.
  • 2. Test Driven Development TDD is a development process where tests for code are written before the writing of implementation code. Has been primarily focused on unit testing. In recent years functional and integration testing have become more common. Some examples of unit testing tools: Java: JUnit C#: NUnit Ruby: Test::Unit Many languages have xUnit frameworks
  • 3. xUnit Testing xUnit frameworks focus on creating tests for code. There is little opportunity to involve the consumers of the software in the process. The language and style speak directly to software developers, not stake holders. Is very code centric Tests are typically organized in classes. Very few domain experts can read xUnit tests.
  • 4. JUnit Test Example @ Test public void simpleAdd() { Money m12CHF = new Money ( 12 , "CHF" ); Money m14CHF = new Money ( 14 , "CHF" ); Money expected = new Money ( 26 , "CHF" ); Money result = m12CHF . add(m14CHF); assertTrue(expected . equals(result)); }
  • 5. JUnit Test Fixture Setup public class MoneyTest { private Money f12CHF; private Money f14CHF; private Money f28USD; @Before public void setUp () { f12CHF = new Money ( 12 , "CHF" ); f14CHF = new Money ( 14 , "CHF" ); f28USD = new Money ( 28 , "USD" ); } }
  • 6. Behavior Driven Development Focus on what something should do. Encourages a literate style. Supports extraction of the specification in a readable format. Specs should be readable by domain experts. Specs should be executable. Should support testing code in isolation, integrated and full stack. When the spec runs you’re done.
  • 7. My BDD Tool Kit Cucumber Specify what the user should see and be able to do. RSpec Specify what code should do. Mocha Mocking and stubbing library. FactoryGirl Automated setup of database fixtures. Integrates with Rails ActiveRecord Implementation of the Fixture Factory pattern.
  • 8. Cucumber Cucumber lets software development teams describe how software should behave in plain text. Cucumber features are written in a business-readable domain-specific language and serve as: Documentation Automated tests Development aid Cucumber works with Ruby, Java, .Net, Flex, or web apps in any language. It has been translated into over 30 spoken languages, including lolz.
  • 9. Cucumber Example Feature: Contact Us As an anonymous user I want to be able to send a message So that I can receive support or get an answer to a question Scenario: Load Form Given I am on "home page" When I follow "Contact Us" Then I should see "Please use the following form" Scenario: Submitting form Given I am on the "contact us page" When I fill in "contact_handler[email]" with "[email protected]" And I fill in "contact_handler[subject]" with "Help" And I fill in "contact_handler[body]" with "Content" And I press "send" Then I should see "Thanks for your message."
  • 10. Why Cucumber? Your clients can help you create the feature specifications. When it’s green you’re done. Stop the dithering. You have an agreed on deliverable. If the deliverable request changes then the spec changes. Makes clients aware they’re moving the goal post. In Rails it is very easy to test the complete app stack. Can be used with any web application. .Net, ASP, Java, PHP, Python. Django, etc.
  • 11. RSpec RSpec provides a domain specific language with which you can express executable examples of the expected behavior of your code. RSpec is code centric. RSpec includes support for mocking and stubbing. I use it as a replacement for unit and integration testing. Models and controllers
  • 12. An RSpec Example You: Describe an account when it is first created. Customer: It should have a balance of $0. describe Account, "when first created" do it "should have a balance of $0" do ... end end When you run this example, RSpec can provide a report like this: Account when first created - should have a balance of $0
  • 13. Why RSpec? Extremely expressive Supports building of test contexts in steps. Built in support for mocking and stubbing to support testing in isolation. I personally use Mocha, but starting with RSpec is fine. They both work. Easily produce specifications for client approval. Has a literate style accessible to domain experts. Has excellent support for Rails.
  • 14. Mocha A mocking and stubbing library for Ruby. Uses a syntax similar to JMock. Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking. Commonly used to isolate layers in an application to isolate tests. Can also be used to test expected collaborations between classes.
  • 15. The Example Application A simple check book ledger.

Editor's Notes

  • #15: Show example_4_spec.rb