SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Test Driven Development
Introductie
● Wat is TDD?
● Waarom TDD?
● Workshop
Wat is TDD?
Wikipedia: a software development process that relies on
the repetition of a very short development cycle: first the
developer writes an (initially failing) test case that defines a
desired improvement or new function, then produces the
minimum amount of code to pass that test, and finally
refactors the new code to acceptable standards
Wat is TDD?
Wikipedia: a software development process that relies on
the repetition of a very short development cycle: first the
developer writes an (initially failing) test case that
defines a desired improvement or new function, then
produces the minimum amount of code to pass that test,
and finally refactors the new code to acceptable standards
Wat is TDD?
Wikipedia: a software development process that relies on
the repetition of a very short development cycle: first the
developer writes an (initially failing) test case that defines a
desired improvement or new function, then produces the
minimum amount of code to pass that test, and finally
refactors the new code to acceptable standards
Wat is TDD?
Wikipedia: a software development process that relies on
the repetition of a very short development cycle: first the
developer writes an (initially failing) test case that defines a
desired improvement or new function, then produces the
minimum amount of code to pass that test, and finally
refactors the new code to acceptable standards
Waarom TDD
NIET testen:
Waarom TDD
De workshop - Coding Dojo regels
Groepjes van twee
Computer wisselt met elke stap
Alle code moet getest zijn
Er zijn meerdere oplossingen mogelijk
Probeer eens iets nieuws
De opdracht
Toon een opeenvolgende rij van getallen
Als een getal deelbaar is door 3, toon "Fizz"
Als een getal deelbaar is door 5, toon "Buzz"
Als een getal deelbaar is door 3 en 5, toon
"FizzBuzz"
Voorbeelduitkomst
"1"

"11"

"Fizz"

"31"

"41"

"2"

"Fizz"

"22"

"32"

"Fizz"

"Fizz"

"13"

"23"

"Fizz"

"43"

"4"

"14"

"Fizz"

"34"

"44"

"Buzz"

"FizzBuzz"

"Buzz"

"Buzz"

"FizzBuzz"

"Fizz"

"16"

"26"

"Fizz"

"46"

"7"

"17"

"Fizz"

"37"

"47"

"8"

"Fizz"

"28"

"38"

"Fizz"

"Fizz"

"19"

"29"

"Fizz"

"49"

"Buzz"

"Buzz"

"FizzBuzz"

"Buzz"

"Buzz"
Voorbeeldoplossing - stap 1
Schrijf een (falende) test:
test_fizz_buzz.rb:
require_relative "fizz_buzz"

console:
E

require "test/unit"

Finished tests in 0.000378s, 2642.4268 tests/s,
0.0000 assertions/s.

class TestFizzBuzz < Test::Unit::TestCase

1) Error:
test_number_3(TestFizzBuzz):
NoMethodError: undefined method `print for
FizzBuzz:Class
test_fizz_buzz.rb:6:in `test_number_3'

def test_number_3
assert_equal "Fizz", FizzBuzz.print(3)
end
end

1 tests, 0 assertions, 0 failures, 1 errors, 0
skips
Voorbeeldoplossing - stap 2
Schrijf de minimale code om de test te laten lukken:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "Fizz" if number == 3
end
end

console:
.
Finished tests in 0.000306s, 3266.2660 tests/s,
3266.2660 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 3
Wat gebeurt er als we 6 meegeven?
test_fizz_buzz.rb:
class TestFizzBuzz < Test::Unit::TestCase
def test_number_3
assert_equal "Fizz", FizzBuzz.print(3)
end

def test_number_6
assert_equal "Fizz", FizzBuzz.print(6)
end
end

console:
.F
Finished tests in 0.000525s, 3808.0804 tests/s,
3808.0804 assertions/s.
1) Failure:
test_number_6(TestFizzBuzz) [test_fizz_buzz.rb:
10]:
<"Fizz"> expected but was
<nil>.
2 tests, 2 assertions, 1 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 4
Herschrijf de code:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "Fizz" if (number % 3 == 0)
end
end

