Lecture Notes for Advanced Programming II

20 March 2001 - Testing


  1. an iritating e-mail
    I sent you my assignment, and I was hoping too see if it worked correctly.
    I dunno; what do you think?

    One of the more important skills you'll need to develop as a programmer and particularly as a software engineer is the ability to answer the questions "Is it correct? Does it work?" to the satisfaction of your colleagues, managers, customers, and others who may ask.

    I'm usually happy to answer a specific question, such as "My program does X if Y happens. Is that correct?" However the more general fishing expeditions, such as "Is my program right?", I'll leave to you to answer, at least up until the due date.

  2. what is testing

    1. breaking your code

  3. good testing

    1. through - test everything relevent

    2. reproducible

    3. easy to do - although not perhaps to set up

  4. write code to be testable

    1. write code in small pieces - deeply nested code is difficult to test

    2. write pieces with small function - complex functions are hard to understand

    3. make sure functions are well defined - what is wrong and right

    4. testable code is well structured

  5. write code to test well

    1. program for trouble - defensive programming; make it clea when you program's wandered into an erronious condition

    2. check procedure arguments

    3. check error returns

    4. assertions are your friend

    5. cover the impossible cases too

  6. test systematically

    1. test a piece at a time - build larger pieces from smaller ones

    2. start with small pieces - from the inside out

    3. know the expected output

    4. test for expected properties

    5. make sure you've tested everything

  7. generating test data

    1. a difficult thing to do

    2. test at the boundries

    3. test the legal and the illegal

    4. test at representative values

    5. test at volume - stress testing

  8. automate testing

    1. test it once, and test it twice and test it once again - regression testing; test after every change

    2. testing generates lots of data

    3. comparing results is tedious but important

    4. generate tests and data automatically

    5. know your tools - make, shell scripts, awk, sed, perl, tcl, . . .


This page last modified on 27 February 2001.