SlideShare una empresa de Scribd logo
1 de 27
Journey to Unit Testing : A Lesson
Learned
Avicienna Ulhaq
@noxymon
Workin’ Ground Truth!
Program testing can be used
to show the presence of
bugs, but never to show
their absence!
(Dijkstra, 1970)
Edsger W. Dijkstra (1930 - 2002)
Notes on Structured Programming, Technological
University Eindhoven
Why ?
Rotten Code
Write-Ignore-Rot
Beck, Kent. 2 Hat Of Developer
Refactoring
When you're wearing the refactoring
hat, every change you make
preservers observable behavior,
keeps the tests green, and allows you
to make many small changes without
going near a debugger.
Adding function.
When you add function, however,
things are more open ended as you
will add tests and break existing
tests. The adding function hat is
more stressful and riskier, so it's
nice to wear the refactoring hat as
much as possible.
“All code is guilty until
proven it innocent”
Key of Agile Development
The heart of Scrum is a Sprint, a time-box of one month or less during
which a "Done", useable, and potentially releasable product
Increment is created.
(Shuterland and Schwaber)
What ?
It’s a Tools
Level of Testing
Does the whole system work?
Does our code work against
code we can’t change?
Do our objects do the right
thing, are they convenient to
work with?
How ?
Single Responsibility Principle
A class should have only one reason to change.
Function Always Do One Thing
Functions should do one thing. They should do it well. They should do it only.
Abstrak
Function Always Do One Thing
VIOLATESALLOWED
Dependecy Injection
Setup of dependency, is responsibility of the caller. Not The Dependent.
OrderService
DriverOjek
+ saveTarif()
<<use>>
DB
OrderService DriverOjek
Example :
Not Testable
Testable
Mocking Tools
mock objects are simulated objects that mimic the
behavior of real objects in controlled ways
● Verify behavior
● Mimic behavior
Use the DI Trick
Verify the behavior
FIRST Principle
● [F]ast ‒ imagine, every you stroke ctrl+s
● [I]solated ‒ avoid dependency to other unit test
● [R]epeatable ‒ it’s not truth, if not constant
● [S]elf-Validating ‒ avoid manual thing: setup, verification
● [T]imely ‒ later means never
Mimic the behavior
Mimic the behavior
Right Are the results right
B Are all the boundary conditions correct
I Can you check inverse relationship
C Can you cross-check result using others means
?
E Can you force error conditions to happen ?
P Are performance characteristics within bounds
?
Right-BICEP
3 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.
*iya, emang susah.
Further Reading
● Clean Code by Robert C Martin
● Pragmatic Unit Testing in Java 8 with JUnit by Jeff
Langr
● Google Clean Code Talks,
https://www.youtube.com/watch?v=wEhu57pih5w
● Three Laws of TDD,
https://www.youtube.com/watch?v=qkblc5WRn-U
● Uncle Bob Test Workshop,
https://www.youtube.com/watch?v=K7yR--yL0bc
Happy Code !

Más contenido relacionado

La actualidad más candente

Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
Foyzul Karim
 
Ohira icsm2012
Ohira icsm2012Ohira icsm2012
Ohira icsm2012
SAIL_QU
 

La actualidad más candente (14)

QA Fest 2017. Jeremias Rößler. Applying AI to testing
QA Fest 2017. Jeremias Rößler. Applying AI to testingQA Fest 2017. Jeremias Rößler. Applying AI to testing
QA Fest 2017. Jeremias Rößler. Applying AI to testing
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
 
TDD - Test Driven Dvelopment | Test First Design
TDD -  Test Driven Dvelopment | Test First DesignTDD -  Test Driven Dvelopment | Test First Design
TDD - Test Driven Dvelopment | Test First Design
 
TDD: Facts and Fallacies
TDD: Facts and FallaciesTDD: Facts and Fallacies
TDD: Facts and Fallacies
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
 
How to push a react js application in production and sleep better
How to push a react js application in production and sleep betterHow to push a react js application in production and sleep better
How to push a react js application in production and sleep better
 
Ohira icsm2012
Ohira icsm2012Ohira icsm2012
Ohira icsm2012
 
Giving automated tests the love they deserve at Listings
Giving automated tests the love they deserve at ListingsGiving automated tests the love they deserve at Listings
Giving automated tests the love they deserve at Listings
 
Page Objects - You're Doing it Wrong by Titus Fortner
Page Objects - You're Doing it Wrong by Titus FortnerPage Objects - You're Doing it Wrong by Titus Fortner
Page Objects - You're Doing it Wrong by Titus Fortner
 
Dot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel TettelarDot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel Tettelar
 
