The moment you need to introduce some if-logic into a method, you jump over to write the test, but not before. This approach argues it is unnecessary overhead to write the test before you create the method because the method could be absent of any conditions, in the case it is comprised of calls to other methods.
Example - not needing a test
Example - needs at least 2 tests because there are 2 branches of code
The phrase Test-If-Development has one other benefit. That is,"If" you are doing "Development", you "Test". Period.
Read More »
Example - not needing a test
void populateContactInfo() {
populateName();
populateAddress();
populatePhone();
}
Example - needs at least 2 tests because there are 2 branches of code
void populateContactInfo() {
if (hasName) {
populateName();
}
else {
populateDefaultName();
}
populateAddress();
populatePhone();
}
The phrase Test-If-Development has one other benefit. That is,"If" you are doing "Development", you "Test". Period.