It is tedious, slow and error-prone to test correctness of program manually. This article is an introduction, how to make this process as simple as a hit of one button, very fast and precise.
In the last issue about Iterative Divide & Conquer we have found out, how it is tedious to manually check that our program works correctly.
We have concluded, that it is tedious and slow to manually check that the output of our
Mitigating human error-proneness via automation
Let’s get back to our example from the previous issue:
1 2 3 4 5
What if we could ask our computer to run
english_integer_in_tens function with provided arguments and check that the output is exactly what we provided in a comment?
Let’s try to put it in pseudo-code:
If we run that code, of course, we will get some sort of compilation error, or runtime error (depending on the programming language), because function
equal is not defined yet. Let’s define it! Presumably, it should be comparing left argument with right argument and printing something useful on the screen.
1 2 3 4 5 6 7
If we run the program after defining this function we will get:
If we were to break the function
english_integer_in_tens’s implementation, we might get something like:
Making automation nicer
Having all this output every time we import our small library in any application going to the standard output would be annoying to say the least. How about separating the test automation from the library?
Let’s extract all our testing
1 2 3 4 5 6 7 8 9
Running only this separate file will produce expected output:
1 2 3 4 5
Importing or running directly our original library will not produce any output. This is much nicer.
Thank you for reading!
Today we have made our testing:
- easier: hit of one button, or one command on the terminal;
- faster: from minutes of manual verification to milliseconds of automated checks;
- preciser: automated checks can’t make a mistake, if we have something except
OK- we have an error, if everything is
OK- the program is working correctly;
- better feedback cycle: we can see if our change is correct in the matter of 1-2 seconds after making this change.
Next time we will build a fully-functional mini testing framework. Stay tuned!