Tdd
TddTdd
Tdd
 
Quality Assurance
Quality Assurance Quality Assurance
Quality Assurance
 
The art of being an agile programmer
The art of being an agile programmerThe art of being an agile programmer
The art of being an agile programmer
 
Defect life cycle
Defect life cycleDefect life cycle
Defect life cycle
 

Similar a Journey to unit testing

Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
Babul Mirdha
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 

Similar a Journey to unit testing (20)

TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
[Rakuten TechConf2014] [G-4] Beyond Agile Testing to Lean Development
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
 
Unit Testing in Android
Unit Testing in AndroidUnit Testing in Android
Unit Testing in Android
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 

Más de Scrum Day Bandung

Más de Scrum Day Bandung (19)

How (can) Scrum and DevOps Walk Together to Build a High-Quality Product Deli...
How (can) Scrum and DevOps Walk Together to Build a High-Quality Product Deli...How (can) Scrum and DevOps Walk Together to Build a High-Quality Product Deli...
How (can) Scrum and DevOps Walk Together to Build a High-Quality Product Deli...
 
Mob Programming: What I've been Learning from Woody Zuill - Ivan Darmawan
Mob Programming: What I've been Learning from Woody Zuill - Ivan DarmawanMob Programming: What I've been Learning from Woody Zuill - Ivan Darmawan
Mob Programming: What I've been Learning from Woody Zuill - Ivan Darmawan
 
Journey toward Quality Assistance - Agustinus Verdy & Fachrul
Journey toward Quality Assistance - Agustinus Verdy & FachrulJourney toward Quality Assistance - Agustinus Verdy & Fachrul
Journey toward Quality Assistance - Agustinus Verdy & Fachrul
 
How Crucial a Performance Appraisal Practice Inside the Self-organizing Team?...
How Crucial a Performance Appraisal Practice Inside the Self-organizing Team?...How Crucial a Performance Appraisal Practice Inside the Self-organizing Team?...
How Crucial a Performance Appraisal Practice Inside the Self-organizing Team?...
 
Unconventional HR Practices - Sky You
Unconventional HR Practices - Sky YouUnconventional HR Practices - Sky You
Unconventional HR Practices - Sky You
 
Escaping the Drama Triangle - Christine Anna Rumawas
Escaping the Drama Triangle - Christine Anna RumawasEscaping the Drama Triangle - Christine Anna Rumawas
Escaping the Drama Triangle - Christine Anna Rumawas
 
How to Coach Difficult People - Rendy Aries Fajrin & Raka Dipura
How to Coach Difficult People - Rendy Aries Fajrin & Raka DipuraHow to Coach Difficult People - Rendy Aries Fajrin & Raka Dipura
How to Coach Difficult People - Rendy Aries Fajrin & Raka Dipura
 
Traits of A Successful Zombie Product Owner - Kevin Yudistira
Traits of A Successful Zombie Product Owner - Kevin YudistiraTraits of A Successful Zombie Product Owner - Kevin Yudistira
Traits of A Successful Zombie Product Owner - Kevin Yudistira
 
Be a survivor in transition process from BA chronicle to product mastery - Ar...
Be a survivor in transition process from BA chronicle to product mastery - Ar...Be a survivor in transition process from BA chronicle to product mastery - Ar...
Be a survivor in transition process from BA chronicle to product mastery - Ar...
 
How to Successfully Increase Agility in Your Organization by being a Silo Mas...
How to Successfully Increase Agility in Your Organization by being a Silo Mas...How to Successfully Increase Agility in Your Organization by being a Silo Mas...
How to Successfully Increase Agility in Your Organization by being a Silo Mas...
 
The Secret Life of Product Owner - Linawaty Dwi Halianto
The Secret Life of Product Owner - Linawaty Dwi HaliantoThe Secret Life of Product Owner - Linawaty Dwi Halianto
The Secret Life of Product Owner - Linawaty Dwi Halianto
 
Enhance Your Business with Agile Contract & Procurement - Yusuf Kurniawan
Enhance Your Business with Agile Contract & Procurement  - Yusuf KurniawanEnhance Your Business with Agile Contract & Procurement  - Yusuf Kurniawan
Enhance Your Business with Agile Contract & Procurement - Yusuf Kurniawan
 
Scrum Around the World - Scrum Day Bandung
Scrum Around the World - Scrum Day BandungScrum Around the World - Scrum Day Bandung
Scrum Around the World - Scrum Day Bandung
 
Managing Technical Debt - Scrum Day Bandung
Managing Technical Debt - Scrum Day BandungManaging Technical Debt - Scrum Day Bandung
Managing Technical Debt - Scrum Day Bandung
 
