SlideShare a Scribd company logo
Is your code ready for testing?
Ralph Ligtenberg
September 20, 2018
Ralph Ligtenberg
Tech Lead @ Travix
.Net/C#, Go, Google Cloud Platform
twitter.com/prutswonder
travix.io/@prutswonder
linkedin.com/in/ralphligtenberg
Who am I?
What is Test-Driven Development (TDD)?
A software development process that encourages developers to
write tests of their code before actually writing the code itself.
1. Write a test
2. Run tests to see it fail (RED)
3. Write just enough code to pass test
4. Run tests to see it succeed (GREEN)
5. REFACTOR code to make it right
6. Repeat!
How does TDD work?
(cue for demo)
Does TDD work for you?
Pros
● Makes you write code that you need
● Code coverage is high
● End solution is guaranteed to work
Cons
● Feels more like writing tests than writing code
● Easy to depart from the straightforward solution
● Can easily produce unmaintainable code
Does TDD work for you?
Write code first,
create tests later
What about an alternative?
● Make sure your code is SOLID
● Use “pure” functions
● Isolate code that use data sources
● Avoid unnecessary code: YAGNI
Ensure your code is testable
1. Write a piece of code your way
2. Write a test to cover a part of your code
3. Compromise your code
4. Run tests to see it fail (RED)
5. Restore your code
6. Run tests to see it succeed (GREEN)
7. Repeat (from step 2) until your code is covered
Test-ready development (TRD)
(another cue for demo)
Will TRD work for you?
Pros
● Focus is on code, not on writing tests
● Lets you write code your way
● Requires less refactoring
Cons
● Writing tests can be arbitrary
● Less effective if you don’t know what you’re doing
● Can lead to incorrect tests
Will TRD work for you?
TDD or TRD? Which one should I pick?
Exploratory code creation
→ Use TDD
Fixed path code creation
→ Use TRD
Thank you!

More Related Content

PDF
Performance profiling and testing of symfony application 2
PDF
Effectively Reuse the Code Between PHP Projects
PPTX
Importance of the quality of code
PDF
Tdd 왜 배우기 어려운가
PDF
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
PDF
Mutation testing pixels camp 2019
PDF
PHPUnit with Magento
PDF
Quick Intro to Clean Coding
Performance profiling and testing of symfony application 2
Effectively Reuse the Code Between PHP Projects
Importance of the quality of code
Tdd 왜 배우기 어려운가
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
Mutation testing pixels camp 2019
PHPUnit with Magento
Quick Intro to Clean Coding

What's hot (20)

PDF
The art of being an agile programmer
PDF
Writing Tests with the Unity Test Framework
PDF
Tdd presentation
PPT
Test-Driven Development
PPT
Test Driven Development
PPT
Test-Driven Development
PDF
Test Driven Development en Go con Ginkgo y Gomega
PDF
Software Analysis using Natural Language Queries
PDF
Let linguistics guide software analysis
PPTX
Let's Explore C# 6
PDF
Coding Dojo: Naming with Dices (2021)
PDF
Five steps towards your testing dream
ODP
Automated Tests for Android apps
PDF
Achieving quality with tools case study
PDF
Java User Groups in Austria (2013)
PDF
Why and how to keep your code quality
PDF
How ANDROID TESTING changed how we think about Death
PPTX
Creating a reasonable project boilerplate
PDF
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
PPTX
Xp2007
The art of being an agile programmer
Writing Tests with the Unity Test Framework
Tdd presentation
Test-Driven Development
Test Driven Development
Test-Driven Development
Test Driven Development en Go con Ginkgo y Gomega
Software Analysis using Natural Language Queries
Let linguistics guide software analysis
Let's Explore C# 6
Coding Dojo: Naming with Dices (2021)
Five steps towards your testing dream
Automated Tests for Android apps
Achieving quality with tools case study
Java User Groups in Austria (2013)
Why and how to keep your code quality
How ANDROID TESTING changed how we think about Death
Creating a reasonable project boilerplate
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Xp2007
Ad

Similar to Is your code ready for testing? (20)

ODP
Effective TDD - Less is more
PPTX
Test-Driven Development
PPTX
TDD in Agile
PPTX
Test Driven Development
PPTX
Test Driven Development - a gentle introduction
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PDF
Test Driven Development Methodology and Philosophy
PPTX
Test-Driven Development
PPTX
Understanding TDD - theory, practice, techniques and tips.
PPTX
TDD - Seriously, try it! - Bucarest Tech Week
PPTX
An Introduction To Software Development - Test Driven Development, Part 1
PPT
Introduction to Test Driven Development
PPTX
{10.0} Test Driven Development.pptx
PPTX
TDD - Seriously, try it! - Opensouthcode
PPTX
Test Driven Development on Android (Kotlin Kenya)
PPTX
TDD - Seriously, try it - Codemotion (May '24)
PPTX
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
PPTX
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
Effective TDD - Less is more
Test-Driven Development
TDD in Agile
Test Driven Development
Test Driven Development - a gentle introduction
TDD and Simple Design Workshop - Session 1 - March 2019
Test Driven Development Methodology and Philosophy
Test-Driven Development
Understanding TDD - theory, practice, techniques and tips.
TDD - Seriously, try it! - Bucarest Tech Week
An Introduction To Software Development - Test Driven Development, Part 1
Introduction to Test Driven Development
{10.0} Test Driven Development.pptx
TDD - Seriously, try it! - Opensouthcode
Test Driven Development on Android (Kotlin Kenya)
TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Understanding_Digital_Forensics_Presentation.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MYSQL Presentation for SQL database connectivity

Is your code ready for testing?

  • 1. Is your code ready for testing? Ralph Ligtenberg September 20, 2018
  • 2. Ralph Ligtenberg Tech Lead @ Travix .Net/C#, Go, Google Cloud Platform twitter.com/prutswonder travix.io/@prutswonder linkedin.com/in/ralphligtenberg Who am I?
  • 3. What is Test-Driven Development (TDD)? A software development process that encourages developers to write tests of their code before actually writing the code itself.
  • 4. 1. Write a test 2. Run tests to see it fail (RED) 3. Write just enough code to pass test 4. Run tests to see it succeed (GREEN) 5. REFACTOR code to make it right 6. Repeat! How does TDD work?
  • 6. Does TDD work for you?
  • 7. Pros ● Makes you write code that you need ● Code coverage is high ● End solution is guaranteed to work Cons ● Feels more like writing tests than writing code ● Easy to depart from the straightforward solution ● Can easily produce unmaintainable code Does TDD work for you?
  • 8. Write code first, create tests later What about an alternative?
  • 9. ● Make sure your code is SOLID ● Use “pure” functions ● Isolate code that use data sources ● Avoid unnecessary code: YAGNI Ensure your code is testable
  • 10. 1. Write a piece of code your way 2. Write a test to cover a part of your code 3. Compromise your code 4. Run tests to see it fail (RED) 5. Restore your code 6. Run tests to see it succeed (GREEN) 7. Repeat (from step 2) until your code is covered Test-ready development (TRD)
  • 12. Will TRD work for you?
  • 13. Pros ● Focus is on code, not on writing tests ● Lets you write code your way ● Requires less refactoring Cons ● Writing tests can be arbitrary ● Less effective if you don’t know what you’re doing ● Can lead to incorrect tests Will TRD work for you?
  • 14. TDD or TRD? Which one should I pick? Exploratory code creation → Use TDD Fixed path code creation → Use TRD