Open the test black box and write test cases from the perspective of code!

Black box testing only focuses on input and output, and treats the program as a black box. Without missing requirements, opening this black box and analyzing it from the perspective of code implementation can better understand test cases, help us improve test case design, and better improve test results.

This article systematically expounds the addition and multiplication operation procedures of unary polynomials in order to clarify the author's thinking.

Program function description: Design the program to calculate the product and sum of two unary polynomials respectively.

(1) Input: The input is divided into 2 lines. Each line first gives the number of non-zero items of the polynomial, and then enters a polynomial non-zero item coefficient and exponent in an exponentially descending manner. The numbers are separated by spaces

(2) Output: The output is divided into 2 lines, and the coefficients and exponents of the product polynomial and the non-zero term of the sum polynomial are respectively output in an exponentially descending manner. A zero polynomial should output 0,0

(3) Example:

picture

The result after performing the addition operation:

picture

(4) Program input and expected output

Input:

3 9 12 15 8 3 2

4 26 19 -4 8 -13 6 82 0

Output:

234 31 390 27 78 21 -36 20 -117 18 -60 16 -195 14 738 12 -12 10 1191 8 246 2

26 19 9 12 11 8 -13 6 3 2 82 0

1 program frame thinking

(1) The data structure uses a linked list: a linked list is more flexible than an array, but it is more error-prone, so it is more suitable for example in this article:

picture

(2) The program structure is as follows:

picture

i. Construct linked list and store data through Creat( ) function

ii. Perform multiplication with the multiple( ) function and return the result

iii. Use the add() function to perform addition and return the result

iv. Print the result through the PrintLink( ) function

Combined with program functions, multiple( ) may be more error-prone from the perspective of implementation difficulty. The specific implementation of each sub-function is not listed here, and will be described in detail later in conjunction with the test points.

2 test verification

1). Critical test

Enter the empty polynomial to run the program, and you can see that the output data has been confused.

picture

Analysis: After checking the code, it is found that because the null pointer scenario is not considered (the Next pointer of the head pointer is NULL), the pointer points to an unknown memory space, resulting in data exceptions. In addition, it needs to be explained that a null pointer will also cause a segmentation fault. This is a situation that we often encounter during the test process, especially in the early stage of the project: the pointer is null and causes the program to crash.

Solution: Increase the determination and processing of the Next of the head pointer being NULL.

picture

2). Equivalence class test

I. add( ) 

For the addition function, it needs to consider three basic cases: two univariate polynomials are compared, i. the coefficient of the former is greater than the latter ii. the coefficient of the former is equal to the latter iii. the coefficient of the former is smaller than the latter. The three branches of the If statement correspond to the three equivalence class test points.

picture

Compared with the two cases of i and iii, the problem is likely to occur when the coefficients of ii are equal: a special scenario needs to be considered here. When the added coefficient is 0, the relevant data will not be recorded, and the free( ) function needs to be used at the same time Release the corresponding memory space.

Therefore, when designing the corresponding test cases, it is necessary to consider the scenario where the coefficients add up to 0, and pay attention to the memory usage while judging the output.

picture

II. multiple( )

The multiplication function is more complicated than the addition function, and needs to be realized through two layers of while loops and insert() sub-functions:

picture

The two-layer while loop simulates the steps of multiplying two unary polynomials, and insert( ) inserts the result into the result linked list. Therefore, it is necessary to pay attention to the insert ( ) subfunction synchronously. The insert function is not directly implemented in multiple( ), which is the basic rule of programming: avoid code redundancy and increase flexibility. Insert ( ) part of the code is as follows:

picture

We can see that the test points here are similar to the add( ) function, and three situations need to be considered: the exponent is greater than, the exponent is less than, and the exponent is equal. When the exponents are equal, the coefficient addition operation will be triggered. When the result is 0, the memory needs to be released through the free() function.

picture

Therefore, when designing test cases, comprehensive consideration is required, do not miss the scene where the sum of coefficients is 0, and pay attention to memory usage simultaneously.

3). About the cycle 

Branches and loops are the two most common scenarios in program code. From the perspective of gray box testing, branches correspond to equivalence class division in test design, and loops can correspond to boundary values.

The program may be abnormal at the branch or loop, for example, if the loop is not exited normally, serious cases will cause the program to crash and the program will enter an infinite loop.

give a chestnut

Description: Perform a connection operation, artificially make the Sender process abnormal, Receiver will perform repeated reconnection attempts, click the connection cancel button, but Receiver still continues to perform reconnection.

Analysis: After clicking the cancel button, the loop is not terminated, and there is a code missing in the cancel operation, which causes the loop to not terminate normally.

3 little thoughts

Due to the low entry threshold for testing, test engineers need to prepare their own skills reserves to enhance their competitiveness. The author suggests improving from the following aspects:

1). Think more about everything and why? try to figure out the reason behind

2). The fact that the software version has no serious faults in the test does not mean that there are no serious faults. It may be that it has not been exposed in the experimental environment or there are test omissions. Therefore, it is still necessary to think more and use more in order to fully expose product defects.

3). Increase awareness of automation: Any repetitive operations can be replaced by automation. We can start little by little from windows bat and Linux sh scripts: accumulating sand to form a tower. However, cost-effectiveness must be considered. In the long run, if the time cost of automation is far greater than the cost of manual work, then maintain manual work.

4). Improve from the code level, master at least one programming language (such as C++), and have a deeper understanding of data structures. In spare time, cultivate the habit of brushing questions: you can do programming practice on websites such as Niuke.com, PTA, OpenJudge, etc., carefully analyze the reasons for Not Accepted and the test cases of programming websites, and reverse the loopholes in your own programming, and improve accordingly Own logical thinking ability, strengthen the logic and comprehensiveness of test case writing.

Finally: The complete software testing video tutorial below has been sorted out and uploaded, and friends who need it can get it by themselves [Guaranteed 100% free]

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

Guess you like

Origin blog.csdn.net/wx17343624830/article/details/132481461