2.3 - Producing Robust Programs (Part 2)
Testing Programs
- Testing is an essential part of defensive design. It helps find errors and bugs,
ensures that the program behaves as expected, helps prevent security vulnerabilities,
and makes sure that the program solves the problem at hand.
- The two different types of testing are iterative and final testing.
Iterative Testing
- Iterative testing is a process of testing the program as it is being developed,
often in small increments or iterations.
- It helps identify errors and bugs early in the development process, allowing
for fixes to be made before the program is released.
- It is important to note that iterative testing should be done on a small
subset of the program, as it is easier to identify errors and bugs in a smaller
scope.
Final Testing
- Final testing is a process of testing the program after it has mostly been developed
and refined.
- It helps ensure that the program behaves as expected and meets the requirements
of the users.
- Final testing checks the program against real data, including normal data, but also
boundary and erroneous data.
- It is important to note that final testing should be done on a larger subset
of the program, as it is more difficult to identify errors and bugs in a larger
scope.
- Final testing is often called 'Alpha' or 'Beta' testing, depending on the stage
of development.
Identifying syntax and logic errors
- Syntax and logic errors are types of errors that occur when the program
is not written correctly.
- They can be caused by typos, incorrect indentation, or incorrect use of
operators or keywords.
- Syntax and logic errors can be identified by running the program and
checking for error messages or unexpected behavior.
- Syntax errors are errors which break the grammatical rules of the programming language
and stop it from being run/translated.
- Logic errors are errors which produce unexpected output.
Example:
Before:
Some errors have been picked up by the IDE.
After:
There are no underlined errors.
Selecting and using suitable test data
- There are three main categories of test data: boundary, erroneous, and normal.
- Boundary data is data that is outside the expected range of values, such as
extremely high or low numbers.
- Erroneous data is data that is incorrect or unexpected, such as strings that
contain invalid characters or numbers that are not in the correct format.
- Normal data is data that is within the expected range of values, such as
numbers that are within a certain range or strings that are in the correct format.
- Test data should be selected based on the requirements of the program,
ensuring that it covers all possible scenarios and edge cases.
- There is also a fourth extra category, invalid, which is data that is not valid
for the program, such as if a number is too large.