How to test a program which uses external files
All of these are things to think about when using an
external file with a program. Not all of them can be detected
in beginning programs. In that case, the program may crash.
If so, document it! That is a result! If you were supposed
to manage it so that the crash didn't happen, then you need
to fix your bug. If you were not specified to handle that
condition, it is still a case to be documented.
Using an external file for input
- Does the file exist? (another way to say it is
"do I have the name of the file correct?")
- Does the file exist but is empty?
- Does the file have the right number of lines?
(sometimes matters, sometimes doesn't) i.e. multiple of 10 lines, etc.
- Does the file have the right number of pieces of data on each line?
- Does the file have the right type of data?
This can be hard to tell in Python until you try to use a typecast on
the line input.
- What happens when the file data is exhausted? usually that is NOT a crash condition.
Using an external file for output
- Do you have room on the output device for the file that is
being created?
- Do you have permissions to write to it (the output device)?
- Do you have the correct path to write to it?
- Do you know the format desired for the output file?
(line breaks, alignment, spacing, etc.)
- Did the file get completely flushed to the output device?