Behavior-Driven Development

Behaviour-Driven Development

Behaviour-Driven Development (BDD) is an evolution in the thinking behind TestDrivenDevelopment and AcceptanceTestDrivenPlanning.

It pulls together strands from TestDrivenDevelopment and DomainDrivenDesign into an integrated whole, making the relationship between these two powerful approaches to software development more evident.

TDD/BDD in Ruby - Chapter 7

To-Do List

$5 + 10 CHF = $10 if rate is 2:1
$5 * 2 - $10
Make "amount" private
Dollar side effects?
Money rounding?
equals()
hashCode()
Equal null
Equal object
5 CHF * 2 - 10 CHF
Dollar/Franc duplication
Common equals
Common times
Compare Francs with Dollars
Currency?

TDD/BDD in Ruby - Chapter 6

To-Do List

$5 + 10 CHF = $10 if rate is 2:1
$5 * 2 - $10
Make "amount" private
Dollar side effects?
Money rounding?
equals()
hashCode()
Equal null
Equal object
5 CHF * 2 - 10 CHF
Dollar/Franc duplication
Common equals
Common times
Compare Francs with Dollars

TDD/BDD in Ruby - Chapter 5

To-Do List

$5 + 10 CHF = $10 if rate is 2:1
$5 * 2 - $10
Make "amount" private
Dollar side effects?
Money rounding?
equals()
hashCode()
Equal null
Equal object
5 CHF * 2 - 10 CHF
Dollar/Franc duplication
Common equals
Common times

Test Code


public void testMultiplication {
  Dollar five = new Dollar(5);
  assertEquals(new Dollar(10), five.times(2));
  assertEquals(new Dollar(15), five.times(3));
}

TDD/BDD in Ruby - Chapter 4

To-Do List

$5 + 10 CHF = $10 if rate is 2:1
$5 * 2 - $10
Make "amount" private
Dollar side effects?
Money rounding?
equals()
hashCode()
Equal null
Equal object

Test Code


public void testMultiplication {
  Dollar five = new Dollar(5);
  assertEquals(new Dollar(10), five.times(2));
  assertEquals(new Dollar(15), five.times(3));
}

TDD/BDD in Ruby - Chapter 3

To-Do List

$5 + 10 CHF = $10 if rate is 2:1
$5 * 2 - $10
Make "amount" private
Dollar side effects?
Money rounding?
equals()
hashCode()


public void testEquality() {
  assertTrue(new Dollar(5).equals(new Dollar(5)));
}

TDD/BDD in Ruby - Chapter 2

TDD Cycle

  1. Write a test
  2. Make it run
  3. Make it right

The goal is clean code that works - Ron Jeffries

So we want to test multiplication and make sure that the "times()" method returns the right amount when passed a multiplier.


public void testMultiplication() {
  Dollar five = new Dollar(5);
  Dollar product = five.times(2);
  assertEquals(10, product.amount);
  product = five.times(3);
  assertEquals(15, product.amount);
}

RSpec - Behaviour Specification Framework for Ruby

RSpec is a behaviour specification framework for Ruby. RSpec was created in
response to Dave Astels’ article _A New Look at Test Driven
Development_ which can be read at: daveastels.com/index.php?p=5
RSpec is intended to provide the features discussed in Dave’s
article.

Syndicate content