[go: up one dir, main page]

CN118093352A - Test case generation method, device, equipment, medium and product - Google Patents

Test case generation method, device, equipment, medium and product Download PDF

Info

Publication number
CN118093352A
CN118093352A CN202211430311.2A CN202211430311A CN118093352A CN 118093352 A CN118093352 A CN 118093352A CN 202211430311 A CN202211430311 A CN 202211430311A CN 118093352 A CN118093352 A CN 118093352A
Authority
CN
China
Prior art keywords
test
unit
parameters
tested
program
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211430311.2A
Other languages
Chinese (zh)
Inventor
曹紫光
高玉军
毛雪
刘冠成
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Douyin Vision Co Ltd
Original Assignee
Douyin Vision Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Douyin Vision Co Ltd filed Critical Douyin Vision Co Ltd
Priority to CN202211430311.2A priority Critical patent/CN118093352A/en
Publication of CN118093352A publication Critical patent/CN118093352A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the disclosure provides a test case generation method, a device, equipment, a medium and a product. The test case generation method may include: analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested; determining a unit to be tested corresponding to the change function according to the change function and a calling function corresponding to the change function; the tested unit is the smallest program module participating in the test in the program to be tested; and generating the test case of the tested unit based on the case generation strategy. The technical problem that the test case generation is too low is solved.

Description

