Software Testing Part 1: Motivation
Why is software testing important? For a variety of reasons, we sometimes need to change/extend/improve code. Take for instance we have a function func() which might look like
func(a, b) := 0.5 * a + 0.5 * b
Say we want to change this to
func(a, b) := (a + b)/2
As we have changed the implementation of func(), we need to check that every thing still works fine. To do it manually is laborious and for huge projects, where it is needed most, manual checking is very time consuming and error prone.
What can we do? This is where automated testing frameworks such as pytest really shines. We can set up a test for the above function. Of course we want to make sure it covers every case we can think of. In pseudo-code, it could look like
def func_test():
inputs = [[3, 5], [2, -4], [-3, -2]]
expected_outputs = [4, -1, -2.5]
for i in range(len(inputs)):
assert func(inputs[i,0], inputs[i,1]) == expected_outputs[i]
We have three sets of inputs and outputs above. But you can imagine a hundred sets of inputs and outputs covering every conceivable case you can think of.
All you need to do is launch the tests and if anything is off, it will be immediately flagged. The developer can then go fix this.
Furthermore, you can chain a couple of small tests together and test a larger set of components. Then chaining the large components together, you can test the whole system. All by launching the automated tests via a single clock.
This is standard best practice for software that works in any mission-critical environment. Here at OVECT, we use continuous automated testing for all our products so that our codebase is long-term maintainable.