console:
..
Finished tests in 0.000342s, 5851.4436 tests/s,
5851.4436 assertions/s.
2 tests, 2 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 5
Schrijf de test voor nummer 5:
test_fizz_buzz.rb:
class TestFizzBuzz < Test::Unit::TestCase
def test_number_5
assert_equal "Buzz", FizzBuzz.print(5)
end
end

console:
.F.
Finished tests in 0.000589s, 5092.4794 tests/s,
5092.4794 assertions/s.
1) Failure:
test_number_5(TestFizzBuzz) [test_fizz_buzz.rb:
14]:
<"Buzz"> expected but was
<nil>.
3 tests, 3 assertions, 1 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 6
Schrijf de code voor nummer 5:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "Fizz" if (number % 3 == 0)
return "Buzz" if number == 5
end
end

console:
...
Finished tests in 0.000352s, 8522.3157 tests/s,
8522.3157 assertions/s.
3 tests, 3 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 7
Wat gebeurt er nu bij nummer 10?
test_fizz_buzz.rb:
class FizzBuzz < Test::Unit::TestCase
def test_number_5
assert_equal "Buzz", FizzBuzz.print(5)
end

def test_number_10
assert_equal "Buzz", FizzBuzz.print(10)
end
end

console:
F...
Finished tests in 0.000565s, 7083.0057 tests/s,
7083.0057 assertions/s.
1) Failure:
test_number_10(TestFizzBuzz) [test_fizz_buzz.rb:
18]:
<"Buzz"> expected but was
<nil>.
4 tests, 4 assertions, 1 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 8
Herschrijf de code:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
end
end

console:
....
Finished tests in 0.000387s, 10343.3474 tests/s,
10343.3474 assertions/s.
4 tests, 4 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 9
Schrijf de test voor 3 en 5:
test_fizz_buzz.rb:
class TestFizzBuzz < Test::Unit::TestCase
def test_number_15
assert_equal "FizzBuzz", FizzBuzz.print(15)
end
end

console:
.F...
Finished tests in 0.000618s, 8085.1594 tests/s,
8085.1594 assertions/s.
1) Failure:
test_number_15(TestFizzBuzz) [test_fizz_buzz.rb:
22]:
<"FizzBuzz"> expected but was
<"Fizz">.
5 tests, 5 assertions, 1 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 10
Schrijf de code voor 3 en 5:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "FizzBuzz" if number == 15
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
end
end

console:
.....
Finished tests in 0.000392s, 12763.0138 tests/s,
12763.0138 assertions/s.
5 tests, 5 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 11
Wat gebeurt er nu bij 30?
test_fizz_buzz.rb:
class TestFizzBuzz < Test::Unit::TestCase
def test_number_15
assert_equal "FizzBuzz", FizzBuzz.print(15)
end

def test_number_30
assert_equal "FizzBuzz", FizzBuzz.print(30)

console:
...F..
Finished tests in 0.000599s, 10010.2104 tests/s,
10010.2104 assertions/s.
1) Failure:
test_number_30(TestFizzBuzz) [test_fizz_buzz.rb:
26]:
<"FizzBuzz"> expected but was
<"Fizz">.

end
end

6 tests, 6 assertions, 1 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 12
Schrijf de code voor 30:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "FizzBuzz" if (number % 3 == 0) &&
(number && 5 == 0)
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
end
end

console:
......
Finished tests in 0.000423s, 14191.6775 tests/s,
14191.6775 assertions/s.
6 tests, 6 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 13
Refactor de code voor 30:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "FizzBuzz" if (number % 15 == 0)
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
end
end

console:
......
Finished tests in 0.000423s, 14191.6775 tests/s,
14191.6775 assertions/s.
6 tests, 6 assertions, 0 failures, 0 errors, 0
skips
Voorbeeldoplossing - stap 14
Wat als we een foutje hadden gemaakt?
fizz_buzz.rb:

console:
F.F.FF

class FizzBuzz
Finished tests in 0.000999s, 6007.5034 tests/s, 6007.5034 assertions/s.

def self.print(number)
return "FizzBuzz" if (number % 3 == 0) ||
(number % 5 == 0)
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
end
end

