bdd: tdd and beyond the infinite
TRANSCRIPT
![Page 1: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/1.jpg)
BEHAVIOUR DRIVEN DEVELOPMENT:TDD AND BEYOND THE INFINITE
![Page 2: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/2.jpg)
Duct Tape Religion War
![Page 3: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/3.jpg)
At the beginning…
![Page 4: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/4.jpg)
![Page 5: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/5.jpg)
end;
// CellText := str;
except
// Gabriele non t'ha beccato, Gigi neppure, a chi toccherà?
end;
end;
![Page 6: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/6.jpg)
while ((!found) && (pos < (fileContent.Length - 6))){ byteData = new byte[6]; Array.Copy(fileContent, pos, byteData, 0, 6); pos = pos + 6; str_byteData = enc.GetString(byteData); if (str_byteData.Contains("s")) { posE_byteData = str_byteData.IndexOf("s"); pos = pos + (posE_byteData - 6); Array.Copy(fileContent, pos, byteData, 0, 6); pos = pos + 6; if (byteData[0] == 0x73) // 's' { if (byteData[1] == 0x74) // 't' { if (byteData[2] == 0x72) // 'r' { if (byteData[3] == 0x65) // 'e' { if (byteData[4] == 0x61) // 'a' { if (byteData[5] == 0x6D) // 'm' { found = true; break; } else { if (byteData[5] == 0x73) { pos = pos - 1; } } }
![Page 7: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/7.jpg)
function TfrmPreviewTrascr.DBToLinear(DB: Double): Double;
begin
//Result := Power(10, DB/20)*1;
Result := Power(10, DB / 100) * 1; { TODO : trovare la relazione corretta }
//LisyLabel4.Caption := Format('%.2f:%.2f', [DB, Result] );
end;
![Page 8: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/8.jpg)
![Page 9: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/9.jpg)
![Page 10: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/10.jpg)
Kent Beck gave Tdd to programmers!
![Page 11: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/11.jpg)
The Three Laws of TDD
![Page 12: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/12.jpg)
The Three Laws of TDD
1 - You are not allowed to write any production code unless it is to make a failing unit test pass.
![Page 13: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/13.jpg)
The Three Laws of TDD
1 - You are not allowed to write any production code unless it is to make a failing unit test pass.
2 - You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
![Page 14: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/14.jpg)
The Three Laws of TDD
1 - You are not allowed to write any production code unless it is to make a failing unit test pass.
2 - You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
3 - You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
![Page 15: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/15.jpg)
TDD Cycle
![Page 16: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/16.jpg)
TDD Cycle
![Page 17: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/17.jpg)
TDD Cycle
![Page 18: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/18.jpg)
TDD Cycle
![Page 19: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/19.jpg)
TDD Cycle
![Page 20: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/20.jpg)
TDD Cycle
![Page 21: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/21.jpg)
TDD Cycle
![Page 22: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/22.jpg)
TDD Cycle
![Page 23: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/23.jpg)
TDD Cycle
![Page 24: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/24.jpg)
TDD Cycle
![Page 25: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/25.jpg)
TDD Cycle
![Page 26: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/26.jpg)
Is that the end of our problems?
![Page 27: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/27.jpg)
I’m a programmer, not a tester!
![Page 28: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/28.jpg)
My code it’s difficult to test!
![Page 29: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/29.jpg)
It’s a trivial, doesn’t need a test!
![Page 30: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/30.jpg)
I’ve no time to make automatic tests!
![Page 31: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/31.jpg)
It’s about specifications
![Page 32: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/32.jpg)
Sapir-Whorf hypotesis
“there is a systematic relationship between the grammatical categories of the language aperson speaks and how that person both understands the world and behaves in it.”
![Page 33: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/33.jpg)
The Challenge
![Page 34: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/34.jpg)
for(var i = 1; i <= 100; i++){ var output = i + ": "; if(i % 3 == 0) output += "fizz"; if(i % 5 == 0) output += "buzz"; console.log(output);}
48 sec
![Page 35: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/35.jpg)
for(var i = 1; i <= 100; i++){ var output = i + ": "; if(i % 3 == 0) output += "fizz"; if(i % 5 == 0) output += "buzz"; console.log(output);}
But it’s wrong!
![Page 36: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/36.jpg)
puts (1..100).map { |n| '1'*n+":#{n}\n" }.join. gsub(/^(1{5})*:/,'\0Buzz').gsub(/^(1{3})*:/,'Fizz').gsub(/.*:|(z)\d+/,'\1')
WTF?!?!!
![Page 37: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/37.jpg)
package biz.scalzo.tdd;import junit.framework.Assert;import org.junit.Test;import biz.scalzo.tdd.Fizzbuzzer;
public class FizzbuzzTest { @Test public void testForOne(){ Assert.assertEquals("1", new Fizzbuzzer().count(1)); }}
FizzbuzzTest.java
![Page 38: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/38.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { return null; }
}
Fizzbuzzer.java
![Page 39: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/39.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { return "1"; }
}
Fizzbuzzer.java
![Page 40: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/40.jpg)
@Testpublic void testForTwo(){ Assert.assertEquals("2", new Fizzbuzzer().count(2));}
FizzbuzzTest.java
![Page 41: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/41.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { return Integer.toString(i); }
}
Fizzbuzzer.java
![Page 42: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/42.jpg)
@Test public void testForThree(){ Assert.assertEquals("Fizz", new Fizzbuzzer().count(3)); }
FizzbuzzTest.java
![Page 43: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/43.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { if (i == 3) return "Fizz";
return Integer.toString(i); }
}
Fizzbuzzer.java
![Page 44: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/44.jpg)
@Test public void testForFour(){ Assert.assertEquals("4", new Fizzbuzzer().count(4)); }
FizzbuzzTest.java
![Page 45: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/45.jpg)
@Test public void testForFive(){ Assert.assertEquals("Buzz", new Fizzbuzzer().count(5)); }
FizzbuzzTest.java
![Page 46: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/46.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { if (i == 3) return "Fizz"; if (i == 5) return "Buzz";
return Integer.toString(i); }
}
Fizzbuzzer.java
![Page 47: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/47.jpg)
@Test public void testForSix(){ Assert.assertEquals("Fizz", new Fizzbuzzer().count(6)); }
FizzbuzzTest.java
![Page 48: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/48.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { if (i % 3 == 0) return "Fizz"; if (i == 5) return "Buzz";
return Integer.toString(i); }
}
Fizzbuzzer.java
![Page 49: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/49.jpg)
@Test public void testForSeven(){ Assert.assertEquals(“7", new Fizzbuzzer().count(7)); }
FizzbuzzTest.java
![Page 50: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/50.jpg)
@Test public void testForEight(){ Assert.assertEquals(“8", new Fizzbuzzer().count(8)); }
FizzbuzzTest.java
![Page 51: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/51.jpg)
@Test public void testForNine(){ Assert.assertEquals(“Fizz", new Fizzbuzzer().count(9)); }
FizzbuzzTest.java
![Page 52: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/52.jpg)
@Test public void testForTen(){ Assert.assertEquals("Buzz", new Fizzbuzzer().count(10)); }
FizzbuzzTest.java
![Page 53: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/53.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int i) { if (i % 3 == 0) return "Fizz"; if (i % 5 == 0) return "Buzz";
return Integer.toString(i); }
}
Fizzbuzzer.java
![Page 54: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/54.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int number) { if (isMultipleOf(number, 3)) return "Fizz"; if (isMultipleOf(number, 5)) return "Buzz";
return Integer.toString(number); }
private boolean isMultipleOf(int number, int multiple) { return number % multiple == 0; }}
Fizzbuzzer.java
![Page 55: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/55.jpg)
@Test public void testForFifteen(){ Assert.assertEquals("FizzBuzz", new Fizzbuzzer().count(15)); }
FizzbuzzTest.java
![Page 56: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/56.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int number) { if (isMultipleOf(number, 3) && isMultipleOf(number, 5)) return "FizzBuzz"; if (isMultipleOf(number, 3)) return "Fizz"; if (isMultipleOf(number, 5)) return "Buzz";
return Integer.toString(number); }
private boolean isMultipleOf(int number, int multiple) { return number % multiple == 0; }}
Fizzbuzzer.java
![Page 57: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/57.jpg)
package biz.scalzo.tdd;
public class Fizzbuzzer {
public String count(int number) { String fizzOrBuzz = fizz(number) + buzz(number); return fizzOrBuzz.equals("") ? Integer.toString(number) : fizzOrBuzz; }
private boolean isMultipleOf(int number, int multiple) { return number % multiple == 0; }
private String fizz(int number) { return isMultipleOf(number, 3) ? "Fizz" : ""; }
private String buzz(int number) { return isMultipleOf(number, 5) ? "Buzz" : ""; }}
Fizzbuzzer.java
![Page 58: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/58.jpg)
Result
![Page 59: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/59.jpg)
package biz.scalzo.tdd;import junit.framework.Assert;import org.junit.Test;import biz.scalzo.tdd.Fizzbuzzer;
public class FizzbuzzTest { @Test public void testForOne(){ Assert.assertEquals("1", new Fizzbuzzer().count(1)); }
@Test public void testForTwo(){ Assert.assertEquals("2", new Fizzbuzzer().count(2)); }
@Test public void testForThree(){ Assert.assertEquals("Fizz", new Fizzbuzzer().count(3)); }
@Test public void testForFive(){ Assert.assertEquals("Buzz", new Fizzbuzzer().count(5)); }
@Test public void testForSix(){ Assert.assertEquals("Fizz", new Fizzbuzzer().count(6)); }
FizzbuzzTest.java
![Page 60: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/60.jpg)
@Test public void testForSeven(){ Assert.assertEquals("7", new Fizzbuzzer().count(7)); }
@Test public void testForEight(){ Assert.assertEquals("8", new Fizzbuzzer().count(8)); }
@Test public void testForNine(){ Assert.assertEquals("Fizz", new Fizzbuzzer().count(9)); }
@Test public void testForTen(){ Assert.assertEquals("Buzz", new Fizzbuzzer().count(10)); }
@Test public void testForFifteen(){ Assert.assertEquals("FizzBuzz", new Fizzbuzzer().count(15)); }}
FizzbuzzTest.java
![Page 61: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/61.jpg)
![Page 62: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/62.jpg)
Bdd Way
![Page 63: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/63.jpg)
Bdd Way
Test method names should be sentences
![Page 64: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/64.jpg)
package biz.scalzo.bdd;
import java.util.ArrayList;import java.util.List;
import org.junit.Test;import static org.hamcrest.MatcherAssert.assertThat;import static org.hamcrest.Matchers.*;
public class AFizzbuzzer { @Test public void shouldYellOneForOne() { assertThat(new Fizzbuzzer().count(1), is(equalTo("1"))); }}
AFizzbuzzer.java
![Page 65: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/65.jpg)
package biz.scalzo.bdd;
import java.util.ArrayList;import java.util.List;
import org.junit.Test;import static org.hamcrest.MatcherAssert.assertThat;import static org.hamcrest.Matchers.*;
public class AFizzbuzzer { @Test public void shouldYellOneForOne() { assertThat(new Fizzbuzzer().count(1), is(equalTo("1"))); }}
AFizzbuzzer.java
![Page 66: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/66.jpg)
Bdd Way
the class should do something
![Page 67: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/67.jpg)
package biz.scalzo.bdd;
import java.util.ArrayList;import java.util.List;
import org.junit.Test;import static org.hamcrest.MatcherAssert.assertThat;import static org.hamcrest.Matchers.*;
public class AFizzbuzzer { @Test public void shouldYellOneForOne() { assertThat(new Fizzbuzzer().count(1), is(equalTo("1"))); }}
AFizzbuzzer.java
![Page 68: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/68.jpg)
package biz.scalzo.bdd;
import java.util.ArrayList;import java.util.List;
import org.junit.Test;import static org.hamcrest.MatcherAssert.assertThat;import static org.hamcrest.Matchers.*;
public class AFizzbuzzer { @Test public void shouldYellOneForOne() { assertThat(new Fizzbuzzer().count(1), is(equalTo("1"))); }}
AFizzbuzzer.java
![Page 69: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/69.jpg)
@Test public void shouldYellTwoForTwo() { assertThat(new Fizzbuzzer().count(2), is(equalTo("2"))); }
AFizzbuzzer.java
![Page 70: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/70.jpg)
@Test public void shouldYellFizzForMultipleOfThree() { int[] fizzers = { 3, 6, 9, 12, 18 }; for (int fizzer : fizzers) { assertThat(new Fizzbuzzer().count(fizzer), is(equalTo("Fizz"))); } }
AFizzbuzzer.java
![Page 71: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/71.jpg)
@Test public void shouldYellBuzzForMultipleOfFive() { int[] buzzers = { 5, 10 }; for (int buzzer : buzzers) { assertThat(new Fizzbuzzer().count(buzzer), is(equalTo("Buzz"))); } }
AFizzbuzzer.java
![Page 72: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/72.jpg)
@Test public void shouldYellFizzBuzzForMultipleOfThreeAndFive() { int[] fizzBuzzers = { 15, 30, 45, 60 }; for (int fizzBuzzer : fizzBuzzers ) { assertThat(new Fizzbuzzer().count(fizzBuzzer), is(equalTo("FizzBuzz"))); } }
AFizzbuzzer.java
![Page 73: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/73.jpg)
@Test public void shouldYellTheNumberForNotMultipleOfThreeOrFive() { for (int plainNumber : plainNumbers()) { assertThat(new Fizzbuzzer().count(plainNumber), is(equalTo(Integer .toString(plainNumber)))); } }
private List<Integer> plainNumbers() { List<Integer> numbers = new ArrayList<Integer>(); for (int i = 1; i <= 100; i++) numbers.add(i); for (int i = 1; i < 35; i++) numbers.remove(new Integer(i * 3));
for (int i = 1; i < 25; i++) numbers.remove(new Integer(i * 5)); return numbers; }
AFizzbuzzer.java
![Page 74: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/74.jpg)
![Page 75: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/75.jpg)
Fathers of Bdd
![Page 76: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/76.jpg)
The Ruby Way to Bdd
![Page 77: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/77.jpg)
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require "fizzbuzzer"
describe "Fizzbuzzer" do it "should yell one for one" do Fizzbuzzer.new.count(1).should == '1' endend
fizzbuzzer_spec.rb
![Page 78: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/78.jpg)
it "should yell two for two" do Fizzbuzzer.new.count(2).should == '2' end
fizzbuzzer_spec.rb
![Page 79: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/79.jpg)
it "should yell Fizz for three" do Fizzbuzzer.new.count(3).should == 'Fizz' end
fizzbuzzer_spec.rb
![Page 80: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/80.jpg)
it "should yell Fizz for multiple of three" do [3, 6, 9, 12].each do |number| Fizzbuzzer.new.count(number).should == 'Fizz' end end
fizzbuzzer_spec.rb
![Page 81: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/81.jpg)
it "should yell Buzz for multiple of five" do [5, 10].each do |number| Fizzbuzzer.new.count(number).should == 'Buzz' end end
fizzbuzzer_spec.rb
![Page 82: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/82.jpg)
it "should yell FizzBuzz for multiple of three and five" do [15, 30, 45].each do |number| Fizzbuzzer.new.count(number).should == 'FizzBuzz' end end
fizzbuzzer_spec.rb
![Page 83: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/83.jpg)
it "should yell the number itself for non multiple of three or five" do (1..100).select { |n| n % 3 != 0 && n % 5 != 0}.each do |number| Fizzbuzzer.new.count(number).should == number.to_s end end
fizzbuzzer_spec.rb
![Page 84: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/84.jpg)
Result
![Page 85: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/85.jpg)
class Fixnum def fizzbuzzed? "FizzBuzz" if self % 3 == 0 && self % 5 == 0 end def fizzed? "Fizz" if self % 3 == 0 end def buzzed? "Buzz" if self % 5 == 0 endend
class Fizzbuzzer def count(number) number.fizzbuzzed? || number.fizzed? || number.buzzed? || number.to_s endend
fizzbuzzer.rb
![Page 86: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/86.jpg)
describe "Fizzbuzzer" do it "should yell one for one" do Fizzbuzzer.new.count(1).should == '1' end it "should yell two for two" do Fizzbuzzer.new.count(2).should == '2' end it "should yell Fizz for multiple of three" do [3, 6, 9, 12].each do |number| Fizzbuzzer.new.count(number).should == 'Fizz' end end it "should yell Buzz for multiple of five" do [5, 10].each do |number| Fizzbuzzer.new.count(number).should == 'Buzz' end end it "should yell FizzBuzz for multiple of three and five" do [15, 30, 45].each do |number| Fizzbuzzer.new.count(number).should == 'FizzBuzz' end end it "should yell the number itself for non multiple of three or five" do (1..100).select { |n| n % 3 != 0 && n % 5 != 0}.each do |number| Fizzbuzzer.new.count(number).should == number.to_s end endend
fizzbuzzer_spec.rb
![Page 87: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/87.jpg)
output
![Page 88: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/88.jpg)
output
![Page 89: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/89.jpg)
Stories
![Page 90: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/90.jpg)
As a [role]I want [feature]So that [benefit]
Story
![Page 91: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/91.jpg)
Scenario 1: TitleGiven [context] And [some more context]...When [event]Then [outcome] And [another outcome]
Scenario Acceptance Criteria
![Page 92: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/92.jpg)
Cucumber
![Page 93: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/93.jpg)
Cucumber
fizzbuzzer.featurefizzbuzzer_steps.rb
![Page 94: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/94.jpg)
Feature: perfect fizzbuzzing As a inattentive counter I want an automatic Fizzbuzzer So that I can win Fizzbuzz Championsip
fizzbuzzer.feature
![Page 95: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/95.jpg)
Scenario: manage fizz numbers Given a Fizzbuzzer When I ask for a multiple of 3 Then Fizzbuzzer yells 'Fizz'
fizzbuzzer.feature
![Page 96: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/96.jpg)
require "fizzbuzzer"
Given "a Fizzbuzzer" do @fizzbuzzer = Fizzbuzzer.newend
When "I ask for a multiple of $m" do |m| @result = [1, 2].map { |base| @fizzbuzzer.count(base*eval(m).to_i) }end
Then "Fizzbuzzer yells '$yell'" do |yell| @result.each do |result| result.should == yell endend
fizzbuzzer_steps.rb
![Page 97: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/97.jpg)
Scenario: manage buzz numbers Given a Fizzbuzzer When I ask for a multiple of 5 Then Fizzbuzzer yells 'Buzz'
Scenario: manage fizzbuzz numbers Given a Fizzbuzzer When I ask for a multiple of 3*5 Then Fizzbuzzer yells 'FizzBuzz'
fizzbuzzer.feature
![Page 98: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/98.jpg)
Scenario: manage plain numbers Given a Fizzbuzzer When I ask for a plain number Then Fizzbuzzer yells the number itself
fizzbuzzer.feature
![Page 99: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/99.jpg)
When "I ask for a plain number" do @expected = (1..100).select { |n| n % 3 != 0 && n % 5 != 0}
@result = @expected.each do |number| @fizzbuzzer.count(number).to_i end
end
Then "Fizzbuzzer yells the number itself" do @result.should == @expectedend
fizzbuzzer_steps.rb
![Page 100: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/100.jpg)
Scenario Outline: manage plain numbers Given a Fizzbuzzer When I ask for '<number>' Then Fizzbuzzer yells '<result>' Examples: | number | result | | 1 | 1 | | 2 | 2 | | 3 | Fizz | | 4 | 4 | | 5 | Buzz | | 6 | Fizz |
fizzbuzzer.feature
![Page 101: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/101.jpg)
When "I ask for '$m'" do |number| @result = @fizzbuzzer.count(number.to_i)end
Then "Fizzbuzzer yells '$yell'" do |yell| @result.each do |result| result.should == yell endend
fizzbuzzer_steps.rb
![Page 102: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/102.jpg)
neat, isn’t it?
![Page 103: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/103.jpg)
Back to Java
![Page 104: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/104.jpg)
Where it all started
![Page 105: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/105.jpg)
jbehave
manage_fizzbuzzerManageFizzbuzzer.javaManageFizzbuzzerSteps.java
![Page 106: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/106.jpg)
Feature: perfect fizzbuzzing As a inattentive counter I want an automatic Fizzbuzzer So that I can win Fizzbuzz Championsip
Scenario: manage fizz numbers Given a Fizzbuzzer When I ask for a multiple of 3 Then Fizzbuzzer yells 'Fizz'
Scenario: manage buzz numbers Given a Fizzbuzzer When I ask for a multiple of 5 Then Fizzbuzzer yells 'Buzz'
Scenario: manage fizzbuzz numbers Given a Fizzbuzzer When I ask for a multiple of 15 Then Fizzbuzzer yells 'FizzBuzz'
manage_fizzbuzzer
![Page 107: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/107.jpg)
Scenario: manage plain numbers Given a Fizzbuzzer When I ask for a plain number Then Fizzbuzzer yells the number itself
Scenario: manage plain numbers Given a Fizzbuzzer When I ask for '[number]' Then Fizzbuzzer yells '[yell]'
Examples: | number | yell | | 1 | 1 | | 2 | 2 | | 3 | Fizz | | 4 | 4 | | 5 | Buzz | | 6 | Fizz |
manage_fizzbuzzer
![Page 108: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/108.jpg)
package biz.scalzo.jbehave;
import org.jbehave.scenario.Scenario;
public class ManageFizzbuzzer extends Scenario { public ManageFizzbuzzer() { super(new ManageFizzbuzzerSteps()); }}
ManageFizzbuzzer.java
![Page 109: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/109.jpg)
import biz.scalzo.bdd.Fizzbuzzer;
public class ManageFizzbuzzerSteps extends Steps { private Fizzbuzzer fizzbuzzer; private List<String> results; private List<String> expected; private String result;
@BeforeScenario public void setUp() { expected = new ArrayList<String>(); results = new ArrayList<String>(); }
ManageFizzbuzzerSteps.java
![Page 110: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/110.jpg)
@Given("a Fizzbuzzer") public void startFizzbuzzer() { fizzbuzzer = new Fizzbuzzer(); }
@When("I ask for a multiple of $divisor") public void askForMultipleOf(int divisor) { for (int number = 1; number < 3; ++number) results.add(fizzbuzzer.count(number * divisor)); }
@Then("Fizzbuzzer yells '$yell'") public void checkYell(String yell) { for (String result : results) { assertThat(result, is(equalTo(yell))); } }
ManageFizzbuzzerSteps.java
![Page 111: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/111.jpg)
@When("I ask for a plain number") public void askForPlainNumbers() { for (int i = 1; i <= 100; i++) if (i % 3 != 0 && i % 5 != 0) expected.add(Integer.toString(i));
for (String number : expected) results.add(fizzbuzzer.count(Integer.parseInt(number))); }
@Then("Fizzbuzzer yells the number itself") public void yellsNumberItself() { for (int i = 0; i < expected.size(); i++) { assertThat(results.get(i), is(equalTo(expected.get(i)))); } }
ManageFizzbuzzerSteps.java
![Page 112: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/112.jpg)
@When("I ask for '[number]'") public void askFor(@Named("number") int number) { result = fizzbuzzer.count(number); }
@Then("Fizzbuzzer yells '[yell]'") public void checkResult(@Named("yell") String yell) { assertThat(result, is(equalTo(yell))); }
ManageFizzbuzzerSteps.java
![Page 113: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/113.jpg)
Other Frameworks
![Page 114: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/114.jpg)
•ASSpec ActionScript 3•CppSpec C++•Spec- cpp C++•CSpec C•cfSpec ColdFusion•dSpec Delphi•easyb Groovy•EasySpec Groovy•tspec Groovy•GSpec Groovy•Concordion Java•GivWenZen Java•Instinct Java•JavaStubs Java•JBehave Java•JDave Java•beanSpec Java•JFXtras Test JavaFX•JSpec JavaScript•JSSpec JavaScript•Screw- unit JavaScript
Other Frameworks
![Page 115: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/115.jpg)
•NBehave .Net•NSpec .Net•NSpecify .Net•SpecUnit .Net•NUnit .Net•Specter .Net•StoryQ .Net•ObjectiveMatchy iPhone•PHPSpec PHP•Pyccuracy Python•Pyhistorian Python•PyCukes Python•Robot Framework Python•ScalaTest Scala•specs Scala
Other Frameworks
![Page 116: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/116.jpg)
Conclusions?
![Page 117: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/117.jpg)
Bdd is about specifications
![Page 118: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/118.jpg)
Homework
![Page 119: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/119.jpg)
http://github.com/coreyhaines/practice_game_of_life
![Page 120: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/120.jpg)
Feature: Evolving a living cell In order to create a functioning rules engine As a programmer of Conway's Game of Life I can evolve a single living cell Scenario: Living cell with 0 neighbors dies Given the following setup | . | . | . | | . | x | . | | . | . | . | When I evolve the board Then the center cell should be dead Scenario: Living cell with 1 neighbor dies Given the following setup | . | x | . | | . | x | . | | . | . | . | When I evolve the board Then the center cell should be dead Scenario: Living cell with 2 neighbors lives Given the following setup | . | x | . | | . | x | x | | . | . | . | When I evolve the board Then the center cell should be alive Scenario: Living cell with 3 neighbors lives Given the following setup | x | x | x | | . | x | . | | . | . | . | When I evolve the board Then the center cell should be alive
![Page 121: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/121.jpg)
Start Bdd now!
![Page 122: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/122.jpg)
![Page 123: Bdd: Tdd and beyond the infinite](https://reader036.vdocuments.net/reader036/viewer/2022062905/54214b6d7bef0a060c8b5d0b/html5/thumbnails/123.jpg)
? ? ????