2. Test Driven
Development
Technique to design and develop software.
Practice part of the Extreme Programming methodology — XP
Based on three fundamental pillars.
3. TheThree
Pillars
Implement the exact
functionality of the software.
Reduce the number of defects
on the software – good quality
software
Produce modular and highly
reusable software.
4. When Doing
TDD
It’s not about just writing tests.
Translate use cases to examples.
Enough to describe the functionality without ambiguity.
Architecture will eventually emerge.
10. The Problem
Email validation mechanism
Neither empty nor null.
Has to contain an @ symbol
Has to belong to the .com, .net and .eduTDLs
Domain part can’t be 1 character long
All lowercase
Not contain numbers
Only _ . - symbols
19. In the end…
Components will behave exactly as we want.
Tests will be the documentation of our system.
Tests will break if changes compromise the system.
Design:
* We normally rush to start coding a solution without thinking much about the problem itself.
Exact functionality:
*
Examples:
Traditionally we will code based on use cases that describe the functionality with natural language.
Most of the times there is ambiguity expressed on them because of our language.
The idea is to generate as much examples as needed in order to remove all the ambiguity.
Architecture:
Will emerge at a higher level.
Depends on the type of application we are implementing and the technologies we are using.
Not that we should not think on architectural decisions or concerns, but we will postpone them until they are necessary.
Normally we design applications having several layers, transfer objects, factories and so on, but we may not need them.
Freedom to the developer. In some contexts, all has to be coded the same way.
Red
We’ll start writing a test for a certain example.
Why?
Compilation errors
Test failures
Green
We’ll implement the minimum possible functionality to cover the test case.
We’ll be tempted to write a bit more code. We should be strong.
Refactor
We’ll revisit our test and implementation code to see if we can improve something without changing the functionality.
What can we do?
Clean the code
Extract variables,
Reduce duplication
We should try to improve something, at least a bit. Sometimes it won’t be obvious, but we should spend a bit of time trying to refactor.
What does email validation mean for this specific context?
The fact is that validating an email, although sounds universal, may be very specific depending on the business context.
To write tests we need some technology support, which is presented as a Testing Framework.
Some languages and frameworks include some kind of unit testing support, such as …
But in any case there are several unit testing frameworks we can use to write tests for our code, even if the language does provide some testing support.
Just to name a few
Java
.NET
JavaScript