Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprising" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, article, or apparatus.
The technical solution of the present invention will be described in detail with specific examples. Several of the following embodiments may be combined with each other and some details of the same or similar concepts or processes may not be repeated in some embodiments.
The embodiment of the application provides a program testing method, which is applied to a scene of performing regression testing after function optimization or function error modification of a program, obtains a test case set with a missing test probability of the modified program, obtains a regression test case set formed by test cases with the missing test probability being larger than a preset probability, and tests the modified program by using the regression test case set. The scheme can reduce the test time and improve the test efficiency.
In the embodiment of the application, when testing is performed on an original program, namely an unmodified program, the testing is consistent with the existing implementation, and the written test case set is directly adopted for testing.
The newly added content in the embodiment of the application is that after the unmodified program is tested and the on-line operation is performed, the program needs to be modified, and before the modified program is tested, a test missing probability test case set M corresponding to the unmodified program is generated0The test case set of the test case with the test missing probability comprises the test cases and the test missing probability corresponding to the test cases. The specific generation mode is as follows:
obtaining a test case set for testing an unmodified program, estimating the probability of missing test for each test case in the test case set, and forming a test case set M with the probability of missing test corresponding to the unmodified program0。
The probability of missing test of the test case refers to the probability that no defect is found after the test case is executed, but the defect occurs after the test case is operated on line; the specific implementation of how to obtain the missing test probability of each test case is as follows:
referring to fig. 1, fig. 1 is a schematic flow chart illustrating a process of determining a probability of missed test for each test case in a test case set according to an embodiment of the present application. The method comprises the following specific steps:
step 101, a test case set for testing an unmodified program is obtained.
102, obtaining the probability of the statement covering the error, the probability of the error intermediate state and the probability of the output error result corresponding to each test case in the test case set.
And the probability of covering the error statement is the probability of covering the corresponding error statement when the test case test is executed.
In the embodiment of the present application, obtaining the probability of the statement that covers the error includes:
static scanning is carried out on the program, and an error statement is obtained;
in the process of executing each test case, recording executed sentences and unexecuted sentences in an inserting mode;
and determining that the probability that the test case is executed to the corresponding wrong statement is the probability that the test case covers the wrong statement.
Wherein, the static scanning of the program can use sonarQube to perform static scanning of the program (code); and checking whether the scanned error program is executed or not, and if the error program is covered, determining that the probability of covering the error statement in the execution of the corresponding error statement is 1, namely the probability of covering the error statement of the test case is 1.
The probability of the error intermediate state is the probability of the error intermediate state generated after the error sentence is executed.
In the embodiment of the present application, obtaining the probability of the occurrence of the erroneous intermediate state includes:
and acquiring the probability of the occurrence of the wrong intermediate state set for the test case.
And after the system is on-line once, the running case is checked back, and whether the error intermediate state is generated or not is checked from the code to obtain the probability of the error intermediate state. Or experience estimation is adopted for some specific scenes, and the probability of generating an error intermediate state is estimated through experience when a test case is written for verification on the assumption that a tester walks through the logic of a certain developed code.
The probability of the error intermediate state of the test case obtained in any way is set and stored, and the set value is directly obtained when the test case is used.
The probability of outputting the error result is the probability that the error statement generates an error intermediate state after being executed, and the output result is an error after the error intermediate state is executed.
In the embodiment of the present application, obtaining the probability of outputting the error result includes:
when the erroneous intermediate state result is used as calculability, the error probability of the intermediate state result is taken as the probability of outputting the erroneous result;
if the result variable of the intermediate state is faulty, and the result returned by the method is definitely wrong if the variable is taken as an entry of another method. That is, the probability of the intermediate state error is closely related to the probability of the output result, so that the probability of the output error result can be approximately equal to the probability of the intermediate state error result according to the error probability of the intermediate state result.
When the erroneous intermediate state result is used as one control branch of the control flow, the product of the probabilities of whether all the branch expressions are erroneous is used as the probability of outputting the erroneous result.
Control flow usage, which refers to the result of intermediate states, is one use of control flow.
When the value of the wrong intermediate state result is used in a branch statement conditional expression, a program execution path error results. The factor affecting the execution result is therefore whether the expressions of the branch statement execute incorrectly, so the product of the probabilities of whether all branch expressions are incorrect can be used as the probability of error of the output result.
The probability calculation mode of whether the branch expressions are wrong is that all the executed branch expressions are found firstly, after the system is on line, a certain use case is checked reversely to see that the use case executes a wrong program and is an intermediate state which generates errors, and then the value of the error intermediate state is judged whether to be executed by the branch statement expressions or not, and the probability is estimated.
And 103, determining that the test case missing probability is the product of the probability of the error covering statement, the probability of the error intermediate state and the probability of the output error result.
Thus, the 0 th modified program, that is, the test case set of the probability of missing test corresponding to the unmodified program is obtained.
The process of testing the modified program will be described in detail below with reference to the accompanying drawings.
Referring to fig. 2, fig. 2 is a schematic view illustrating a program testing process in the embodiment of the present application. The method comprises the following specific steps:
step 201, obtaining a missed test probability test case set M corresponding to the program modified for the Nth timeN。
The test case set can be determined to be directly used when needed, and can also be pre-estimated and stored, and the stored test case set with the probability of missing test can be directly obtained when in use.
In this embodiment, N is an integer not less than 0, and when N is 0, it refers to the program modified at 0 th time, that is, the test case set of the probability of missing test corresponding to the original program.
When N is 0, acquiring a test case set for testing an unmodified program, estimating the test missing probability of each test case in the test case set, and forming a test case set with the test missing probability corresponding to the unmodified program;
when N is 1, obtaining a test case set M of the test probability corresponding to the program modified for the 1 st time according to the type of the statement modified for the program for the 1 st time and the test case set of the test probability corresponding to the unmodified program1;
When N is an integer larger than 1, according to the type of the statement modified for the program for the (N-1) th time and the test-missing probability test case set M corresponding to the modified program for the (N-1) th timeN-1Obtaining a test case set M of the probability of missing test corresponding to the program modified for the Nth timeN。
Step 202, according to the type of the statement modified for the program at the N +1 th time, and MNDetermining a test case set M of the probability of missing test corresponding to the program modified for the (N + 1) th timeN+1。
The determination of the test case set of the test probability corresponding to the modified program according to the test case set of the test probability corresponding to the program before the modification is described in detail below with reference to the drawings.
The statement types include: operation statements and flow control statements;
the operation statement refers to a statement containing an operation symbol in java, such as an arithmetic operator, a valuation operator, a self-increment and self-decrement cloud operator, a logical operator and a ternary operator.
The flow control statement includes a sequential structure, a branch structure (if, switch), and a loop structure (for, while, do … while).
If the memories are consistent, if the memories are respectively stored in the stack memory and the heap memory, the memories are determined to be stored in different memories; if both are stored in stack memory, or both are stored in heap memory, then the memories are determined to be the same.
The java virtual machine memory comprises a heap memory, a stack memory and a program counter, wherein local variables are stored in the stack memory, a new object is stored in the heap memory, and the program counter stores byte code instructions for recording a program.
Referring to fig. 3, fig. 3 is a schematic flowchart of determining a test case set of the missed measure probability corresponding to the modified program in the embodiment of the present application. The method comprises the following specific steps:
step 301 determines the type of statement modified, and the storage location of the intermediate result.
Step 302, when the modified statement is an operation statement and the intermediate result is in the same memory, the M is executedNAs MN+1. The flow is ended.
The modified statement is an operation statement, and before and after modification, the intermediate result of the statement is executed in the same memory. Therefore, the test missing probability in the test missing case set corresponding to the program before modification can be approximately equal to the test missing probability corresponding to the modified test case.
Examples are as follows:
the modified statement is x, which is an operation statement, for example, x ═ a + b, and intermediate results generated by the programs before and after modification in executing the statement all exist in the same stack memory, and M is stored in the same stack memoryNAs MN+1That is, the probability of missing test for each test case is not changed.
Step 303, when the modified statement is an operation statement and the intermediate result is not in the same memory, MN+1The probability of missing test corresponding to the middle test case is 1 and MNThe difference of the missed test probabilities of the corresponding test cases. The flow is ended.
The modified statement is an operation statement, and before and after modification, intermediate results of executing the statement are stored in different memories. Therefore, the difference value of the missed measure probability in the missed measure case set corresponding to the program before modification and 1 can be used as the missed measure probability corresponding to the modified test case.
The method comprises the following specific steps: the statement before modification is an operation statement x ═ a + b, the value of a + b is stored in x, the program operation statement after modification is changed into y ═ a × b, the statement after modification does not assign x, assigns y, and the values stored in variables x and y are changed when the operation statement is executed. The probability of missing test of each test case corresponding to the modified program is as follows: 1-corresponding probability of missed measure before modification.
Step 304, when the type of the modified statement is a flow control statement, M is addedNAs MN+1。
When the modified statement is a flow control statement, the execution path before and after modification may change, but the testing validity of each test case on the modified statement can be reflected to a certain extent, and M is directly usedNAs MN+1That is, the probability of missing test for each test case is not changed.
In this step, M is determinedN+1During the process, the regression test set can be determined currently, and the regression test set can be stored, so that the program can be modified for the (N + 2) th time in the following to directly obtain the regression test case for determination.
Step 203, obtaining MN+1And forming a regression test case set by the test cases with the middle and missing test probability larger than the preset threshold value.
The setting of the preset threshold may be set according to actual needs, or empirically, such as setting 60%, which is not limited in the embodiments of the present application.
And filtering the test cases with the test missing probability not greater than the preset threshold value, so that part of the test cases can be reduced.
And 204, testing the program modified for the (N + 1) th time by using the regression test case set.
In the embodiment of the application, the probability of missing test after each use case is on line is evaluated to generate a test case missing probability use case set of the test use cases. And the test case set of the missed test probability is used as a basis to evaluate the modified program and execute the probability of the missed test of each test case. Through the two key points, the test cases with high occurrence rate of missing test are selected, and a new regression case set is generated, so that the number of the test cases in the regression test case set is reduced, the regression case set obtained by the method is used for testing the modified program, the test time can be shortened, and the test efficiency is improved.
Based on the same inventive concept, the embodiment of the application also provides a program testing device. Referring to fig. 4, fig. 4 is a schematic structural diagram of a program testing device in an embodiment of the present application. The device comprises: afirst acquisition unit 401, adetermination unit 402, asecond acquisition unit 403, and atest unit 404;
a first obtainingunit 401, configured to obtain a missing test probability test case set M corresponding to the nth modified programN(ii) a The test case set of the test case with the test missing probability comprises test cases and test missing probabilities corresponding to the test cases;
adetermination unit 402 for determining the type of the statement for program modification according to the (N + 1) th time, and M acquired by thefirst acquisition unit 401NDetermining a test case set M of the probability of missing test corresponding to the program modified for the (N + 1) th timeN+1;
A second obtainingunit 403 for obtaining M determined by the determiningunit 402N+1Test cases with the middle and missing test probability larger than a preset threshold value form a regression test case set;
thetesting unit 404 is configured to test the program modified at the (N + 1) th time by using the regression test case set acquired by the second acquiringunit 403.
Preferably, the apparatus further comprises: a storage unit;
the storage unit is configured to use the test case set M of the missed measure probability corresponding to the program modified for the (N + 1) th time determined by the determiningunit 402N+1And (5) storing.
Preferably, the first and second electrodes are formed of a metal,
afirst acquisition unit 401, in particular forWhen the missed measure probability test case set corresponding to the program modified for the Nth time is obtained, the method comprises the following steps: when N is 0, acquiring a test case set for testing an unmodified program, estimating the test missing probability of each test case in the test case set, and forming a test case set with the test missing probability corresponding to the unmodified program; when N is 1, obtaining a test case set M of the test probability corresponding to the program modified for the 1 st time according to the type of the statement modified for the program for the 1 st time and the test case set of the test probability corresponding to the unmodified program1(ii) a When N is an integer larger than 1, according to the type of the statement modified for the program for the (N-1) th time and the test-missing probability test case set M corresponding to the modified program for the (N-1) th timeN-1Obtaining a test case set M of the probability of missing test corresponding to the program modified for the Nth timeN。
Preferably, the first and second electrodes are formed of a metal,
the first obtainingunit 401 is specifically configured to obtain a test case set for testing an unmodified program, and when a test missing probability is estimated for each test case in the test case set, the obtaining unit includes: acquiring a test case set for testing an unmodified program; acquiring the probability of error covering sentences, the probability of error intermediate state occurrence and the probability of output error results corresponding to each test case in the test case set; and determining the probability of missing test of the test case as the product of the probability of the statement covering the error, the probability of the error intermediate state and the probability of outputting the error result.
Preferably, the first and second electrodes are formed of a metal,
a first obtainingunit 401, specifically configured to perform static scanning on a program and obtain an error statement; in the process of executing each test case, recording executed sentences and unexecuted sentences in an inserting mode; determining the probability that the test case is executed to the corresponding wrong statement as the probability that the test case covers the wrong statement; acquiring the probability of the occurrence of the wrong intermediate state set for the test case; when the erroneous intermediate state result is used as calculability, the error probability of the intermediate state result is taken as the probability of outputting the erroneous result; when the erroneous intermediate state result is used as one control branch of the control flow, the product of the probabilities of whether all the branch expressions are erroneous is used as the probability of outputting the erroneous result.
Preferably, the first and second electrodes are formed of a metal,
adetermination unit 402, in particular for the type of statement according to the N +1 th modification of the program, and MNDetermining a test case set M of the probability of missing test corresponding to the program modified for the (N + 1) th timeN+1And then, includes: when the type of the modified statement is an operation statement and the intermediate result is in the same memory, M is addedNAs MN+1(ii) a When the modified statement is an operation statement and the intermediate result is not in the same memory, MN+1The probability of missing test corresponding to the middle test case is 1 and MNThe difference value of the test missing probability of the corresponding test case; when the modified statement is a flow control statement, M is addedNAs MN+1。
The units of the above embodiments may be integrated into one body, or may be separately deployed; may be combined into one unit or further divided into a plurality of sub-units.
In another embodiment, an electronic device is also provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the program testing method when executing the program.
In another embodiment, a computer readable storage medium is also provided, having stored thereon computer instructions, which when executed by a processor, may implement the steps in the program test method.
Fig. 5 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention. As shown in fig. 5, the electronic device may include: a Processor (Processor)510, a communication Interface (Communications Interface)520, a Memory (Memory)530 and acommunication bus 540, wherein theProcessor 510, thecommunication Interface 520 and theMemory 530 communicate with each other via thecommunication bus 540.Processor 510 may call logic instructions inmemory 530 to perform the following method:
obtaining a test case set M of the probability of missing test corresponding to the program modified for the Nth timeN;
Type of statement modified for program according to N +1 th time, and MNDetermining a test case set M of the probability of missing test corresponding to the program modified for the (N + 1) th timeN+1;
Obtaining MN+1Test cases with the middle and missing test probability larger than a preset threshold value form a regression test case set;
testing the program modified for the (N + 1) th time by using the regression test case set;
the test case set with the test case missing probability comprises test cases and test cases corresponding to the test cases missing probability.
Furthermore, the logic instructions in thememory 530 may be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.