Incremental Testing of Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1
Incremental Development Key idea: Build and test program one function at a time One method: – Start with “lower level” functions that do not call anything else Could build in order in which called, but not necessary – Implement functions that use tested methods If bug, most likely in function currently being developed – Finish with main program
Balloon Program Example Lowest level functions: – set_target() – get_velocity() – compute_miss(target, velocity, angle) – print_row(angle, miss_distance) Then build print_table(target, velocity) – Requires print_row be done first Then main program
Unit Testing Testing each function separately Requires – Function definition to be tested – Code to test the function Prompt for inputs (if any) Call function with inputs Print what it returns (if anything)
Unit Test Example
Unit Test Functions Can create “testing function” for each function – Should keep simple (just get input, call, and print) More complex testing function More likely it has bugs! – Can use to retest a function at any time Bugs suspected Function changed in future versions) Do not delete!
Unit Test Function Example Can call from main during testing – If necessary, comment out actual main program during testing