Test case generation method, device, equipment, medium and product
Technical Field
The embodiment of the disclosure relates to the technical field of computers, in particular to a test case generation method, a device, equipment, a medium and a product.
Background
In computer programming, unit Testing (Unit Testing) may also be referred to as a test module, which may be a test effort to verify the correctness of a program module. A test unit may refer to the smallest testable component in an application of a single program, function, procedure, etc., and may also be referred to as a unit under test. In the unit test, when a program module is actually tested, a test case is generally used to test a certain execution branch of a test unit in an application program. One test unit may include at least one execution branch and the test results of the test unit typically use code coverage to gauge the quality of the test results. Therefore, in order to more comprehensively test the codes in the test unit and obtain higher code coverage, a larger number of test cases need to be generated for the test unit.
At present, test cases are generally written manually, but as the complexity of application programs increases, more test cases need to be written to ensure the code coverage rate of tested units, so that the generation efficiency of the test cases is lower.
Disclosure of Invention
The embodiment of the disclosure provides a test case generation method, a device, equipment, a medium and a product, which are used for solving the problem of low test case generation efficiency caused by manually writing test cases.
In a first aspect, an embodiment of the present disclosure provides a test case generating method, including:
Analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
Determining a unit to be tested corresponding to the change function according to the change function and a calling function corresponding to the change function; the tested unit is the smallest program module participating in test in the program to be tested;
Based on the case generation policy, a test case of the unit under test is generated.
In a second aspect, an embodiment of the present disclosure provides a test case generating apparatus, including:
the program analysis unit is used for analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
The call analysis unit is used for determining a tested unit corresponding to the change function according to the change function and a call function corresponding to the change function; the tested unit is the smallest program module participating in test in the program to be tested;
And the use case generating unit is used for generating the test use case of the tested unit based on the use case generating strategy.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a processor and a memory;
The memory stores computer-executable instructions;
The processor executes computer-executable instructions stored in the memory to cause the at least one processor to perform the test case generating method of the first aspect and the various possible designs of the first aspect as described above.
In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium having stored therein computer-executable instructions that, when executed by a processor, implement the test case generating method of the first aspect and the various possible designs of the first aspect as described above.
In a fifth aspect, embodiments of the present disclosure provide a computer program product comprising a computer program which, when executed by a processor, implements the test case generation method of the above first aspect and the various possible designs of the first aspect.
According to the technical scheme provided by the embodiment, the change function which is changed in code relative to the original program can be obtained through analysis from the program to be tested, and the unit to be tested is determined according to the change function and the calling function corresponding to the change function. The unit under test may refer to the program module of the program under test that is least involved in the test. The rapid positioning of the tested unit can be realized by changing the function, the test case of the tested unit is generated by using the case generation strategy, and the generation efficiency and accuracy of the test case are improved.
Drawings
In order to more clearly illustrate the embodiments of the present disclosure or the solutions in the prior art, a brief description will be given below of the drawings that are needed in the embodiments or the description of the prior art, it being obvious that the drawings in the following description are some embodiments of the present disclosure, and that other drawings may be obtained from these drawings without inventive effort to a person of ordinary skill in the art.
FIG. 1 is a diagram of an application network architecture for a test case generation method provided by an embodiment of the present disclosure;
FIG. 2 is a flow chart of one embodiment of a test case generation method provided by embodiments of the present disclosure;
FIG. 3 is a flow chart of one embodiment of a test case generation method provided by an embodiment of the present disclosure;
FIG. 4 is a flow chart of one embodiment of a test case generation method provided by embodiments of the present disclosure;
FIG. 5 is a flowchart of yet another embodiment of a test case generation method provided by an embodiment of the present disclosure;
FIG. 6 is a schematic structural diagram of a test case generating device according to an embodiment of the present disclosure;
fig. 7 is a schematic hardware structure of an electronic device according to an embodiment of the disclosure.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present disclosure more apparent, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure, and it is apparent that the described embodiments are some embodiments of the present disclosure, but not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without inventive effort, based on the embodiments in this disclosure are intended to be within the scope of this disclosure.
The technical scheme disclosed by the invention can be applied to an automatic test scene of an application program, the change function and the call function corresponding to the change function can be accurately obtained by analyzing the change code of the program to be tested, the tested unit can be accurately positioned, the automatic generation of the test case is realized by utilizing the case generation strategy, and the generation efficiency and accuracy of the test case are improved.
In the related art, test cases are generally written manually, but the efficiency is low. Currently, there are also some automatic generation schemes of use cases, such as a symbol-based use case generation scheme and a search-based use case generation scheme. The generation schemes of the two cases are similar, and the corresponding test case can be generated by carrying out statistical analysis on codes and realizing hit detection on the codes. But this direct hit detection analysis is performed on the code to take advantage of the code coverage maximization as the set of applications to which the code execution corresponds. The analysis mode is complex, the program code is required to be subjected to hit detection continuously, the execution complexity is high, and the generation efficiency of the use case is low.
In order to solve the technical problems, in the present disclosure, detection of a change function that changes a code in a program to be tested is adopted, so that a unit to be tested can be quickly positioned through the change function, and generation of test cases is quickly completed by using the unit to be tested and a case generation strategy. The efficiency and the accuracy of the use case generation are improved.
In the embodiment of the disclosure, a change function which generates code change relative to an original program can be obtained through analysis from the program to be tested, and a unit to be tested is determined according to the change function and a calling function corresponding to the change function. The unit under test may refer to the program module of the program under test that is least involved in the test. The rapid positioning of the tested unit can be realized by changing the function, the test case of the tested unit is generated by using the case generation strategy, and the generation efficiency and accuracy of the test case are improved.
The following describes the technical solutions of the present disclosure and how the technical solutions of the present disclosure solve the above technical problems in detail with specific embodiments. The following embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Fig. 1 is an application network architecture diagram for a test case generation method provided in accordance with the present disclosure. An application network architecture according to an embodiment of the present disclosure may include an electronic device and a client that is connected to the electronic device through a local area network or a wide area network. The specific type of the electronic device in the present disclosure is not limited too much, provided that the electronic device may be a personal computer, a general server, a super personal computer, a cloud server, or the like. The client may be, for example, a mobile phone, a tablet computer, a personal computer, an intelligent home appliance, a wearable device, and the specific type of the client is not limited in this disclosure. As shown in fig. 2, taking an electronic device as the cloud server 1, and taking the first client 2 as the mobile phone 21 and the tablet computer 22 as examples, any one of the clients 2 may provide a use case generation request for initiating a program to be tested to the cloud server 1. The cloud server 1 can acquire the technical scheme based on the disclosure, analyze and acquire a change function which is changed relative to the code of the original program from the program to be tested, determine the tested unit by using the change function and the change function, generate the test case of the tested unit by using the case generation strategy, and realize the accurate generation of the test case. In the technical scheme of the disclosure, the use case generation policy can specifically realize the generation of test cases, the test cases are generally generated through executable files, and the executable files can include: parameter constructor 11, assertion processing module 12, coverage technique 13, use case filter 14, and use case generator 15.
Further, the cloud server 1 may transmit the generated test case to the client 2. The client 2 can use the checking test case and automatically test the tested unit in the program to be tested by using the test case.
Referring to fig. 2, fig. 2 is a flowchart of an embodiment of a test case generating method provided by an embodiment of the present disclosure, where the test case generating method may be configured as a test case generating device, and the test case generating device may be located in an electronic device. The test case generation method can comprise the following steps:
201: analyzing and obtaining a change function which changes codes relative to the original program from the program to be tested.
The original program may be a historical version of the application program. The program to be tested can be a new application program obtained by updating the version of the application program and adjusting the codes in the program, and the application program can be tested.
The program to be tested may include a relatively updated application or Library (Library), and the program to be tested may be composed of a plurality of functions. The functions illustrated in the present disclosure may refer to program code written in a programming language to automatically complete data processing, and do not refer to mathematical ideas or mathematical formulas.
The change function may include a program module that changes code, which may include one or more lines.
Alternatively, after determining the program to be tested, the code version management program may be used to perform code comparison between the program to be tested and the history program to determine a change function in which a code change exists. The history program may be program code corresponding to a previous version of the program to be tested. The history program may be a program that has completed code testing.
202: Determining a unit to be tested corresponding to the change function according to the change function and a calling function corresponding to the change function; the tested unit is the smallest program module participating in test in the tested program.
The change function may be a function in which a code change occurs. The calling function may have a calling relationship with the changing function. A calling (caller) function may be all the callers of a change function, and a calling function may be called by a change function, i.e., a change function may call a calling function. Of course, in some embodiments, the calling function may also call the changing function, i.e., the calling function may call the changing function, which may be determined based on the call and analysis requirements between functions.
The change function and the call function corresponding to the change function can form a unit to be tested. Program modules involved in the test may refer to modules corresponding to code used for the test.
203: Based on the case generation policy, a test case of the unit under test is generated.
The test cases may include test parameters for testing the unit under test, the test cases may be used for testing the unit under test, and inputting the test cases as input data to the unit under test may generate test results. The actual testing of the unit under test may be performed automatically after the test cases of the unit under test are generated to achieve automated unit testing.
In the embodiment of the disclosure, a change function which is changed in code relative to an original program can be obtained by analyzing from the program to be tested, and a unit to be tested is determined according to the change function and a calling function corresponding to the change function. The unit under test may refer to the smallest program module involved in testing among the programs under test. The rapid positioning of the tested unit can be realized by changing the function, the test case of the tested unit is generated by using the case generation strategy, and the generation efficiency and accuracy of the test case are improved.
To ensure that the accuracy of the test cases obtained is higher, the test cases may be screened. As shown in fig. 3, a flowchart of still another embodiment of a test case generating method according to an embodiment of the present disclosure may be configured as a test case generating device, where the test case generating device may be located in an electronic device. The difference from the embodiment shown in fig. 2 is that step 203: based on the case generation policy, generating a test case for the unit under test may include the following steps:
301: generating test parameters for the tested unit, and obtaining at least one test parameter corresponding to the tested unit.
The step of generating test parameters for the unit under test may be performed one or more times to obtain at least one test parameter for the unit under test.
302: And selecting a target test parameter from at least one test parameter based on a parameter selection condition with the minimum parameter number and the maximum code coverage rate of the tested unit.
The number of parameters may include a number of parameters of the target test parameter. The minimum number of parameters means that the number of parameters of the selected target test parameter is the minimum compared to the number of parameters of other selectable test parameters.
Other alternative test parameters may be code coverage equal to the code coverage of the target test parameter, but the number of test parameters involved in the test is greater than the number of parameters of the target test parameter.
The code coverage of the unit under test may include: the ratio of the number of codes tested in the codes of the unit under test to the total number of codes of all codes of the unit under test.
303: And generating a test case of the tested unit by using the target test parameters.
The target test parameters may include a plurality of target test parameters, any of which may be used to generate test cases for the unit under test.
In the embodiment of the disclosure, after generating at least one test parameter for the unit under test, the at least one test parameter may be subjected to parameter screening by a parameter selection condition to obtain a target test parameter. The accurate selection of the target test parameters can be realized through the selection of the parameter selection conditions, the test cases of the tested units are generated by utilizing the target test parameters, and the rapid and accurate generation of the test cases is realized.
In practical application, test cases corresponding to at least one test parameter respectively can be generated for each branch path of the test unit, so that accurate generation of each test path of the test unit is realized. Fig. 4 is a flowchart of still another embodiment of a test case generating method according to an embodiment of the present disclosure, where the test case generating method may be configured as a test case generating device, and the test case generating device may be located in an electronic device. The difference from the embodiment shown in fig. 3 is that step 301: generating test parameters for the unit under test, and obtaining at least one test parameter corresponding to the unit under test, wherein the test parameters can comprise the following units:
401: and determining at least one branch path corresponding to the tested unit according to the function call relation between the change function and the call function corresponding to the change function.
In practical applications, the change function may include if statements, switch statements, etc. for setting branch programs of different parameter execution programs to the same parameter or result, and different branch programs of the same parameter are juxtaposed.
The branch path may refer to a program call path or a program jump path corresponding to a call function of a certain branch program in the change function when the branch program is executed. One unit under test may include at least one branch path. Of course, in practical applications, the unit under test may include one or more units.
402: At least one test parameter is generated for the branch paths to obtain at least one test parameter corresponding to the at least one branch path respectively.
One or more test parameters may be generated for the branch path. In practical applications, since the operation of the program is affected by the test parameters, at least one test parameter may be generated for the branch path in order to ensure that the branch path is effectively tested. Each branch path may correspond to at least one test parameter. The test parameters of each branch path are used for testing whether the codes in the branch path can be successfully executed or not, and whether the execution result is accurate or not can be judged by utilizing the assertion program of the branch path.
403: And determining at least one test parameter corresponding to the at least one branch path as at least one test parameter corresponding to the tested unit.
The at least one test parameter corresponding to the unit under test may include at least one test parameter corresponding to the at least one branch path, respectively.
In the embodiment of the disclosure, at least one branch path of the unit under test can be determined according to the function call relationship between the change function and the call function corresponding to the change function. By generating at least one test parameter for the branch paths, at least one test parameter corresponding to the at least one branch path can be obtained, and accurate generation of the at least one test parameter is realized. By generating the test parameters for at least one branch path respectively, each branch path in the tested unit can be ensured to be covered completely, and the comprehensiveness of the test parameters is ensured.
In one possible design, the branch path includes a branch code passed by the change function when executing any one time and a call code corresponding to the branch code in the call function; generating at least one test parameter for the branch path, comprising:
and determining a first parameter corresponding to the branch path in the branch code according to the function information of the change function.
And determining a second parameter corresponding to the calling code by utilizing the jump relation between the branch code and the calling code corresponding to the calling function in the function calling relation based on the parameter constructor.
Determining the first parameter corresponding to the branch code and the second parameter corresponding to the calling code as the test parameters of the branch path, returning to the step of determining the first parameter corresponding to the branch code of the branch path to continue execution according to the function information of the change function until the number of parameters for generating at least one test parameter for the branch path meets the preset number threshold.
Wherein the function information of the change function may include a function signature. The function signature defines the input and output of the function or method and may include at least one of a function type, a function name, a parameter name of the function, a parameter type, a return parameter name, a return parameter type, and the like. The first parameter corresponding to the branch code can be directly generated through the function signature of the change function.
The parameter constructor (ArgumentFuzzer) may be constructed based on the Fuzz idea. After the first parameter of the branch code is constructed through the function signature, the second parameter of the downstream call code can be randomly constructed through the parameter constructor by utilizing the jump relation between the branch code and the call code corresponding to the call function in the function call relation.
In the embodiment of the disclosure, the first parameter corresponding to the branch code in the branch path may be determined according to the function information of the change function. In addition, a parameter constructor can also be utilized to determine a second parameter corresponding to the calling code by utilizing a function calling relation. By respectively carrying out parameter setting on the branch codes and the calling codes in the branch paths, finer granularity parameter setting can be realized, and the parameter setting accuracy is improved.
In order to obtain accurate target test parameters, fig. 5 is a flowchart of still another embodiment of a test case generating method according to an embodiment of the present disclosure, where the test case generating method may be configured as a test case generating device, and the test case generating device may be located in an electronic device. The difference from the embodiment shown in fig. 3 is that step 302: the selecting of the target test parameter from the at least one test parameter based on the parameter selection condition that the number of parameters is minimum and the code coverage rate of the unit under test is maximum may comprise the steps of:
501: and carrying out parameter test processing on the test parameters to obtain at least one test result and code coverage information respectively corresponding to the test parameters.
Alternatively, the test parameters may be pre-executed once, and may be input to an execution program interface of the unit under test to be tested.
And the test parameters obtain the feedback test result of the tested unit through the execution program interface. The tested unit has set coverage parameters, so that the code coverage rate of the tested unit can be tracked. Code Coverage can be specifically calculated by Coverage Counter (Coverage Counter)
502: And selecting candidate parameters meeting the test conditions from the at least one test parameter according to the test results respectively corresponding to the at least one test parameter.
The test conditions may include that the test results are normal.
503: Selecting target test parameters of parameter selection conditions from the candidate parameters according to code coverage information corresponding to the candidate parameters; the parameter selection conditions include: the number of parameters is minimum and the code coverage rate of the tested unit is maximum.
The maximum code coverage rate of the tested unit may mean that the code coverage of the tested unit is 100%, and when the code coverage rate corresponds to the tested unit, the coverage test is performed.
In one possible design, steps 502 and 503 may be accomplished by a use case filter. The candidate parameters can be initially screened by using the case filter by using the test conditions to obtain qualified candidate parameters, and the candidate parameters can be screened in more detail by using the parameter selection conditions to ensure that the selected target test parameters can reach the minimum number and the maximum coverage rate.
In the embodiment of the disclosure, parameter test processing can be performed on the test parameters to obtain the test result and the code coverage information corresponding to at least one test parameter respectively. Candidate parameters satisfying the test condition can be selected from the at least one test parameter by the test results respectively corresponding to the at least one test parameter. The selection of the candidate parameters is a preliminary selection of at least one test condition using the test conditions. Through the code coverage information corresponding to the candidate parameters, the target test parameters with the minimum parameter quantity and the maximum code coverage rate can be selected from the candidate parameters, so that the secondary selection of the parameters is realized. The candidate parameters can be subjected to more detailed parameter selection through secondary selection of the parameters, and the parameter selection efficiency and accuracy are improved.
In some embodiments, performing parameter test processing on the test parameters to obtain test results and code coverage information corresponding to at least one test parameter, where the test results and code coverage information respectively include:
And obtaining a target test unit obtained by executing the overlay parameter instrumentation processing for the code of the tested unit.
And packaging a program execution interface for the target test unit.
Inputting the test parameters into an execution program interface, and executing test processing on the test parameters by utilizing a target test unit packaged in the program execution interface to obtain test results and code coverage information corresponding to the test parameters.
And acquiring at least one test parameter and respectively inputting the test parameter into a program execution interface so as to acquire a test result and code coverage information respectively corresponding to the at least one test parameter.
And adding the coverage parameter statement into the code of the tested unit to complete the instrumentation of the coverage parameter, thereby obtaining the target test unit. And reading the coverage of the test parameters in the target test unit through the coverage rate counter to obtain code coverage information corresponding to the test parameters.
In the embodiment of the disclosure, coverage statistics of the tested unit is completed through pile-inserting processing, and generation of an executable program of the target test unit is completed through packaging a program execution interface for the target test unit, so that the target test unit can be executed. The target test unit can be tested through the execution program interface, corresponding code coverage information is obtained through the coverage parameters, pile insertion and test of the target test unit are achieved, automatic operation setting of the tested unit is completed, and smooth operation of a follow-up scheme is ensured.
In one possible design, inputting the test parameters into the execution program interface, and executing test processing on the test parameters by using a target test unit encapsulated in the program execution interface to obtain test results and code coverage information corresponding to the test parameters, including:
inputting the test parameters into an execution program interface, and executing test processing on the test parameters by utilizing a target test unit packaged in the program execution interface;
If the target test unit is determined to interrupt the test parameters or fails to compile, determining that the test failure is a test result corresponding to the test parameters;
If the normal return information of the target test unit to the test parameters is determined to be received, acquiring the information returned by the target test unit as a test result;
Reading data according to the coverage parameters processed by pile insertion to obtain coverage data corresponding to the coverage parameters;
and generating code coverage information of the test parameters according to the coverage data corresponding to the coverage parameters.
After the test parameters are input into the program execution interface, the target test unit encapsulated in the program execution interface can be utilized to execute test processing on the test parameters, so as to obtain corresponding processing results. The test parameters may be filtered using a use case filter (CASESFILTER). And if the processing result of the target test unit on the test parameters is that the parameter execution is interrupted or the compiling is failed, determining that the test abnormality is a test result. If the processing result is normal processing and normal return information is obtained, the normal return information returned by the target test unit can be obtained as a test result. And then, the use case filter can perform use case screening, namely code coverage information of the test parameters is obtained, and the test parameters are further screened by using the code coverage information of the test parameters and the constraint solving model so as to obtain the target test parameters with the minimum use case number and highest coverage rate.
In the embodiment of the disclosure, after the test parameters are input to the execution program interface, the target test unit in the program execution interface can execute test processing on the test parameters, the process of executing the test processing on the test parameters can be detected, the test result of the target test unit can be obtained in time, and the timeliness of obtaining the test result is improved. In addition, through reading data of the coverage parameters processed by the pile inserting, code coverage information of the test parameters can be acquired more accurately, the code coverage condition of the test parameters can be acquired accurately by the pile inserting mode, and the acquisition efficiency and accuracy are improved.
In some embodiments, the test results include test success or test failure;
According to the test results respectively corresponding to the at least one test parameter, selecting candidate parameters meeting the test conditions from the at least one test parameter, wherein the candidate parameters comprise:
Selecting a normal test parameter with a successful test result from at least one test parameter according to the test result respectively corresponding to the at least one test parameter;
performing assertion testing on the return information of the normal test parameters according to the assertion program of the tested unit to obtain assertion results of the normal test parameters;
And determining normal test parameters with normal assertion as candidate parameters from assertion results.
Alternatively, the assertions may be generated in real-time or may be generated historically. And the test parameters are subjected to assertion processing through an assertion program, so that whether feedback information is accurate after the test parameters are input is judged.
The generating of the assertion program may be obtained by performing field acquisition and hit rate determination on a plurality of test results, and specifically, reference may be made to description of related technologies, which are not described herein.
The assertion result may include assertion normal and assertion abnormal. A normal test parameter that asserts normal may be used as a candidate parameter. That is, the candidate parameter may be a test parameter that is tested successfully and that asserts testing normal.
In the embodiment of the disclosure, normal test parameters which are successfully tested in the test results corresponding to at least one test parameter respectively can be acquired, the return information of the normal test parameters is asserted, whether the return information of the normal test parameters is abnormal or not is judged, and the normal test parameters with normal assertion results are determined to be candidate parameters from assertion results. The accurate selection of the candidate parameters can be completed through the two progressive detection and judgment of whether the test result is normal or not and whether the return information in the test result is normal or not.
In order to obtain more accurate target test parameters, selecting the target test parameters with the minimum parameter number and the maximum code coverage rate for the tested unit from the candidate parameters according to the code coverage information corresponding to the candidate parameters may include:
Determining a constraint solving model taking the minimum number of parameters and the maximum code coverage rate of a unit to be measured as a solving target;
Inputting code coverage information corresponding to the candidate parameters into a constraint solving model, and solving through the constraint solving model to obtain target test parameters meeting a solving target in the candidate parameters.
Optionally, a constraint solving model may be included in the use case filter. After the candidate parameters are primarily screened through the test results, the candidate parameters can be screened in one step by using a constraint solving model in a use case filter. Namely, the candidate parameters are subjected to intersection under the constraint of the parameter selection condition by utilizing a constraint solving model, and the target test parameters are obtained by taking the intersection calculation result as a solving target which can contain all codes and has the minimum parameter quantity.
Alternatively, the code coverage information may comprise a code coverage vector. The code coverage vector corresponding to the candidate parameter may be determined by the branch path covered by the candidate parameter and the branch path not covered. Taking the example that the target test unit includes 5 branch paths, a certain branch path is tested, the value of the branch path is 1 in the code coverage vector of the candidate parameter, the branch path is not tested, and the value of the branch path is 0 in the code coverage vector of the candidate parameter. Assuming that the obtained candidate parameters are represented using a code coverage vector, this may include: (0 000 1) (1 000 1) (0 111 1) (0 100 0) from which the constraint solving model can select the smallest number of target test parameters with the highest coverage, which can include: all branch paths are covered entirely. That is, the constraint solving model may perform intersection computation on the code coverage vectors and find a set of parameters that satisfy the constraint condition through the intersection computation. The intersection of the two vectors (1 000 1) and (0 111 1) in the code coverage vector (1 111 1) is obtained, that is, the candidate parameters of the two code coverage vectors can be used as target test parameters capable of obtaining the minimum number of target test parameters capable of covering all branch paths.
In the embodiment of the disclosure, the target test parameters can be solved through the constraint solving model, so that the accurate target test parameters are obtained.
In one possible design, to quickly complete the generation of test cases, generating test cases for a unit under test using target test parameters may include:
Determining a use case generation template;
And inserting the target test parameters into a test module corresponding to the use case generating template, and updating the use case parameters in the use case generating template into the unit information of the unit to be tested to obtain the test use case of the unit to be tested.
The use case generating template can be a program which is compiled in advance according to the information such as the test environment, the application type of the test language program or the scene. The target test parameters may be converted into test modules consistent with the use case generation template.
In the embodiment of the disclosure, the target test parameters are inserted into the test modules corresponding to the case generation templates through the case generation templates, and the case parameters in the case generation templates are updated to the unit information of the tested unit, so that the test case of the tested unit is accurately generated.
The method for obtaining the test case of the unit to be tested includes the steps of:
Inserting the target test parameters into a test module corresponding to the use case generation template, and updating the use case parameters in the use case generation template into unit information of a unit to be tested to obtain an executable file of the unit to be tested;
Based on the executable file of the tested unit, a message generating queue of the test case is established;
And responding to a consumption request of a thread or a process for generating a message queue, consuming an execution process corresponding to the executable file from the message queue, and obtaining a test case when the execution of the executable file is finished.
The method for generating the case can compile the test case into an executable file, the executable file is packed to generate a message queue, and the message queue is subjected to consumption execution to obtain the test case. When the executable file is not executed, the executable file is a section of executable code, the execution of the executable file needs to be triggered, the consumption execution of the executable file can be realized by a message queue mode, and the automatic generation of the test case is realized.
Based on the executable file of the tested unit, the creating a message queue of the test case may include: and packaging the executable file of the tested unit, and inputting the packaged executable file into a message queue.
In the embodiment of the disclosure, the generation of the test case is rapidly completed in a message queue mode.
In one possible design, the unit under test in the program under test comprises at least one; after generating the test case of the unit under test based on the case generation policy, the method further comprises:
determining test cases corresponding to at least one tested unit respectively;
Dividing the tested units belonging to the same file information into the same unit group according to the file information respectively corresponding to the at least one tested unit to obtain at least one unit group; the unit group comprises at least one test unit;
Carrying out case combination on the test cases corresponding to at least one test unit in the unit group to obtain file cases corresponding to at least one piece of file information;
And determining the file use cases corresponding to at least one piece of file information as a target use case set of the program to be tested.
File information may be associated for each test unit. The case merging of the test cases corresponding to at least one test unit in the unit group respectively can comprise: and splicing and merging the test codes of the test cases corresponding to at least one test unit in the unit group respectively to obtain the file cases of the file corresponding to the unit group. Splicing test codes of the test cases corresponding to at least one test unit respectively can be as follows: and splicing the test codes corresponding to at least one test case according to the position and calling relation of the test unit corresponding to each test case in the file.
In the embodiment of the disclosure, the test cases of the test units of the same file information are combined, so that the file can be used as the tested object, and the test of a plurality of test units under the file can be completed at the same time by one-time file test, thereby improving the test efficiency and the integrity.
In one possible design, resolving a change function from a program to be tested that generates a code change relative to an original program includes:
Responding to a use case generation request aiming at a program to be tested, and analyzing and obtaining a change function which generates code change relative to an original program from the program to be tested;
after generating the test case of the unit under test based on the case generation policy, the method further comprises:
and outputting the test cases generated for the tested unit.
Outputting the generated test case for the unit under test may include sending the test user to the client, which displays the test case. May further include: and controlling the display device to directly display the test cases.
The output of the test cases can enable the user to view the corresponding test cases, so that in practical application, the user can update the test cases through the client. The electronic equipment can detect the update operation of the user on the test case, and update the test case by using the update content corresponding to the update operation to obtain the latest test case.
In the embodiment of the disclosure, the test case test request is responded, the test case is generated, the test case is output, the test case generation interaction is realized, and the information processing efficiency is improved.
In one possible design, after generating the test case of the unit under test based on the case generation policy, the method further includes:
responding to a program test request aiming at a program to be tested, and performing test processing on the program to be tested by using a test case of a unit to be tested to obtain a test result;
and outputting a test result of the program to be tested.
The program test request may be sent by a client, and the client may detect a program test request triggered by a user and send the program test request to the electronic device. The program test request may also be automatically triggered by the electronic device to generate, for example, when it is determined that the test case generation is finished, the program test request for generating the program to be tested may be automatically triggered.
In the embodiment of the disclosure, after the test case is obtained, the test case of the unit under test is utilized to test the program under test after the program test request is received, so as to obtain a test result. The test efficiency of the tested unit can be improved through the automatic test of the tested unit.
In some embodiments, the method may further comprise:
Acquiring a function call graph corresponding to a program to be tested; the function call graph comprises an inter-calling relation between at least one function in the program to be tested;
And inquiring the calling function with calling relation with the change function from the function call graph.
Alternatively, the functional call graph (callgraph) may be obtained by parsing the program under test into an AST (Abstract Syntax Tree ). The abstract syntax tree may parse out the data structure of the source code in a tree structure, and nodes on the tree may represent a structure of the source code, which may include functions. Edges between nodes on a tree may refer to calling relationships between two structures.
The functional call graph may be generated in real time or may be generated in advance. The obtaining the function call graph corresponding to the program to be tested may include: inputting the program to be tested into AST for analysis to obtain the function call graph. The obtaining the function call graph corresponding to the program to be tested may further include: and reading a function call graph file of the program to be tested, and analyzing the file to obtain a function call graph.
In the embodiment of the disclosure, the calling relationship between at least one function is acquired by utilizing the function call graph, so that quick and accurate query of the calling function is realized.
As shown in fig. 6, a schematic structural diagram of an embodiment of a test case generating device according to an embodiment of the present disclosure is provided, where the test case generating device may be located in an electronic device. The test case generating apparatus 600 may include the following units:
program analysis section 601: and the change function is used for analyzing and obtaining the code change relative to the original program from the program to be tested.
Call analysis unit 602: the unit to be tested is used for determining the change function according to the change function and the call function corresponding to the change function; the tested unit is the smallest program module participating in test in the tested program.
Use case generation section 603: the method is used for generating the test cases of the tested unit based on the case generation strategy.
As one embodiment, the use case generating unit includes:
the parameter determining module is used for generating test parameters for the tested unit and obtaining at least one test parameter corresponding to the tested unit;
The parameter selection module is used for selecting a target test parameter from at least one test parameter based on a parameter selection condition with minimum parameter quantity and maximum code coverage rate of a unit to be tested;
and the case generation module is used for generating the test case of the tested unit by utilizing the target test parameters.
In one possible design, the parameter determination module may include:
The branch determination submodule is used for determining at least one branch path corresponding to the tested unit according to the function call relation between the change function and the call function corresponding to the change function;
The parameter generation sub-module is used for generating at least one test parameter for the branch paths so as to obtain at least one test parameter corresponding to the at least one branch paths respectively;
And the parameter determination submodule is used for determining at least one test parameter corresponding to the at least one branch path as at least one test parameter corresponding to the tested unit.
In one possible design, the branch path includes a branch code passed by the change function when executing any one time and a call code corresponding to the branch code in the call function; the parameter generation submodule may be specifically configured to:
determining a first parameter corresponding to the branch path in the branch code according to the function information of the change function;
Determining a second parameter corresponding to the calling code by utilizing a branch code and a jump relation of the branch code between the calling codes corresponding to the calling functions in the function calling relation based on the parameter constructor;
Determining the first parameter corresponding to the branch code and the second parameter corresponding to the calling code as the test parameters of the branch path, returning to the step of determining the first parameter corresponding to the branch code of the branch path to continue execution according to the function information of the change function until the number of parameters for generating at least one test parameter for the branch path meets the preset number threshold.
In one possible design, the parameter selection module includes:
The parameter testing sub-module is used for carrying out parameter testing processing on the testing parameters to obtain at least one testing result and code coverage information which correspond to the testing parameters respectively;
The candidate selection submodule is used for selecting candidate parameters meeting the test conditions from at least one test parameter according to the test results respectively corresponding to the at least one test parameter;
the target selection sub-module is used for selecting target test parameters of parameter selection conditions from the candidate parameters according to code coverage information corresponding to the candidate parameters; the parameter selection conditions include: the number of parameters is minimum and the code coverage rate of the tested unit is maximum.
In one possible design, the parametric test sub-module may be specifically configured to:
Obtaining a target test unit obtained by executing coverage parameter instrumentation processing for codes of a unit to be tested;
Packaging a program execution interface for the target test unit;
Inputting the test parameters into an execution program interface, and executing test processing on the test parameters by utilizing a target test unit packaged in the program execution interface to obtain test results and code coverage information corresponding to the test parameters;
And acquiring at least one test parameter and respectively inputting the test parameter into a program execution interface so as to acquire a test result and code coverage information respectively corresponding to the at least one test parameter.
In certain embodiments, the parameter testing sub-module may also be specifically configured to:
inputting the test parameters into an execution program interface, and executing test processing on the test parameters by utilizing a target test unit packaged in the program execution interface;
If the target test unit is determined to interrupt the test parameters or fails to compile, determining that the test failure is a test result corresponding to the test parameters;
If the normal return information of the target test unit to the test parameters is determined to be received, acquiring the information returned by the target test unit as a test result;
Reading data according to the coverage parameters processed by pile insertion to obtain coverage data corresponding to the coverage parameters;
and generating code coverage information of the test parameters according to the coverage data corresponding to the coverage parameters.
As one embodiment, the test results include test success or test failure;
A candidate selection sub-module, comprising:
The normal selection sub-module is used for selecting the test result from the at least one test parameter as the normal test parameter of successful test according to the test result respectively corresponding to the at least one test parameter;
The assertion testing submodule is used for carrying out assertion testing on the return information of the normal testing parameters according to the assertion program of the tested unit to obtain the assertion result of the normal testing parameters;
And determining normal test parameters with normal assertion as candidate parameters from assertion results.
In some embodiments, the target selection submodule may be specifically configured to:
Determining a constraint solving model taking the minimum number of parameters and the maximum code coverage rate of a unit to be measured as a solving target;
Inputting code coverage information corresponding to the candidate parameters into a constraint solving model, and solving through the constraint solving model to obtain target test parameters meeting a solving target in the candidate parameters.
As one embodiment, the use case generation module may include:
the template determination submodule is used for determining a use case generation template;
and the parameter inserting sub-module is used for inserting the target test parameters into the test module corresponding to the use case generating template, updating the use case parameters in the use case generating template into the unit information of the unit to be tested, and obtaining the test use case of the unit to be tested.
In one possible design, the parameter insertion sub-module is specifically configured to:
Inserting the target test parameters into a test module corresponding to the use case generation template, and updating the use case parameters in the use case generation template into unit information of a unit to be tested to obtain an executable file of the unit to be tested;
Based on the executable file of the tested unit, a message generating queue of the test case is established;
And responding to a consumption request of a thread or a process for generating a message queue, consuming an execution process corresponding to the executable file from the message queue, and obtaining a test case when the execution of the executable file is finished.
As one embodiment, the unit under test in the program under test includes at least one; the apparatus further comprises:
the use case determining unit is used for determining the test use cases corresponding to at least one tested unit respectively;
The file dividing unit is used for dividing the tested units belonging to the same file information into the same unit group according to the file information respectively corresponding to the at least one tested unit to obtain at least one unit group; the unit group comprises at least one test unit;
The system comprises a case merging unit, a test unit and a control unit, wherein the case merging unit is used for merging cases of test cases respectively corresponding to at least one test unit in a unit group to obtain file cases respectively corresponding to at least one piece of file information;
And the set determining unit is used for determining the file use cases corresponding to the at least one piece of file information as a target use case set of the program to be tested.
In some embodiments, the program parsing unit includes:
The use case response module is used for responding to a use case generation request aiming at the program to be tested, and analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
The apparatus may further include:
And the first output unit is used for outputting the test cases generated for the tested unit.
As yet another embodiment, further comprising:
The test response unit is used for responding to a program test request for the program to be tested, and testing the program to be tested by using a test case of the tested unit to obtain a test result;
And the second output unit is used for outputting the test result of the program to be tested.
In certain embodiments, further comprising:
The function determining unit is used for obtaining a function call graph corresponding to the program to be tested; the function call graph comprises an inter-calling relation between at least one function in the program to be tested;
and the relation inquiring unit is used for inquiring the calling function with the calling relation with the changed function from the function call graph.
The device provided in this embodiment may be used to implement the technical solution of the foregoing method embodiment, and its implementation principle and technical effects are similar, and this embodiment will not be described herein again.
In order to achieve the above embodiments, the embodiments of the present disclosure further provide an electronic device.
Referring to fig. 7, there is shown a schematic diagram of an electronic device 700 suitable for use in implementing embodiments of the present disclosure, which electronic device 700 may be a terminal device or a server. The terminal device may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a Personal Digital Assistant (PDA) or the like, a tablet computer (Portable Android Device) or the like, a Portable Multimedia Player (PMP) or the like, a car-mounted terminal (e.g., car navigation terminal) or the like, and a fixed terminal such as a digital TV or a desktop computer or the like. The electronic device shown in fig. 7 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
As shown in fig. 7, the electronic apparatus 700 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 701 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 702 or a program loaded from a storage device 708 into a random access Memory (Random Access Memory RAM) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 are also stored. The processing device 701, the ROM702, and the RAM 703 are connected to each other through a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
In general, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, and the like; an output device 707 including, for example, a Liquid Crystal Display (LCD) CRYSTAL DISPLAY, a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication means 709 may allow the electronic device 700 to communicate wirelessly or by wire with other devices to exchange data. While fig. 7 shows an electronic device 700 having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via communication device 709, or installed from storage 708, or installed from ROM 702. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing device 701.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
The computer-readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to perform the methods shown in the above-described embodiments.
Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a local area network (Local Area Network, LAN for short) or a wide area network (Wide Area Network, WAN for short), or may be connected to an external computer (e.g., through the internet using an internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. The name of the unit does not in any way constitute a limitation of the unit itself, for example the first acquisition unit may also be described as "unit acquiring at least two internet protocol addresses".
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a Field Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a system on a chip (SOC), a Complex Programmable Logic Device (CPLD), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
In a first aspect, according to one or more embodiments of the present disclosure, there is provided a test case generating method, including:
Analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
Determining a unit to be tested corresponding to the change function according to the change function and a calling function corresponding to the change function; the tested unit is the smallest program module participating in test in the program to be tested;
Based on the case generation policy, a test case of the unit under test is generated.
According to one or more embodiments of the present disclosure, generating test cases for a unit under test based on a case generation policy includes:
generating test parameters for the tested unit, and obtaining at least one test parameter corresponding to the tested unit;
Selecting a target test parameter from at least one test parameter based on a parameter selection condition that the number of parameters is minimum and the code coverage rate of the unit to be tested is maximum;
And generating a test case of the tested unit by using the target test parameters.
According to one or more embodiments of the present disclosure, generating test parameters for a unit under test, obtaining at least one test parameter corresponding to the unit under test, includes:
determining at least one branch path corresponding to the tested unit according to the function call relation between the change function and the call function corresponding to the change function;
Generating at least one test parameter for the branch paths to obtain at least one test parameter corresponding to the at least one branch path respectively;
and determining at least one test parameter corresponding to the at least one branch path as at least one test parameter corresponding to the tested unit.
According to one or more embodiments of the present disclosure, a branch path includes a branch code that passes through when any one is executed in a change function and a call code to which the branch code corresponds in a call function; generating at least one test parameter for the branch path, comprising:
Determining a first parameter corresponding to the branch path in the branch code according to the function information of the change function; determining a second parameter corresponding to the calling code by utilizing a branch code and a jump relation of the branch code between the calling codes corresponding to the calling functions in the function calling relation based on the parameter constructor;
Determining the first parameter corresponding to the branch code and the second parameter corresponding to the calling code as the test parameters of the branch path, returning to the step of determining the first parameter corresponding to the branch code of the branch path to continue execution according to the function information of the change function until the number of parameters for generating at least one test parameter for the branch path meets the preset number threshold.
According to one or more embodiments of the present disclosure, selecting a target test parameter from at least one test parameter based on a parameter selection condition that a number of parameters is minimum and code coverage to a unit under test is maximum, includes:
performing parameter test processing on the test parameters to obtain at least one test result and code coverage information respectively corresponding to the test parameters;
Selecting candidate parameters meeting the test conditions from the at least one test parameter according to the test results respectively corresponding to the at least one test parameter;
Selecting target test parameters of parameter selection conditions from the candidate parameters according to code coverage information corresponding to the candidate parameters; the parameter selection conditions include: the number of parameters is minimum and the code coverage rate of the tested unit is maximum.
According to one or more embodiments of the present disclosure, performing parameter test processing on test parameters to obtain test results and code coverage information corresponding to at least one test parameter, where the test results and code coverage information respectively include:
Obtaining a target test unit obtained by executing coverage parameter instrumentation processing for codes of a unit to be tested;
Packaging a program execution interface for the target test unit;
Inputting the test parameters into an execution program interface, and executing test processing on the test parameters by utilizing a target test unit packaged in the program execution interface to obtain test results and code coverage information corresponding to the test parameters;
And acquiring at least one test parameter and respectively inputting the test parameter into a program execution interface so as to acquire a test result and code coverage information respectively corresponding to the at least one test parameter.
According to one or more embodiments of the present disclosure, inputting test parameters into an execution program interface, performing test processing on the test parameters by using a target test unit encapsulated in the program execution interface, obtaining test results and code coverage information corresponding to the test parameters, including:
inputting the test parameters into an execution program interface, and executing test processing on the test parameters by utilizing a target test unit packaged in the program execution interface;
If the target test unit is determined to interrupt the test parameters or fails to compile, determining that the test failure is a test result corresponding to the test parameters;
If the normal return information of the target test unit to the test parameters is determined to be received, acquiring the information returned by the target test unit as a test result;
Reading data according to the coverage parameters processed by pile insertion to obtain coverage data corresponding to the coverage parameters;
and generating code coverage information of the test parameters according to the coverage data corresponding to the coverage parameters.
According to one or more embodiments of the present disclosure, the test results include test success or test failure;
According to the test results respectively corresponding to the at least one test parameter, selecting candidate parameters meeting the test conditions from the at least one test parameter, wherein the candidate parameters comprise:
Selecting a normal test parameter with a successful test result from at least one test parameter according to the test result respectively corresponding to the at least one test parameter;
performing assertion testing on the return information of the normal test parameters according to the assertion program of the tested unit to obtain assertion results of the normal test parameters;
And determining normal test parameters with normal assertion as candidate parameters from assertion results.
According to one or more embodiments of the present disclosure, according to code coverage information corresponding to candidate parameters, selecting a target test parameter having the smallest number of parameters and the largest code coverage to a unit under test from the candidate parameters, including:
Determining a constraint solving model taking the minimum number of parameters and the maximum code coverage rate of a unit to be measured as a solving target;
Inputting code coverage information corresponding to the candidate parameters into a constraint solving model, and solving through the constraint solving model to obtain target test parameters meeting a solving target in the candidate parameters.
According to one or more embodiments of the present disclosure, generating test cases for units under test using target test parameters includes:
Determining a use case generation template;
And inserting the target test parameters into a test module corresponding to the use case generating template, and updating the use case parameters in the use case generating template into the unit information of the unit to be tested to obtain the test use case of the unit to be tested.
According to one or more embodiments of the present disclosure, inserting a target test parameter into a test module corresponding to a use case generating template, and updating the use case parameter in the use case generating template to unit information of a unit under test, to obtain a test use case of the unit under test, including:
Inserting the target test parameters into a test module corresponding to the use case generation template, and updating the use case parameters in the use case generation template into unit information of a unit to be tested to obtain an executable file of the unit to be tested;
Based on the executable file of the tested unit, a message generating queue of the test case is established;
And responding to a consumption request of a thread or a process for generating a message queue, consuming an execution process corresponding to the executable file from the message queue, and obtaining a test case when the execution of the executable file is finished.
According to one or more embodiments of the present disclosure, a unit under test in a program under test includes at least one; after generating the test case of the unit under test based on the case generation policy, the method further comprises:
determining test cases corresponding to at least one tested unit respectively;
Dividing the tested units belonging to the same file information into the same unit group according to the file information respectively corresponding to the at least one tested unit to obtain at least one unit group; the unit group comprises at least one test unit;
Carrying out case combination on the test cases corresponding to at least one test unit in the unit group to obtain file cases corresponding to at least one piece of file information;
And determining the file use cases corresponding to at least one piece of file information as a target use case set of the program to be tested.
According to one or more embodiments of the present disclosure, resolving and obtaining a change function, which generates a code change with respect to an original program, from a program to be tested includes:
Responding to a use case generation request aiming at a program to be tested, and analyzing and obtaining a change function which generates code change relative to an original program from the program to be tested;
after generating the test case of the unit under test based on the case generation policy, the method further comprises:
and outputting the test cases generated for the tested unit.
According to one or more embodiments of the present disclosure, after generating the test case of the unit under test based on the case generation policy, further includes:
responding to a program test request aiming at a program to be tested, and performing test processing on the program to be tested by using a test case of a unit to be tested to obtain a test result;
and outputting a test result of the program to be tested.
According to one or more embodiments of the present disclosure, further comprising:
Acquiring a function call graph corresponding to a program to be tested; the function call graph comprises an inter-calling relation between at least one function in the program to be tested;
And inquiring the calling function with calling relation with the change function from the function call graph.
In a second aspect, according to one or more embodiments of the present disclosure, there is provided a test case generating apparatus including:
the program analysis unit is used for analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
The call analysis unit is used for determining a tested unit corresponding to the change function according to the change function and a call function corresponding to the change function; the tested unit is the smallest program module participating in test in the program to be tested;
And the use case generating unit is used for generating the test use case of the tested unit based on the use case generating strategy.
In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device comprising: at least one processor and memory;
The memory stores computer-executable instructions;
at least one processor executes computer-executable instructions stored in a memory, causing the at least one processor to perform the test case generating method of the above first aspect and the various possible designs of the first aspect.
In a fourth aspect, according to one or more embodiments of the present disclosure, there is provided a computer-readable storage medium having stored therein computer-executable instructions which, when executed by a processor, implement the test case generating method of the first aspect and the various possible designs of the first aspect as above.
In a fifth aspect, according to one or more embodiments of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the test case generation method of the above first aspect and the various possible designs of the first aspect.
The foregoing description is only of the preferred embodiments of the present disclosure and description of the principles of the technology being employed. It will be appreciated by persons skilled in the art that the scope of the disclosure referred to in this disclosure is not limited to the specific combinations of features described above, but also covers other embodiments which may be formed by any combination of features described above or equivalents thereof without departing from the spirit of the disclosure. Such as those described above, are mutually substituted with the technical features having similar functions disclosed in the present disclosure (but not limited thereto).
Moreover, although operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. In certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are example forms of implementing the claims.

Claims (19)

1. A test case generation method, comprising:
Analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
Determining a unit to be tested corresponding to the change function according to the change function and a calling function corresponding to the change function; the tested unit is the smallest program module participating in the test in the program to be tested;
and generating the test case of the tested unit based on the case generation strategy.
2. The method of claim 1, wherein generating test cases for the unit under test based on the case generation policy comprises:
Generating test parameters for the tested unit to obtain at least one test parameter corresponding to the tested unit;
selecting a target test parameter from at least one test parameter based on a parameter selection condition with minimum parameter number and maximum code coverage rate of the tested unit;
and generating the test case of the tested unit by using the target test parameters.
3. The method according to claim 2, wherein the generating test parameters for the unit under test to obtain at least one test parameter corresponding to the unit under test includes:
determining at least one branch path corresponding to the tested unit according to the function call relation between the change function and the call function corresponding to the change function;
generating at least one test parameter for the branch paths to obtain at least one test parameter corresponding to at least one branch path respectively;
And determining at least one test parameter corresponding to at least one branch path as at least one test parameter corresponding to the tested unit.
4. A method according to claim 3, wherein the branch path includes branch code passed by any one of the change functions and call code to which the branch code corresponds at the call function; said generating at least one test parameter for said branch path comprises:
determining a first parameter corresponding to the branch code of the branch path according to the function information of the change function;
Determining a second parameter corresponding to the calling code by utilizing the branch code and the jump relation of the branch code between the calling codes corresponding to the calling functions in the function calling relation based on a parameter constructor;
And determining the first parameter corresponding to the branch code and the second parameter corresponding to the call code as the test parameters of the branch path, returning to the step of determining the first parameter corresponding to the branch code of the branch path to continue execution according to the function information of the change function until the parameter number of at least one test parameter generated for the branch path meets a preset number threshold.
5. A method according to claim 3, wherein said selecting a target test parameter from at least one of said test parameters based on a parameter selection condition that a number of parameters is minimum and a code coverage for said unit under test is maximum comprises:
Performing parameter test processing on the test parameters to obtain at least one test result and code coverage information respectively corresponding to the test parameters;
Selecting candidate parameters meeting test conditions from at least one test parameter according to test results respectively corresponding to the at least one test parameter;
Selecting target test parameters of the parameter selection conditions from the candidate parameters according to code coverage information corresponding to the candidate parameters; the parameter selection conditions include: the number of parameters is minimum and the code coverage rate of the tested unit is maximum.
6. The method of claim 5, wherein the performing parameter testing on the test parameters to obtain the test result and the code coverage information corresponding to at least one of the test parameters respectively includes:
Obtaining a target test unit obtained by executing overlay parameter instrumentation processing for codes of the tested unit;
packaging a program execution interface for the target test unit;
inputting the test parameters into the execution program interface, and executing test processing on the test parameters by using the target test unit packaged in the program execution interface to obtain a test result corresponding to the test parameters and the code coverage information;
and acquiring at least one test parameter and respectively inputting the test parameter into the program execution interface so as to acquire the test result and the code coverage information which respectively correspond to the at least one test parameter.
7. The method according to claim 6, wherein inputting the test parameters into the execution program interface, performing test processing on the test parameters by using the target test unit encapsulated in the program execution interface, and obtaining test results and the code coverage information corresponding to the test parameters, includes:
Inputting the test parameters into the execution program interface, and executing test processing on the test parameters by using the target test unit packaged in the program execution interface;
If the target test unit is determined to interrupt the test parameters or fail compiling, determining that the test failure is a test result corresponding to the test parameters;
If the normal return information of the target test unit to the test parameters is determined to be received, acquiring the return information of the target test unit as the test result;
Reading data according to the coverage parameters processed by the pile insertion to obtain coverage data corresponding to the coverage parameters;
and generating the code coverage information of the test parameters according to the coverage data corresponding to the coverage parameters.
8. The method of claim 5, wherein the test result comprises a test success or a test failure;
according to the test results respectively corresponding to at least one test parameter, selecting candidate parameters meeting test conditions from at least one test parameter, wherein the candidate parameters comprise:
Selecting a normal test parameter with a successful test result from at least one test parameter according to the test result respectively corresponding to the at least one test parameter;
Performing assertion testing on the return information of the normal test parameters according to the assertion program of the tested unit to obtain assertion results of the normal test parameters;
And determining the normal test parameters of the normal assertion from the assertion result as the candidate parameters.
9. The method according to claim 5, wherein selecting the target test parameter with the smallest number of parameters and the largest code coverage rate for the unit under test from the candidate parameters according to the code coverage information corresponding to the candidate parameters comprises:
Determining a constraint solving model taking the minimum parameter quantity and the maximum code coverage rate of the unit to be measured as solving targets;
Inputting code coverage information corresponding to the candidate parameters into the constraint solving model, and solving the candidate parameters through the constraint solving model to obtain target test parameters meeting the solving target.
10. The method of claim 2, wherein generating the test case for the unit under test using the target test parameters comprises:
Determining a use case generation template;
And inserting the target test parameters into a test module corresponding to the use case generation template, and updating the use case parameters in the use case generation template into the unit information of the unit to be tested to obtain the test use case of the unit to be tested.
11. The method of claim 10, wherein the inserting the target test parameters into the test modules corresponding to the use case generating templates, and updating the use case parameters in the use case generating templates to the unit information of the unit under test, to obtain the test cases of the unit under test, includes:
Inserting the target test parameters into a test module corresponding to the use case generation template, and updating the use case parameters in the use case generation template into unit information of the unit to be tested to obtain an executable file of the unit to be tested;
based on the executable file of the tested unit, a message generating queue of the test case is established;
and responding to a consumption request of a thread or a process for the generated message queue, consuming an execution process corresponding to the executable file from the message queue, and obtaining the test case when the execution of the executable file is finished.
12. The method according to any one of claims 1-11, wherein the unit under test in the program under test comprises at least one; the case-based generation strategy further comprises the following steps after generating the test case of the tested unit:
Determining at least one test case corresponding to each tested unit;
Dividing the tested units belonging to the same file information into the same unit group according to the file information respectively corresponding to at least one tested unit to obtain at least one unit group; said set of cells comprising at least one of said test cells;
Carrying out case combination on the test cases corresponding to at least one test unit in the unit group to obtain file cases corresponding to at least one piece of file information;
And determining at least one file use case corresponding to the file information as a target use case set of the program to be tested.
13. The method according to any one of claims 1 to 11, wherein the parsing from the program to be tested obtains a change function that is changed in code relative to the original program, including:
Responding to a use case generation request aiming at the program to be tested, and analyzing and obtaining a change function which generates code change relative to the original program from the program to be tested;
the case-based generation strategy further comprises the following steps after generating the test case of the tested unit:
And outputting the test cases generated for the tested unit.
14. The method according to any one of claims 1-11, wherein after generating the test cases for the unit under test based on the case generation policy, further comprising:
responding to a program test request aiming at the program to be tested, and performing test processing on the program to be tested by utilizing the test case of the unit to be tested to obtain a test result;
and outputting a test result of the program to be tested.
15. The method according to any one of claims 1-11, further comprising:
acquiring a function call graph corresponding to the program to be tested; the function call graph comprises a calling relation among at least one function in the program to be tested;
And inquiring a calling function which has a calling relation with the change function from the function call graph.
16. A test case generating apparatus, comprising:
the program analysis unit is used for analyzing and obtaining a change function which is changed in code relative to the original program from the program to be tested;
The call analysis unit is used for determining a tested unit corresponding to the change function according to the change function and a call function corresponding to the change function; the tested unit is the smallest program module participating in the test in the program to be tested;
and the use case generating unit is used for generating the test use case of the tested unit based on the use case generating strategy.
17. An electronic device, comprising: a processor, a memory;
The memory stores computer-executable instructions;
the processor executing computer-executable instructions stored in the memory, causing the processor to be configured with the test case generation method of any one of claims 1 to 15.
18. A computer-readable storage medium having stored therein computer-executable instructions that, when executed by a processor, implement the test case generation method of any of claims 1 to 15.
19. A computer program product comprising a computer program, wherein the computer program is executed by a processor to configure the test case generation method of any one of claims 1 to 15.
CN202211430311.2A 2022-11-15 2022-11-15 Test case generation method, device, equipment, medium and product Pending CN118093352A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211430311.2A CN118093352A (en) 2022-11-15 2022-11-15 Test case generation method, device, equipment, medium and product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211430311.2A CN118093352A (en) 2022-11-15 2022-11-15 Test case generation method, device, equipment, medium and product

Publications (1)

Publication Number Publication Date
CN118093352A true CN118093352A (en) 2024-05-28

Family

ID=91162200

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211430311.2A Pending CN118093352A (en) 2022-11-15 2022-11-15 Test case generation method, device, equipment, medium and product

Country Status (1)

Country Link
CN (1) CN118093352A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118819990A (en) * 2024-09-20 2024-10-22 山东云海国创云计算装备产业创新中心有限公司 Memory termination resistor configuration method, electronic device and storage medium
CN119248658A (en) * 2024-12-04 2025-01-03 苏州元脑智能科技有限公司 Function testing method, device, storage medium and program product

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118819990A (en) * 2024-09-20 2024-10-22 山东云海国创云计算装备产业创新中心有限公司 Memory termination resistor configuration method, electronic device and storage medium
CN119248658A (en) * 2024-12-04 2025-01-03 苏州元脑智能科技有限公司 Function testing method, device, storage medium and program product

Similar Documents

Publication Publication Date Title
CN112328419B (en) Test case generation method and device of remote procedure call interface, storage medium and electronic equipment
US20100192128A1 (en) System and methods of using test points and signal overrides in requirements-based test generation
CN118093352A (en) Test case generation method, device, equipment, medium and product
CN110674047B (en) Software testing method and device and electronic equipment
CN111209202A (en) Terminal application testing method and device
CN113485918B (en) Test method, test device, electronic equipment and storage medium
CN112597047A (en) Test method, test device, electronic equipment and computer readable medium
CN112988494A (en) Abnormity testing method and device and electronic device
CN111597120A (en) Interface test apparatus, method, electronic device, and computer-readable storage medium
US11169910B2 (en) Probabilistic software testing via dynamic graphs
US11663113B2 (en) Real time fault localization using combinatorial test design techniques and test case priority selection
CN116225886A (en) Test case generation method, device, equipment, storage medium and program product
US9983975B2 (en) Fixing anti-patterns in javascript
CN112965910B (en) Automatic regression testing method and device, electronic equipment and storage medium
CN117493150A (en) Code quality detection method, apparatus, device, storage medium, and program
CN114911770A (en) Method, device, equipment and medium for evaluating database migration
CN112882921B (en) Fault simulation method and device
CN113360380B (en) Method and device for generating data case based on flow chart
CN117056191A (en) Assertion program processing method, device, equipment, medium and product
CN115860573B (en) Highway engineering detection method based on detection item, electronic equipment and readable medium
US20220350731A1 (en) Method and system for test automation of a software system including multiple software services
CN116361143A (en) Software testing method, device, equipment and storage medium
CN118035065A (en) Interface testing method and device
CN114064484A (en) Interface testing method and device, electronic equipment and readable storage medium
CN117493149A (en) Code security detection method, device, apparatus, storage medium, and program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination