Software testing methods using a console application as an example
There are different kinds and types of software testing. In this short article I will try to outline the essence of such testing methods as: black box testing, gray box testing and white box testing, which are based on knowledge of the system being tested.
For a better understanding of these methods, I will talk about them using the example of testing a simple console application written in the Python programming language. This is a regular calculator that performs basic arithmetic operations. You can download the program file link.
So, Black Box testing. This method is also known as specification-based testing or behavioral testing. This technique does not assume access, either full or partial, to the system, i.e. it is based solely on working with the external interface of the program being tested. That is, we simply study the specification, write test scenarios according to it, launch the application and perform our tests.
![Application Interface. Performing a Positive Test Application Interface. Performing a Positive Test](https://habrastorage.org/getpro/habr/upload_files/149/3ed/d7b/1493edd7b64fbd8a5ecdfbb0551aa64f.png)
Grey Box testing is a combination of White Box and Black Box methods. This method involves partial access to the project code. This information can be obtained from documentation describing the operation of some system functions, from logs or, for example, from a corporate knowledge base that contains error codes and the reasons for their occurrence. All this provides a partial understanding of the system, even without access to the source code of the application. In our example, the source of this information will be a small user guide. From this tutorial we know that the available operation values are stored in the list correct_operations = [‘+’, ‘-‘, ‘*’, ‘/’, ‘%’, ‘**’, ‘log’]. These are addition, subtraction, multiplication, division, the percentage of the first number from the second, raising the first number to the power of the second, and the logarithm of the first number to the base of the second. Based on this knowledge, you can develop more effective test cases.
![Running a negative test case. Entering an unavailable operation Running a negative test case. Entering an unavailable operation](https://habrastorage.org/getpro/habr/upload_files/8ca/940/8c2/8ca9408c2fa1d0f07b9d024f8ee10121.png)
White Box or white box testing is a software testing method that involves full access to the project code, i.e. the internal structure, device and implementation of the system are known to the tester.
Let's consider one of the two white box testing techniques – control flow testing. With this technique, the execution paths of the program module code are determined, after which test cases are created and executed to cover these paths.
A path is a sequence of execution of statements starting at the input and ending at the output of a module.
The basis of control flow testing is control flow graphs. They allow you to document the control structure of a module. Code modules are transformed into graphs, the paths in these graphs are analyzed, and test cases are created from this analysis.
Let's consider control flow graph functions calc(first, second, oper) of the calculator under test.
For simplicity and convenience of describing the paths, we will remove the program code, mark each node with a letter and create routes that can form all possible linear paths in the program module.
![The resulting control flow graph The resulting control flow graph](https://habrastorage.org/getpro/habr/upload_files/7a3/fae/37e/7a3fae37e7a5ce41ce6f5a69d1484583.jpeg)
Thus we have nine routes:
ABJS
ACKS
ADLS
AEMQS
AEMRS
AFNS
AGOS
AHPS
AIS
Next, for each of these paths, test cases are created, the execution of which guarantees coverage of both all branches and all operators.
For a full study of this topic, I recommend reading Lee Copeland's book “A Practical Guide to Test Design”, and I hope that in this short article I managed to convey the essence of software testing using black, white and gray box methods.