SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
dpc
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
varuntaliyan
 

La actualidad más candente (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
 

Destacado

BIBLIOTECA VIRTUAL UA
BIBLIOTECA VIRTUAL UABIBLIOTECA VIRTUAL UA
BIBLIOTECA VIRTUAL UA
Katerin Gomez
 
Lazzat2010
Lazzat2010Lazzat2010
Lazzat2010
bonu_ns
 
Guia didàctica
Guia didàctica Guia didàctica
Guia didàctica
valcalde
 
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
Hrishikesh Nair
 

Destacado (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
 

Similar a Test Driven Development Workshop

The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming Project
Sage Jacobs
 

Similar a 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 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)
 
Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a 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
 

Último

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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