debugging — find the error when your program fail
testing — determined, systematic attempt to break a program you think should work

write test before coding is better because you know what you want to do
bug always happen out of “boundaries” (available range)
Systematic Testing
- test incrementally
- write part
- test it
- if pass; write more and testke
- repeat
- integrate as components are completed
- test simple part first
- test minimum needs of another program you are not test on
- except what happen if pass or if not
- keep record
- svn, readme file, comments
- if program handed an opposite-side function, check both sides
- preserve(保护)input property
- test scaffold: create a simple Structure for function testing
Test Coverage
- path coverage: the path of an input will travel inside the function
- check if all path available is traveled or not
- or need more path to handle unexcepted input
- branch coverage:
- if all branch(if/else statement) is covered?
- condition coverage
- if any condition is tested with test cases?
- thoroughness of testing
- statement
- functions
- path
- states
- input
- output
- test cases
- hand(human) generate
- computer generate
- random generate
Regression Testing
- compare the result from new version of function to old version and see if the test fail
- used in incremental(增加) development and maintenance
- because the previous function might give the right answer, means new version need to change
White / Black box testing
- White box testing
- test path through code
- Black Box Testing
- input and check output only
- functional testing
Testing at Different Stage
- unit test: test individual parts of the source code, kind of white box testing because you can actually see the path
- integration test: test combined modules(模块) and interface between groups
- system testing: test a combined system to evaluate the system`s compliance(依从) with its specific requirement, kind of black-box testing because you can not see the actual code.
Tips:
- function read files—-test empty file, non-exist file
- except a text file—-test binary file
- except specific line of file—-test with huge line file, no line file, no line terminators
- add unusual case to variables and arrays in scaffold(out of bouns or uninternailized)
- change test case between testing
- don`t keep test/implement when there is a known bug
- check if output have all parameters of input
- add additonal output in code which may helpful locate bug
- know what output should be with different input
- keep record and old version