07 Test-Driven Development
07 Test-Driven Development
302CEM
Test-Driven Development
Test-Driven Development (TDD)
Write the test before you write the code!
Use tests to communicate unusual circumstances in which the code should work.
Unit tests written by the developer.
Unit tests must always work at 100% in deployed code.
What is TDD?
Software Development process
Writing tests before the program
Writing enough code to satisfy the test
Refactoring
This leads to
First think about how to use the component
Next how to implement it
TDD enhances development
Components are easy to test and adapt
Why Use TDD?
Developers taking responsibility for the quality of their code, testing really isn't the
point, the point here is about
Responsibility, when you say it's done... is it done?
Can you go to sleep at night knowing the software that you've finished today
works and will help and isn't going to take anything away from people, that's the
point of developer testing...” (K. Beck, 2008)
Benefit of TDD
Why TDD?
Exam Question
Thinking about what is the goal first and then the implementations
Better understand the software behavior
Get quick feedback whether the software works
There is no code without a test
Use the written test as regression tests
More courage to refactor
Can save lots of time
How TDD Work
Solutions:
Tests written by a different person
Implement pair programming
TDD and Feature Branches
Unit tests are part of the feature development
Keep the tests with the code
Branch should contain both tests and code
Merge will bring both the code and tests into the develop branch
TDD and Bug-Fixing
Is the bug reproducible?
If not it can't be fixed
Write unit tests to reproduce the bug
Once the tests pass the bug is squashed
Merge the new unit tests and fixed code
Resolving Interdependencies
Module Dependency Challenges
Data Fare API
Persistence Calculation Interaction