1) Failure:
test_number_10(TestFizzBuzz) [test_fizz_buzz.rb:18]:
<"Buzz"> expected but was
<"FizzBuzz">.
2) Failure:
test_number_3(TestFizzBuzz) [test_fizz_buzz.rb:6]:
<"Fizz"> expected but was
<"FizzBuzz">.
3) Failure:
test_number_5(TestFizzBuzz) [test_fizz_buzz.rb:14]:
<"Buzz"> expected but was
<"FizzBuzz">.
4) Failure:
test_number_6(TestFizzBuzz) [test_fizz_buzz.rb:10]:
<"Fizz"> expected but was
<"FizzBuzz">.
6 tests, 6 assertions, 4 failures, 0 errors, 0 skips
Voorbeeldoplossing - stap 15
Schrijf de test voor alle andere getallen:
test_fizz_buzz.rb:

console:
..F....

class TestFizzBuzz < Test::Unit::TestCase
Finished tests in 0.000631s, 11091.4634 tests/s, 11091.4634 assertions/s.

def test_number_2
assert_equal "2", FizzBuzz.print(2)
end

1) Failure:
test_number_2(TestFizzBuzz) [test_fizz_buzz.rb:30]:
<"2"> expected but was
<nil>.
7 tests, 7 assertions, 1 failures, 0 errors, 0 skips

end
Voorbeeldoplossing - stap 16
Schrijf de code voor alle andere getallen:
fizz_buzz.rb:

console:
.......

class FizzBuzz
Finished tests in 0.000520s, 13452.1220 tests/s, 13452.1220 assertions/s.

def self.print(number)
return "FizzBuzz" if (number % 15 == 0)
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
return number.to_s
end
end

7 tests, 7 assertions, 0 failures, 0 errors, 0 skips
Voorbeelduitkomst - next steps
➢ Elke individuele regel naar een aparte methode
abstraheren
➢ De complete lijst laten zien met het uitvoeren van een
bestand
➢ User Interface
Voorbeeldoplossing - stap 17
Itereren over 100 getallen:
fizz_buzz.rb:
class FizzBuzz
def self.print(number)
return "FizzBuzz" if (number % 15 == 0)
return "Fizz" if (number % 3 == 0)
return "Buzz" if (number % 5 == 0)
return number.to_s
end
end

(1..100).each{|number| puts FizzBuzz.print(number)}

console:
ruby fizz_buzz.rb
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
...etc

Weitere ähnliche Inhalte

Was ist angesagt?

PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to heroJeremy Cook
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnitMindfire Solutions
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmanndpc
 
Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...
Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...
Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...Ange Albertini
 
Антон Наумович, Система автоматической крэш-аналитики своими средствами
Антон Наумович, Система автоматической крэш-аналитики своими средствамиАнтон Наумович, Система автоматической крэш-аналитики своими средствами
Антон Наумович, Система автоматической крэш-аналитики своими средствамиSergey Platonov
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
Testes pythonicos com pytest
Testes pythonicos com pytestTestes pythonicos com pytest
Testes pythonicos com pytestviniciusban
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitMichelangelo van Dam
 

Was ist angesagt? (11)

PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...
Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...
Such a weird Processor: messing with opcodes (...and a little bit of PE) (Has...
 
Антон Наумович, Система автоматической крэш-аналитики своими средствами
Антон Наумович, Система автоматической крэш-аналитики своими средствамиАнтон Наумович, Система автоматической крэш-аналитики своими средствами
Антон Наумович, Система автоматической крэш-аналитики своими средствами
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Testes pythonicos com pytest
Testes pythonicos com pytestTestes pythonicos com pytest
Testes pythonicos com pytest
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 

Andere mochten auch (20)

Railsgirls presentation
Railsgirls presentationRailsgirls presentation
Railsgirls presentation
 
RailsGirls Switserland Presentation
RailsGirls Switserland PresentationRailsGirls Switserland Presentation
RailsGirls Switserland Presentation
 
Dangerous liaisons English
Dangerous liaisons EnglishDangerous liaisons English
Dangerous liaisons English
 
Testing in a microcontroller world
Testing in a microcontroller worldTesting in a microcontroller world
Testing in a microcontroller world
 
Ebps report 2013
Ebps report 2013Ebps report 2013
Ebps report 2013
 
PARA TI ESME TE QUIERO MUCHO
PARA TI ESME TE QUIERO MUCHOPARA TI ESME TE QUIERO MUCHO
PARA TI ESME TE QUIERO MUCHO
 
BIBLIOTECA VIRTUAL UA
BIBLIOTECA VIRTUAL UABIBLIOTECA VIRTUAL UA
BIBLIOTECA VIRTUAL UA
 
Lazzat2010
Lazzat2010Lazzat2010
Lazzat2010
 
Guia didàctica
Guia didàctica Guia didàctica
Guia didàctica
 
Badanie EKD - prezentacja nr 1
Badanie EKD - prezentacja nr 1Badanie EKD - prezentacja nr 1
Badanie EKD - prezentacja nr 1
 
Seminar report on a statistical approach to machine
Seminar report on a statistical approach to machineSeminar report on a statistical approach to machine
Seminar report on a statistical approach to machine
 
Http
HttpHttp
Http
 
Statistical machine translation
Statistical machine translationStatistical machine translation
Statistical machine translation
 
Excretion
ExcretionExcretion
Excretion
 
Health Hazads Due to Different Jobs
Health Hazads Due to Different JobsHealth Hazads Due to Different Jobs
Health Hazads Due to Different Jobs
 
Companies
CompaniesCompanies
Companies
 
чомучки
чомучкичомучки
чомучки
 
學承電腦補習班學員香草painter作品3
學承電腦補習班學員香草painter作品3學承電腦補習班學員香草painter作品3
學承電腦補習班學員香草painter作品3
 
Aplikasi perkantoran arni
Aplikasi perkantoran arniAplikasi perkantoran arni
Aplikasi perkantoran arni
 
Pendidikan anak menurut islam
Pendidikan anak menurut islamPendidikan anak menurut islam
Pendidikan anak menurut islam
 

Ähnlich wie Test Driven Development Workshop

Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.Esehara Shigeo
 
Introducing Swift - and the Sunset of Our Culture?
Introducing Swift - and the Sunset of Our Culture?Introducing Swift - and the Sunset of Our Culture?
Introducing Swift - and the Sunset of Our Culture?dankogai
 
Guildford Coding Dojo1
Guildford Coding Dojo1Guildford Coding Dojo1
Guildford Coding Dojo1thirstybear
 
Exploring type-directed, test-driven development: a case study using FizzBuzz
Exploring type-directed, test-driven development: a case study using FizzBuzzExploring type-directed, test-driven development: a case study using FizzBuzz
Exploring type-directed, test-driven development: a case study using FizzBuzzFranklin Chen
 
Test-driven Development (TDD)
Test-driven Development (TDD)Test-driven Development (TDD)
Test-driven Development (TDD)Bran van der Meer
 
What FizzBuzz can teach us about design
What FizzBuzz can teach us about designWhat FizzBuzz can teach us about design
What FizzBuzz can teach us about designMassimo Iacolare
 
Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a TDDrubocoptero
 
Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Software Craftsmanship Alicante
 
TDD - Test Driven Development - Java JUnit FizzBuzz
TDD - Test Driven Development - Java JUnit FizzBuzzTDD - Test Driven Development - Java JUnit FizzBuzz
TDD - Test Driven Development - Java JUnit FizzBuzzAlan Richardson
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzFranklin Chen
 
Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Sam Livingston-Gray
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming ProjectSage Jacobs
 
FUNctional programming in Python
FUNctional programming in PythonFUNctional programming in Python
FUNctional programming in Pythonknifeofdreams
 
Test Driven Development with Fizz Buzz by Brian Bayer
Test Driven Development with Fizz Buzz by Brian BayerTest Driven Development with Fizz Buzz by Brian Bayer
Test Driven Development with Fizz Buzz by Brian BayerQA or the Highway
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded cBenux Wei
 
Kata de TDD by Jordi Anguela
Kata de TDD by Jordi AnguelaKata de TDD by Jordi Anguela
Kata de TDD by Jordi AnguelaCodium
 
ATS language overview
ATS language overviewATS language overview
ATS language overviewKiwamu Okabe
 

Ähnlich wie Test Driven Development Workshop (20)

Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.Fizz and buzz of computer programs in python.
Fizz and buzz of computer programs in python.
 
Introducing Swift - and the Sunset of Our Culture?
Introducing Swift - and the Sunset of Our Culture?Introducing Swift - and the Sunset of Our Culture?
Introducing Swift - and the Sunset of Our Culture?
 
Guildford Coding Dojo1
Guildford Coding Dojo1Guildford Coding Dojo1
Guildford Coding Dojo1
 
Get Kata
Get KataGet Kata
Get Kata
 
Exploring type-directed, test-driven development: a case study using FizzBuzz
Exploring type-directed, test-driven development: a case study using FizzBuzzExploring type-directed, test-driven development: a case study using FizzBuzz
Exploring type-directed, test-driven development: a case study using FizzBuzz
 
Test-driven Development (TDD)
Test-driven Development (TDD)Test-driven Development (TDD)
Test-driven Development (TDD)
 
What FizzBuzz can teach us about design
What FizzBuzz can teach us about designWhat FizzBuzz can teach us about design
What FizzBuzz can teach us about design
 
Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a TDD
 
Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)
 
