to start with All Exit Criteria in mind. Then find the way to fulfill the Exit Criteria as efficiently as possible. - Have a design of the roadmap/ structure in terms of functions, procedures - before coding begins - The Unit test validates your design - The Unit test is “Documentation by example” in the sense that: (1) Documents the assumptions made by the developer (2) Is an Up to date , “Live”, and executable specification
Forces the complex areas to be identified and worked on first Agile Perspective: - Enables rapid change. - Gives confidence to allow rapid changes to code because breaking changes can be immediately detected. ( Regression) - Integration with Continuous Integration Tools
progress slower compared to traditional development, a period of adjustment required to gain experience - In the long term costs, progress will be more consistent and progress will be faster since changes can be made rapidly with more confidence. - Bugs are detected early on - defects detected later will be exponentially more costly to fix. - Speed of delivery Time TDD Traditional
1 ronald ronald 259 Apr 9 10:46 tests.py -rw-rw-r-- 1 ronald ronald 114 Apr 9 10:44 palindrome.py drwxrwxr-x 6 ronald ronald 4096 Apr 9 10:29 tddenv (tddenv) ronald@ronalddemo01:~/tdd$
input = 'noon' assert is_palindrome01(input) == True def test_function_accept_palindrome_world(): input = 'hello world' assert is_palindrome01(input) == False ~ Tests the following Exit Criteria: 1. “Noon” is a valid palindrome 2. “Hello world” is not a valid palindrome Nosetests will automatically discover functions that being with “test*” and run them as unit tests.
2 tests to test the positive case of a palindrome and assert a negative case. Does it now mean the code functions 100% - Not necessarily! - Unit tests can be considered a “safety net” but does not replace good design - Just because the test pass, does not necessarily follow the code functions 100% correctly - Value of tests depend on quality of unit tests, and coverage
for the following? - Ignore leading or trailing spaces? - Case insensitive palindrome? - Ignore spaces within the string? - Test to handle UTF characters?
Name Stmts Miss Cover ----------------------------------- palindrome.py 4 1 75% ---------------------------------------------------------------------- Ran 2 tests in 0.011s OK
verify functional Exit Criteria of the user story is fulfilled. - E.g “ Checking accounts have an overdraft limit of $500. As long as there are sufficient funds (e.g. -$500 or greater) within a checking account after a withdrawal has been made the withdrawal will be allowed.” - May also overlap with traditional “regression” testing.