Surely you've heard about Test-Driven Development, but do you use it? And do you like it? In this talk, we look at what TDD is, what the shortcomings of TDD are and what you could be doing instead.
1 of 15
Download to read offline
More Related Content
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?
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?
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)
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 dont know what youre 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