Programming Practice – Testing

debugging — find the error when your program fail

testing — determined, systematic attempt to break a program you think should work

无标题.png

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:

  1. function read files—-test empty file, non-exist file
  2. except a text file—-test binary file
  3. except specific line of file—-test with huge line file, no line file, no line terminators
  4. add unusual case to variables and arrays in scaffold(out of bouns or uninternailized)
  5. change test case between testing
  6. don`t keep test/implement when there is a known bug
  7. check if output have all parameters of input
  8. add additonal output in code which may helpful locate bug
  9. know what output should be with different input
  10. keep record and old version

 

 

 

 

 

留下评论