What to Test?
Test all boundaries
Check upper & lower bounds of ALL buffers.
Ensure that a loop iterates for the given number of times.
Recursive functions:
– Consider all possible states of the data.
– Be sure about terminal condition.
Ensure that all conditional statements branch in the right direction
Test pre and post conditions
Assertions can be used to verify the necessary pre-conditions or post-conditions.
Pre and post conditions are simply assumptions about the state of required data in critical portions of the code.
Using assertions is just another way to test some of these assumptions.
Also,
Test the return values from all system calls and library functions. These values are returned for a reason. They indicate problems and error states that need to be handled.
Deal with all errors and anomalies.
Check the consistency of data and the stability of the program wherever possible.
How to Test?
Test simple parts first
Write a small portion of code (or a function) and test it before coding anything else.
This will reduce the amount of testing and debugging that you need when you finish writing the software.
Testing and debugging should go hand-in-hand and be a continuous process intertwined with writing the code.
Test the small portions first and gradually build your code step-by-step, testing and debugging at each and every step.
“Black Box” testing
– Here you are not concerned about the details of what a function or piece of code does.
– You should be concerned simply with whether it produces the correct results.
– Give the function controlled data and test the return values. Since you know what values you should receive you can test whether the function works with varying data.
– This is the type of testing you are doing when you use test harnesses.
Test interfaces between functions
– Each function provides an interface to another function and hides the details of what it does.
– This is one area that is susceptible to bugs because incorrect use may cause incorrect results.
– Black box testing would be appropriate to use here.
– Test all return values from functions and be sure to handle (and/or report) error conditions in a sane manner.
– Be sure that each function has the ability to test for applicable error conditions.
Test incrementally
– Write a function and test it before writing another or using it in another function.
– For larger functions, write a small portion of functional code and test it.
– When a function relies on other functions, combine the smaller functions into a larger function and test as a whole functional unit.
– Check for and handle error states.
– Black Box testing, again, would be appropriate.
No comments:
Post a Comment