Python testing, since 2021-06-06

(2021.06.06 Sat)
A carefull testing plan is an essential part of writing a program. While verifying the correctnss of a program over all possible inputs is usually infeasible, we should aim at executing the program on a representative subset of inputs. At the very minimum, we should make sure that every method of a class is tested at lease once (method coverage). Even better, each code statement in the program should be executed at lease once (statment coverage).

Programs often tend to fail on special cases of the input. Such cases need to be carefully identified and tested. For example, when testing a method that sorts (that is, puts in order) a sequence of integers, we should consider the following inputs:

  • The sequence has zero length (no elements).
  • The sequence has one element.
  • All the elements of the sequence are the same.
  • The sequence is already sorted.
  • The sequence is reverse sorted.

Notice special conditions for the structures used by the program. For instance, if we use a Python list to store data, we should make sure that boundary cases, such as inseting or removing at the beginning or end of the list, are properly handled.

The dependencies among the classes and functions of a program induce a hierarchy. Namely, a component A is above a component B in the hierarchy if A depends upon B, such as when function A calls function B, or function A relies on a parameter that is an instance of class B,

Reference

  1. M. T. Goodrich and etc, Data Structures & Algorithms in Python.

你可能感兴趣的:(Python testing, since 2021-06-06)