You are on page 1of 13

TDD.

Carlos Cárdenas @carcagi


Andrés Hugueth @andreshugueth

2021
TEST DRIVEN DEVELOPMENT.
Why test before you build, and
after.
The TDD Cicle

Plan the functionality Write a test or the Write a simple code


you want to tests for that that fails the tests.
implement. functionality.

Refactor code until it’s Make the code pass


Deploy using CI/CD pretty, usable, and
and automated tests. the tests you wrote.
easy to read.
TDD is not the holy grail.

TDD isn't perfect, of course. (Is anything?) TDD is difficult to use


on legacy codebases. Even with green-field systems, it takes a few
months of steady use to overcome the learning curve. Try it
anyway—although TDD benefits from other XP practices, it
doesn't require them. You can use it on almost any project.
But wait … What is XP?

Well, Extreme Programming is a software development agile


framework, it stresses customer satisfaction, instead of delivering
everything you could possibly want on some date far in the future this
process delivers the software you need as you need it.
Extreme Programming empowers you, developers, to confidently
respond to changing customer requirements, even late in the life
cycle. So planning is a lie.
Also, it encourages technical excellence, you can not deliver quickly
and frequently if you are not good in the technical aspect.
More Info on XP?

http://www.extremeprogramming.org/

https://www.agilealliance.org/glossary/xp/

https://agility.im/frequent-agile-question/what-is-extreme-program
ming/
Why TDD Works? (Some concepts)

Most IDEs check your syntax as you type, and some even compile
every time you save. The feedback loop is so fast that errors are
easy to find and fix. If something doesn't compile, there isn't much
code to check.

Every few minutes—as often as every 20 or 30 seconds—TDD


verifies that the code does what you think it should do. If
something goes wrong, there are only a few lines of code to check.
Mistakes are easy to find and fix.
Why TDD Works? (Some concepts)

Focus on the class' behavior, not its implementation. Programmers


write each test before the corresponding production code.

After TDD is finished, the tests remain. They're checked in with


the rest of the code, and they act as living documentation of the
code.
Why TDD Works? (Some concepts)

More importantly, programmers run all of the tests with (nearly)


every build, ensuring that code continues to work as originally
intended. If someone accidentally changes the code's behavior—
for example, with a misguided refactoring—the tests fail,
signalling the mistake.
Why TDD Works? (Some concepts)

- It’s not a waste of time, and save a lot of headache in the long
run.
- Pair programming (part of XP) is awesome.
- Reduce bugs, since all old code and new one is tested on each
iteration.
- Avoid complexity and code duplication.
- Quick feedback.
- Less time to market.
- No friday nights looking for bugs :)
NOW an example from
Andres H.
Learn More About TDD?

http://www.jamesshore.com/v2/books/aoad1/test_driven_develop
ment

http://www.jamesshore.com/v2/blog/2012/what-does-a-good-test-s
uite-look-like

http://www.jamesshore.com/v2/projects/lets-play-tdd

https://bitbar.com/blog/tdd-vs-bdd-vs-atdd-whats-the-right-choice-
for-you/
Thanks!

You might also like