TDD - Test Driven Development - Java JUnit FizzBuzz
TDD - Test Driven Development - Java JUnit FizzBuzzTDD - Test Driven Development - Java JUnit FizzBuzz
TDD - Test Driven Development - Java JUnit FizzBuzz
 
Type-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzzType-Directed TDD in Rust: a case study using FizzBuzz
Type-Directed TDD in Rust: a case study using FizzBuzz
 
Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming Project
 
FUNctional programming in Python
FUNctional programming in PythonFUNctional programming in Python
FUNctional programming in Python
 
Test Driven Development with Fizz Buzz by Brian Bayer
Test Driven Development with Fizz Buzz by Brian BayerTest Driven Development with Fizz Buzz by Brian Bayer
Test Driven Development with Fizz Buzz by Brian Bayer
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded c
 
The Rule of Three
The Rule of ThreeThe Rule of Three
The Rule of Three
 
Kata de TDD by Jordi Anguela
Kata de TDD by Jordi AnguelaKata de TDD by Jordi Anguela
Kata de TDD by Jordi Anguela
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
 
Wtf per lineofcode
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcode
 

Kürzlich hochgeladen

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Test Driven Development Workshop

  • 2. Introductie ● Wat is TDD? ● Waarom TDD? ● Workshop
  • 3. Wat is TDD? Wikipedia: a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards
  • 4. Wat is TDD? Wikipedia: a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards
  • 5. Wat is TDD? Wikipedia: a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards
  • 6. Wat is TDD? Wikipedia: a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards
  • 9. De workshop - Coding Dojo regels Groepjes van twee Computer wisselt met elke stap Alle code moet getest zijn Er zijn meerdere oplossingen mogelijk Probeer eens iets nieuws
  • 10. De opdracht Toon een opeenvolgende rij van getallen Als een getal deelbaar is door 3, toon "Fizz" Als een getal deelbaar is door 5, toon "Buzz" Als een getal deelbaar is door 3 en 5, toon "FizzBuzz"
  • 12. Voorbeeldoplossing - stap 1 Schrijf een (falende) test: test_fizz_buzz.rb: require_relative "fizz_buzz" console: E require "test/unit" Finished tests in 0.000378s, 2642.4268 tests/s, 0.0000 assertions/s. class TestFizzBuzz < Test::Unit::TestCase 1) Error: test_number_3(TestFizzBuzz): NoMethodError: undefined method `print for FizzBuzz:Class test_fizz_buzz.rb:6:in `test_number_3' def test_number_3 assert_equal "Fizz", FizzBuzz.print(3) end end 1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
  • 13. Voorbeeldoplossing - stap 2 Schrijf de minimale code om de test te laten lukken: fizz_buzz.rb: class FizzBuzz def self.print(number) return "Fizz" if number == 3 end end console: . Finished tests in 0.000306s, 3266.2660 tests/s, 3266.2660 assertions/s. 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
  • 14. Voorbeeldoplossing - stap 3 Wat gebeurt er als we 6 meegeven? test_fizz_buzz.rb: class TestFizzBuzz < Test::Unit::TestCase def test_number_3 assert_equal "Fizz", FizzBuzz.print(3) end def test_number_6 assert_equal "Fizz", FizzBuzz.print(6) end end console: .F Finished tests in 0.000525s, 3808.0804 tests/s, 3808.0804 assertions/s. 1) Failure: test_number_6(TestFizzBuzz) [test_fizz_buzz.rb: 10]: <"Fizz"> expected but was <nil>. 2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
  • 15. Voorbeeldoplossing - stap 4 Herschrijf de code: fizz_buzz.rb: class FizzBuzz def self.print(number) return "Fizz" if (number % 3 == 0) end end console: .. Finished tests in 0.000342s, 5851.4436 tests/s, 5851.4436 assertions/s. 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
  • 16. Voorbeeldoplossing - stap 5 Schrijf de test voor nummer 5: test_fizz_buzz.rb: class TestFizzBuzz < Test::Unit::TestCase def test_number_5 assert_equal "Buzz", FizzBuzz.print(5) end end console: .F. Finished tests in 0.000589s, 5092.4794 tests/s, 5092.4794 assertions/s. 1) Failure: test_number_5(TestFizzBuzz) [test_fizz_buzz.rb: 14]: <"Buzz"> expected but was <nil>. 3 tests, 3 assertions, 1 failures, 0 errors, 0 skips
  • 17. Voorbeeldoplossing - stap 6 Schrijf de code voor nummer 5: fizz_buzz.rb: class FizzBuzz def self.print(number) return "Fizz" if (number % 3 == 0) return "Buzz" if number == 5 end end console: ... Finished tests in 0.000352s, 8522.3157 tests/s, 8522.3157 assertions/s. 3 tests, 3 assertions, 0 failures, 0 errors, 0 skips
  • 18. Voorbeeldoplossing - stap 7 Wat gebeurt er nu bij nummer 10? test_fizz_buzz.rb: class FizzBuzz < Test::Unit::TestCase def test_number_5 assert_equal "Buzz", FizzBuzz.print(5) end def test_number_10 assert_equal "Buzz", FizzBuzz.print(10) end end console: F... Finished tests in 0.000565s, 7083.0057 tests/s, 7083.0057 assertions/s. 1) Failure: test_number_10(TestFizzBuzz) [test_fizz_buzz.rb: 18]: <"Buzz"> expected but was <nil>. 4 tests, 4 assertions, 1 failures, 0 errors, 0 skips
  • 19. Voorbeeldoplossing - stap 8 Herschrijf de code: fizz_buzz.rb: class FizzBuzz def self.print(number) return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) end end console: .... Finished tests in 0.000387s, 10343.3474 tests/s, 10343.3474 assertions/s. 4 tests, 4 assertions, 0 failures, 0 errors, 0 skips
  • 20. Voorbeeldoplossing - stap 9 Schrijf de test voor 3 en 5: test_fizz_buzz.rb: class TestFizzBuzz < Test::Unit::TestCase def test_number_15 assert_equal "FizzBuzz", FizzBuzz.print(15) end end console: .F... Finished tests in 0.000618s, 8085.1594 tests/s, 8085.1594 assertions/s. 1) Failure: test_number_15(TestFizzBuzz) [test_fizz_buzz.rb: 22]: <"FizzBuzz"> expected but was <"Fizz">. 5 tests, 5 assertions, 1 failures, 0 errors, 0 skips
  • 21. Voorbeeldoplossing - stap 10 Schrijf de code voor 3 en 5: fizz_buzz.rb: class FizzBuzz def self.print(number) return "FizzBuzz" if number == 15 return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) end end console: ..... Finished tests in 0.000392s, 12763.0138 tests/s, 12763.0138 assertions/s. 5 tests, 5 assertions, 0 failures, 0 errors, 0 skips
  • 22. Voorbeeldoplossing - stap 11 Wat gebeurt er nu bij 30? test_fizz_buzz.rb: class TestFizzBuzz < Test::Unit::TestCase def test_number_15 assert_equal "FizzBuzz", FizzBuzz.print(15) end def test_number_30 assert_equal "FizzBuzz", FizzBuzz.print(30) console: ...F.. Finished tests in 0.000599s, 10010.2104 tests/s, 10010.2104 assertions/s. 1) Failure: test_number_30(TestFizzBuzz) [test_fizz_buzz.rb: 26]: <"FizzBuzz"> expected but was <"Fizz">. end end 6 tests, 6 assertions, 1 failures, 0 errors, 0 skips
  • 23. Voorbeeldoplossing - stap 12 Schrijf de code voor 30: fizz_buzz.rb: class FizzBuzz def self.print(number) return "FizzBuzz" if (number % 3 == 0) && (number && 5 == 0) return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) end end console: ...... Finished tests in 0.000423s, 14191.6775 tests/s, 14191.6775 assertions/s. 6 tests, 6 assertions, 0 failures, 0 errors, 0 skips
  • 24. Voorbeeldoplossing - stap 13 Refactor de code voor 30: fizz_buzz.rb: class FizzBuzz def self.print(number) return "FizzBuzz" if (number % 15 == 0) return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) end end console: ...... Finished tests in 0.000423s, 14191.6775 tests/s, 14191.6775 assertions/s. 6 tests, 6 assertions, 0 failures, 0 errors, 0 skips
  • 25. Voorbeeldoplossing - stap 14 Wat als we een foutje hadden gemaakt? fizz_buzz.rb: console: F.F.FF class FizzBuzz Finished tests in 0.000999s, 6007.5034 tests/s, 6007.5034 assertions/s. def self.print(number) return "FizzBuzz" if (number % 3 == 0) || (number % 5 == 0) return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) end end 1) Failure: test_number_10(TestFizzBuzz) [test_fizz_buzz.rb:18]: <"Buzz"> expected but was <"FizzBuzz">. 2) Failure: test_number_3(TestFizzBuzz) [test_fizz_buzz.rb:6]: <"Fizz"> expected but was <"FizzBuzz">. 3) Failure: test_number_5(TestFizzBuzz) [test_fizz_buzz.rb:14]: <"Buzz"> expected but was <"FizzBuzz">. 4) Failure: test_number_6(TestFizzBuzz) [test_fizz_buzz.rb:10]: <"Fizz"> expected but was <"FizzBuzz">. 6 tests, 6 assertions, 4 failures, 0 errors, 0 skips
  • 26. Voorbeeldoplossing - stap 15 Schrijf de test voor alle andere getallen: test_fizz_buzz.rb: console: ..F.... class TestFizzBuzz < Test::Unit::TestCase Finished tests in 0.000631s, 11091.4634 tests/s, 11091.4634 assertions/s. def test_number_2 assert_equal "2", FizzBuzz.print(2) end 1) Failure: test_number_2(TestFizzBuzz) [test_fizz_buzz.rb:30]: <"2"> expected but was <nil>. 7 tests, 7 assertions, 1 failures, 0 errors, 0 skips end
  • 27. Voorbeeldoplossing - stap 16 Schrijf de code voor alle andere getallen: fizz_buzz.rb: console: ....... class FizzBuzz Finished tests in 0.000520s, 13452.1220 tests/s, 13452.1220 assertions/s. def self.print(number) return "FizzBuzz" if (number % 15 == 0) return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) return number.to_s end end 7 tests, 7 assertions, 0 failures, 0 errors, 0 skips
  • 28. Voorbeelduitkomst - next steps ➢ Elke individuele regel naar een aparte methode abstraheren ➢ De complete lijst laten zien met het uitvoeren van een bestand ➢ User Interface
  • 29. Voorbeeldoplossing - stap 17 Itereren over 100 getallen: fizz_buzz.rb: class FizzBuzz def self.print(number) return "FizzBuzz" if (number % 15 == 0) return "Fizz" if (number % 3 == 0) return "Buzz" if (number % 5 == 0) return number.to_s end end (1..100).each{|number| puts FizzBuzz.print(number)} console: ruby fizz_buzz.rb 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 ...etc