Data Driven Product Management
Data Driven Product ManagementData Driven Product Management
Data Driven Product Management
 
Path to Agility at DOKU - Scrum Day Bandung
Path to Agility at DOKU - Scrum Day BandungPath to Agility at DOKU - Scrum Day Bandung
Path to Agility at DOKU - Scrum Day Bandung
 
Developing the Midtrans - Scrum Day Bandung
Developing the Midtrans - Scrum Day BandungDeveloping the Midtrans - Scrum Day Bandung
Developing the Midtrans - Scrum Day Bandung
 
Fixed Price Contract is a Big Lie and Unethical - Scrum Day Bandung
Fixed Price Contract is a Big Lie and Unethical - Scrum Day BandungFixed Price Contract is a Big Lie and Unethical - Scrum Day Bandung
Fixed Price Contract is a Big Lie and Unethical - Scrum Day Bandung
 
BCA Executive Agile - Scrum Day Bandung
BCA Executive Agile - Scrum Day BandungBCA Executive Agile - Scrum Day Bandung
BCA Executive Agile - Scrum Day Bandung
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
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...
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Journey to unit testing

  • 1. Journey to Unit Testing : A Lesson Learned Avicienna Ulhaq @noxymon
  • 3. Program testing can be used to show the presence of bugs, but never to show their absence! (Dijkstra, 1970) Edsger W. Dijkstra (1930 - 2002) Notes on Structured Programming, Technological University Eindhoven
  • 6. Beck, Kent. 2 Hat Of Developer Refactoring When you're wearing the refactoring hat, every change you make preservers observable behavior, keeps the tests green, and allows you to make many small changes without going near a debugger. Adding function. When you add function, however, things are more open ended as you will add tests and break existing tests. The adding function hat is more stressful and riskier, so it's nice to wear the refactoring hat as much as possible.
  • 7. “All code is guilty until proven it innocent”
  • 8. Key of Agile Development The heart of Scrum is a Sprint, a time-box of one month or less during which a "Done", useable, and potentially releasable product Increment is created. (Shuterland and Schwaber)
  • 11. Level of Testing Does the whole system work? Does our code work against code we can’t change? Do our objects do the right thing, are they convenient to work with?
  • 12. How ?
  • 13. Single Responsibility Principle A class should have only one reason to change.
  • 14. Function Always Do One Thing Functions should do one thing. They should do it well. They should do it only. Abstrak
  • 15. Function Always Do One Thing VIOLATESALLOWED
  • 16. Dependecy Injection Setup of dependency, is responsibility of the caller. Not The Dependent. OrderService DriverOjek + saveTarif() <<use>> DB OrderService DriverOjek
  • 18. Mocking Tools mock objects are simulated objects that mimic the behavior of real objects in controlled ways ● Verify behavior ● Mimic behavior
  • 19. Use the DI Trick
  • 21. FIRST Principle ● [F]ast ‒ imagine, every you stroke ctrl+s ● [I]solated ‒ avoid dependency to other unit test ● [R]epeatable ‒ it’s not truth, if not constant ● [S]elf-Validating ‒ avoid manual thing: setup, verification ● [T]imely ‒ later means never
  • 24. Right Are the results right B Are all the boundary conditions correct I Can you check inverse relationship C Can you cross-check result using others means ? E Can you force error conditions to happen ? P Are performance characteristics within bounds ? Right-BICEP
  • 25. 3 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. *iya, emang susah.
  • 26. Further Reading ● Clean Code by Robert C Martin ● Pragmatic Unit Testing in Java 8 with JUnit by Jeff Langr ● Google Clean Code Talks, https://www.youtube.com/watch?v=wEhu57pih5w ● Three Laws of TDD, https://www.youtube.com/watch?v=qkblc5WRn-U ● Uncle Bob Test Workshop, https://www.youtube.com/watch?v=K7yR--yL0bc

Notas del editor

  1. Untuk mencapai poin [F]ast ‒ imagine, every you stroke ctrl+s [I]solated ‒ avoid dependency to other unit test [R]epeatable ‒ it’s not truth, if not constant, Dibutuhkan other skills of mocking : mimic bheavior
  2. Untuk melakukan mimic beheavior, mockito menyediakan static function when().thenreturn().
  3. So, out test will be like :
  4. boundary conditions : error json inverse relationship : For mathematic computations, this is often the case: you can verify division with multiplication, addition with subtraction, and so on. cross-check result using others means : pembukuan di akunting, atau order di amount oracle sama postgre force error conditions : throw expection using mock performance characteristics : profiling test
  5. Conformance : email format Ordering :