Why TDD is very important and suitable for SCRUM Development Team?
If you are preparing for PSD 1 assessment and do not know what Code Coverage and TDD are, here you are:
https://www.scrum.org/Resources/PSD-Glossary
Yesterday, an junior developer asked me for help due to required coverage not being met. His questions:
Why TDD is very important and suitable for SCRUM?
Is it feasible to expect 100% code coverage?
Why TDD is very important and suitable for SCRUM?
First of all, it’s make sense to convert each user story to a test case. A test case should be defined to simulate users’ action, behavior, requirement, etc. When executable code is created to make the test pass subsequently, that mean pieces of code is almost ready.
Secondly, TDD will increase transparency of your code.
Basically, the Code Coverage should be 100% if you use TDD. Test coverage is a useful tool for finding untested parts of a codebase. Test coverage is of little use as a numeric statement of how good your tests are, but it can help you finding duplicated or unused code which always untested.
Sometime, untested code is due to your mistake on choosing code statements, expressions, scheme, etc.
For example, WHILE loop and FOR loop, those are very common sense for developers.
Really?
If there were lines of code:
for (int I = 0; i<5; i++)
{
bool success = DoSomething();
If (success)
Break;
}
If it was so lucky to get a success result at first try, what it would mean?
Yes, “i++” would be untested.
Let’s refactor it.
Int RetryTimes = 5;
int count = 0;
bool success=false;
while ((!success) &&(count<RetryTimes))
{
success = DoSomething();
}
Each line of code should be tested.
What’s the different? Just for high code coverage?
It help us to think about the different between FOR loop and WHILE loop.
FOR is for “Index Range” while you can break or continue according to predefined conditions.
WHILE is for “Condition” while you can set the maximum loops.
Just for your reference.