CN115248780A - Interface test case generation method and device - Google Patents
Interface test case generation method and device Download PDFInfo
- Publication number
- CN115248780A CN115248780A CN202211011460.5A CN202211011460A CN115248780A CN 115248780 A CN115248780 A CN 115248780A CN 202211011460 A CN202211011460 A CN 202211011460A CN 115248780 A CN115248780 A CN 115248780A
- Authority
- CN
- China
- Prior art keywords
- case
- seed
- interface
- test case
- tested
- 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
Links
- 238000012360 testing method Methods 0.000 title claims abstract description 185
- 238000000034 method Methods 0.000 title claims abstract description 83
- 108090000623 proteins and genes Proteins 0.000 claims abstract description 123
- 238000013101 initial test Methods 0.000 claims abstract description 95
- 238000012216 screening Methods 0.000 claims abstract description 59
- 230000035772 mutation Effects 0.000 claims description 19
- 239000013598 vector Substances 0.000 claims description 17
- 230000003068 static effect Effects 0.000 claims description 12
- 238000003860 storage Methods 0.000 claims description 9
- 239000013589 supplement Substances 0.000 claims description 9
- 238000012163 sequencing technique Methods 0.000 claims description 7
- 238000010276 construction Methods 0.000 claims description 3
- 238000002474 experimental method Methods 0.000 abstract description 4
- 238000004422 calculation algorithm Methods 0.000 description 46
- 230000002068 genetic effect Effects 0.000 description 22
- 230000008569 process Effects 0.000 description 21
- 238000010586 diagram Methods 0.000 description 19
- 239000000243 solution Substances 0.000 description 15
- 239000003795 chemical substances by application Substances 0.000 description 11
- 238000004458 analytical method Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 7
- 230000007614 genetic variation Effects 0.000 description 7
- 238000004364 calculation method Methods 0.000 description 5
- 238000011161 development Methods 0.000 description 5
- 230000018109 developmental process Effects 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 5
- 238000013459 approach Methods 0.000 description 3
- 230000010354 integration Effects 0.000 description 3
- 230000003993 interaction Effects 0.000 description 3
- 238000012544 monitoring process Methods 0.000 description 3
- 238000005457 optimization Methods 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 230000003416 augmentation Effects 0.000 description 2
- 230000008901 benefit Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 238000004590 computer program Methods 0.000 description 2
- 230000007547 defect Effects 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 239000000047 product Substances 0.000 description 2
- 230000004044 response Effects 0.000 description 2
- 238000012549 training Methods 0.000 description 2
- 230000009466 transformation Effects 0.000 description 2
- 239000002699 waste material Substances 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 230000006978 adaptation Effects 0.000 description 1
- 230000003044 adaptive effect Effects 0.000 description 1
- 230000002776 aggregation Effects 0.000 description 1
- 238000004220 aggregation Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000003190 augmentative effect Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000007796 conventional method Methods 0.000 description 1
- 230000007812 deficiency Effects 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 230000009977 dual effect Effects 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 238000002347 injection Methods 0.000 description 1
- 239000007924 injection Substances 0.000 description 1
- 238000003780 insertion Methods 0.000 description 1
- 230000037431 insertion Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000009191 jumping Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000011112 process operation Methods 0.000 description 1
- 238000004080 punching Methods 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 239000004984 smart glass Substances 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3676—Test management for coverage analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/12—Computing arrangements based on biological models using genetic models
- G06N3/126—Evolutionary algorithms, e.g. genetic algorithms or genetic programming
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Life Sciences & Earth Sciences (AREA)
- Biophysics (AREA)
- Health & Medical Sciences (AREA)
- General Physics & Mathematics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Evolutionary Biology (AREA)
- Quality & Reliability (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Computer Hardware Design (AREA)
- Genetics & Genomics (AREA)
- Evolutionary Computation (AREA)
- General Health & Medical Sciences (AREA)
- Molecular Biology (AREA)
- Computing Systems (AREA)
- Data Mining & Analysis (AREA)
- Computational Linguistics (AREA)
- Mathematical Physics (AREA)
- Software Systems (AREA)
- Biomedical Technology (AREA)
- Artificial Intelligence (AREA)
- Physiology (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
An embodiment of the present specification provides a method and a device for generating an interface test case, where the method for generating the interface test case includes: acquiring case execution data corresponding to an interface to be tested of the application to be tested, and performing cluster screening on the case execution data to obtain a seed case; acquiring execution information of the seed case at an interface to be tested, and screening an initial test case from the seed case according to the execution information; according to a pre-established case gene pool, the initial test cases are subjected to cross variation to obtain extended test cases corresponding to the initial test cases, and target test cases of the interfaces to be tested are generated according to the initial test cases and the extended test cases, so that a large number of test cases corresponding to the interfaces to be tested of the applications to be tested are generated intelligently and automatically, experiments are performed on real interfaces of real applications through seed cases, a large number of test cases are generated efficiently and high in quality, and the coverage rate of the generated test cases on execution branches of the interfaces to be tested is high.
Description
Technical Field
The embodiment of the specification relates to the technical field of application testing, in particular to a method for generating an interface test case. One or more embodiments of the present specification also relate to an interface test case generation apparatus, a computing device, and a computer-readable storage medium.
Background
With the rapid development of computer and internet technologies, various applications emerge endlessly, and relate to the aspects of people's life and work. Under the background of frequent iterative upgrading of a business process, the requirement is updated quickly, in order to ensure the quality of application in each iterative upgrading, the frequency of faults in the use process is reduced, each iterative upgrading is performed, testers need to perform regression testing on original functions of the application, the same function points need to be regressed each time, at the moment, an artificial regression testing mode is adopted, serious manpower waste can be caused, and both the testing efficiency and the quality can be greatly reduced.
Because the realization of the functions of the application and the interaction between the application and other applications can be realized by calling a plurality of interfaces through program codes, the regression test of the original functions of the application can be realized through the test of the interfaces. In the prior art, when an interface is tested, a tester often writes a test case manually to test the interface. However, in the above method, the cost of compiling the interface test case is high, the tester needs to be familiar with the test service, the test experience is rich, the test case can be manually compiled, the requirement on the service capability of the tester is high, and the efficiency and the quality of manually compiling the test case are low.
Disclosure of Invention
In view of this, embodiments of the present specification provide a method for generating an interface test case. One or more embodiments of the present disclosure also relate to an apparatus for generating an interface test case, a computing device, and a computer-readable storage medium, so as to solve technical deficiencies in the prior art.
According to a first aspect of the embodiments of the present specification, there is provided a method for generating an interface test case, including:
acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case;
acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information;
and carrying out cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case.
According to a second aspect of the embodiments of the present specification, there is provided an apparatus for generating an interface test case, including:
the device comprises an obtaining module, a judging module and a judging module, wherein the obtaining module is configured to obtain case execution data corresponding to an interface to be tested of an application to be tested, and perform clustering screening on the case execution data to obtain seed cases;
the screening module is configured to acquire execution information of the seed case at the interface to be tested, and screen an initial test case from the seed case according to the execution information;
and the generating module is configured to perform cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generate a target test case of the interface to be tested according to the initial test case and the extended test case.
According to a third aspect of embodiments herein, there is provided a computing device comprising:
a memory and a processor;
the memory is configured to store computer-executable instructions, and the processor is configured to execute the computer-executable instructions to perform the steps of:
acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case;
acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information;
and carrying out cross variation on the initial test case according to a case gene pool established in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case.
According to a fourth aspect of the embodiments of the present specification, there is provided a computer-readable storage medium storing computer-executable instructions, which when executed by a processor, implement the steps of any one of the interface test case generation methods.
One embodiment of the present specification provides a method for generating an interface test case, which includes acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case; acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information; and carrying out cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case. Under the condition, case execution data corresponding to an interface to be tested of the application to be tested can be obtained, the case execution data is real flow data on a line, a seed case can be constructed through the real flow data on the line, an initial test case is screened out based on the real execution condition of the seed case in the interface to be tested, the initial test case is subjected to cross variation subsequently, and an extended test case corresponding to the initial test case is obtained, so that a large number of test cases corresponding to the interface to be tested of the application to be tested are generated intelligently and automatically, experiments are conducted on the real interface of the real application through the seed case, a large number of test cases are generated efficiently and high in quality, and the coverage rate of the generated test cases on the execution branch of the interface to be tested is high.
Drawings
Fig. 1 is a flowchart of a method for generating an interface test case according to an embodiment of the present specification;
fig. 2a is a schematic diagram of a target link according to an embodiment of the present disclosure;
FIG. 2b is a schematic cross-sectional diagram illustrating a use case provided in an embodiment of the present disclosure;
FIG. 2c is an expanded view of a use case gene pool provided in an embodiment of the present disclosure;
fig. 2d is a schematic diagram of an interface test case generation architecture according to an embodiment of the present disclosure;
fig. 2e is a diagram of a test case generation architecture according to an embodiment of the present specification;
FIG. 2f is a schematic diagram of an environment architecture of a genetic algorithm provided in an embodiment of the present disclosure;
FIG. 2g is a schematic illustration of a lifecycle provided by an embodiment of the present description;
fig. 2h is a schematic diagram of a use case execution according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of an interface test case generation apparatus according to an embodiment of the present specification;
fig. 4 is a block diagram of a computing device according to an embodiment of the present disclosure.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present description. This description may be embodied in many different forms and should not be construed as limited to the embodiments set forth herein, as those skilled in the art will be able to make and use the present disclosure without departing from the spirit and scope of the present disclosure.
The terminology used in the description of the one or more embodiments is for the purpose of describing the particular embodiments only and is not intended to be limiting of the description of the one or more embodiments. As used in one or more embodiments of the present specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in one or more embodiments of the present specification refers to and encompasses any and all possible combinations of one or more of the associated listed business processes.
It will be understood that, although the terms first, second, etc. may be used herein in one or more embodiments to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, a first can also be referred to as a second and, similarly, a second can also be referred to as a first without departing from the scope of one or more embodiments of the present description. The word "if" as used herein may be interpreted as "at" \8230; "or" when 8230; \8230; "or" in response to a determination ", depending on the context.
First, the noun terms to which one or more embodiments of the present specification relate are explained.
Flow data: by collecting the flow of the online machine, the data obtained by the real request and the service response result of the online user are obtained on the premise of not influencing the normal use of the user.
A genetic algorithm: the genetic algorithm is an adaptive random search heuristic algorithm. The basic architecture of the genetic algorithm is a self-organizing and self-adapting artificial intelligence technology which is based on natural selection rules and genetic theory and is used for simulating and solving the problem of the evolution mode and heredity of organisms in the nature.
Interface testing: the interface test is to check whether the requirements of functionality, safety and performance specified by the interface specification are met by the relationship between the input under different conditions of the interface and the output used by the interface, including the data interaction of the component interfaces in the system and the data interaction of the interfaces between different systems and systems.
CFG: a Control Flow Graph (Control Flow Graph), also called a Control Flow Graph, is an abstract representation of a process or program, and is a data structure representing a Control branch structure in program code.
Java-agent: the Java-agent is a native programming interface provided by the Java virtual machine to the outside, and the external process can acquire a plurality of information of the JVM during running through the JVMTI.
Mock: mock is a method for creating a virtual object to test development during development for some objects that are not easily constructed or easily obtained.
It should be noted that, in the background of frequent iterative upgrade of the business process, the requirement is updated quickly. In order to ensure the quality of application, each iteration, testers need to perform regression testing on the original functions of the application, each integration also needs to perform regression on the same function points at each time, and at this time, a regression testing mode of the manpower point points is adopted, so that serious manpower waste can be caused, and the work efficiency and the quality are greatly reduced. The interface test can bring high-efficiency defect detection and quality supervision capability for agile development, and is mainly embodied in the following aspects: continuous integration is easier to realize, and the regression speed is improved, because the link is short, the bug is easier to position before integration; the test cost is lower, the efficiency is higher, and the interface test can provide a low-cost and high-efficiency solution under the condition that the complexity of the system rises.
Currently, there are two main implementation methods for interface testing in the industry: 1. the development or test classmates manually compile test cases by using tools such as ACTS, ITEST and the like, and the method has the advantages of comprehensive coverage and high compiling cost and has the defects that the compiling cost is high, the business process is required to be familiar, and experts experience manual data making and mock making; 2. the method has the advantages of no writing cost and the disadvantages of large quantity of recorded flow, high noise reduction cost and unstable coverage rate.
In addition, for test case generation, currently, unit test cases are mainly researched, and currently, main implementation schemes include: an analysis-based approach, a search-based approach. Mainstream tools using these approaches include: zest, AFL, evosuite, samrtUnit, and the like. Analysis-based methods often cannot handle the complexity of modern internet technology systems, or require too much manual adaptation to accommodate; search-based methods can mostly only handle binary-level mutations, which is often not enough in case most software does not accept arbitrary binary data, since it may consume a lot of computing resources to bypass the verification. There are also some solutions that attempt to solve this problem by introducing a parameter generator that decodes an arbitrary bit sequence into a valid input. This method is superior in efficiency to the conventional method, which may have a good effect in unit testing, but it is difficult to use a complex type of data as a seed for interface testing because there is no simple method of encoding a complex type of input data into a binary sequence
In order to solve the above problems, the present specification provides an automatic and intelligent generation scheme for an interface test case, and a genetic algorithm and an algorithm training environment improved for the interface test case of an internet system are designed and built to automatically generate the interface test case of the internet system.
In the present specification, a method for generating an interface test case is provided, and the present specification relates to an apparatus for generating an interface test case, a computing device, and a computer-readable storage medium, which are described in detail in the following embodiments one by one.
Fig. 1 is a flowchart illustrating a method for generating an interface test case according to an embodiment of the present disclosure, which includes steps 102 to 106.
Step 102: the method comprises the steps of obtaining case execution data corresponding to an interface to be tested of an application to be tested, carrying out cluster screening on the case execution data, and obtaining a seed case.
It should be noted that, the use case execution data is real online traffic data, that is, real data generated when the online business process runs through the interface to be tested of the application to be tested, that is, historical business process data. During specific implementation, historical real flow data of the online business process can be recorded, and case execution data corresponding to the interface to be tested of the application to be tested is obtained.
In practical application, the seed case is mainly obtained by clustering and screening case execution data on lines, and selecting representative cases of about N cases from thousands to hundreds of thousands of case execution data to serve as the seed case of the algorithm.
In an optional implementation manner of this embodiment, the case execution data, that is, the obtained online traffic, may be obtained by analyzing differences between effective features and structures in the case execution data, and picking out about N representative traffic as a seed case of an algorithm, that is, performing cluster screening on the case execution data to obtain a seed case, where the method includes:
determining valid features and structural differences in the use case execution data;
and determining a seed case from the case execution data according to the effective characteristics and the structural difference.
It should be noted that the use case execution data obtained from the online and generated by the business process operation includes many features, for example, the use case execution data may include valid features and invalid features. The effective characteristics refer to characteristics with discrimination in case execution data, and are mainly characteristics similar to product codes, mechanism codes, money amount and the like which can affect code logic; invalid features refer to features that do not normally affect the logic of the code, like order numbers, serial numbers, user identifications, etc.
In addition, the data formats of different use case execution data generated by different business processes may not be the same, so that structural differences may exist between different use case execution data, where the structural differences are that the use case execution data acquired on a line is usually saved in a nested json format, and includes a form of nested key value pairs, and when the keys of the use case execution data are not consistent (no matter how many or few), the data structures may be considered to be inconsistent.
In practical application, which types of features are preset as effective features, for example, the features of product codes, mechanism codes and money types are preset as effective features, and at this time, cases which include effective features and have structural differences can be screened from the acquired execution data of each case to serve as seed cases. Therefore, the use cases with different structures can enrich the diversity of the seed use cases.
In the embodiment of the specification, the seed cases can be determined from a large amount of acquired case execution data according to effective characteristics and structural differences in the case execution data, the screened seed cases all comprise effective characteristics and are identical in structure, the interfaces to be tested of the applications to be tested can be effectively tested, and the seed cases are all data structures which can be identified by the interfaces to be tested of the applications to be tested, so that the test cases corresponding to the interfaces to be tested of the applications to be tested can be conveniently expanded based on the seed cases, and therefore a large amount of test cases can be generated efficiently and in high quality.
Step 104: and acquiring the execution information of the seed case at the interface to be tested, and screening the initial test case from the seed case according to the execution information.
It should be noted that the seed use case may help to clean the target overlay branch link by being replayed in the interface to be tested. That is, the seed cases are input into the interface to be tested for pre-running to obtain corresponding execution information, and according to the execution information, which branches are covered and which branches are not covered can be determined, so that the initial test cases are screened out from each seed case, and the screened initial test cases can be subsequently used as parent cases to perform case expansion through a genetic algorithm.
In an optional implementation manner of this embodiment, the screening, according to the execution information, an initial test case from the seed case includes:
generating a control flow chart corresponding to the interface to be tested according to the execution information, and determining an uncovered target link corresponding to the interface to be tested according to the control flow chart;
determining fitness scores of the seed use cases to all target links, and generating fitness vectors of the seed use cases according to all the fitness scores, wherein the value of each dimensionality in the fitness vectors is the fitness score of the seed use cases to the corresponding target links;
aiming at each target link, determining the screening probability of each seed case according to the fitness score of each seed case;
and screening the initial test cases from the seed cases according to the screening probability.
Specifically, the seed use case is input to the interface to be tested of the application to be tested, so that the execution result, that is, the execution information, of the seed use case through the interface to be tested of the application to be tested can be obtained, and a control flow diagram of the interface to be tested for data can be generated according to the execution information, where the control flow diagram can indicate which execution branches are included in the processing logic of the interface to be tested for data, each execution branch passes through which nodes and the like, which execution branches can be currently covered, and which execution branches are not currently covered, that is, uncovered target links. The target link refers to an execution branch which is not covered by data, that is, no case can test the execution branch, and in order to ensure the test integrity of the interface to be tested, a test case capable of covering the target link needs to be generated, so that the test of the target link can be realized.
It should be noted that, by replaying the seed use case in the interface to be tested, the code coverage, i.e. the execution information, can be collected. For each conditional statement that is covered, if at least one execution branch is not executed in this step, then those execution branches will be set as the target link in the subsequent genetic algorithm, i.e., the benchmark for test case augmentation. For example, fig. 2a is a schematic diagram of a target link provided in an embodiment of the present specification, and as shown in fig. 2a, a control flow tree of an exemplary interface to be tested is shown, in which a pre-run main link is covered but other links are not covered by replaying a seed use case (i.e., historical data), and a 3-entry target link (target links 1-3) as shown in fig. 2a is generated.
In the embodiment of the present specification, the interface test case generation problem may be described as a multi-objective optimization problem. That is, the goal is to generate one test case that can cover multiple target links. Thus, the fitness value of the test case will be a vector, where the value of each dimension is the fitness score of the test case to the target link.
In practical application, fitness scores from a seed case to each target link can be determined, a fitness vector of the seed case is generated according to each fitness score, the fitness score from the seed case to a certain target link can represent the reliability of the seed case for testing the target link, therefore, the screening probability of each seed case can be determined according to the fitness score of each seed case aiming at each target link, the screening probability represents the probability that the seed case is screened out and can be used for testing the corresponding target link of an interface to be tested, based on the screening probability, the corresponding target link which is suitable for the interface to be tested can be screened out from each seed case, a reliable initial test case which can be used for testing the target link can be realized, the test case can be expanded based on the screened initial test case subsequently, the quality of the expanded test case is high, and the larger probability can cover the execution branch which is not covered currently in the interface to be tested.
It should be noted that, in the generation stage of the interface test case, an improved genetic algorithm is designed, the seed case, the target link and the pre-created gene pool form a data chassis of the genetic algorithm, and then a complete generation algorithm of the interface test case can be formed through fitness calculation, case sequencing screening, case crossing and case variation.
In this embodiment of the present specification, the determining fitness scores of the seed use cases to the respective target links includes:
determining the branch distance and the link depth from the seed use case to each target link;
and determining the fitness score of the seed case to each target link according to the branch distance and the link depth from the seed case to each target link.
It should be noted that the fitness score specifically includes two parts, namely a branch distance and a link depth, and the branch distance from the seed case to each target link may represent a value that needs to be changed by the internal variable of the target link that the obtained case wants to go to the code through the resolving capability of a code bytecode (the bytecode is a binary file including an execution program and composed of a sequence of code/data pairs, and is an intermediate code); the link depth refers to the depth of a code branch link, and as shown in fig. 2a, the longest link depth is 5, and the link depth can be calculated to obtain the hierarchical distance.
In practical application, the link depth from the seed case to each target link can be obtained by calculating according to the following formula (1):
wherein r is i Denotes the ith target link, t j Denotes the jth seed case, al (r) i ,t j ) Representing seed case t j To the target link r i Link depth of (r), uncovered (r) i ,t j ) Representative seed case t j Uncovered to target link r i Number of nodes, num (r) i ) Representing the target link r i The total number of nodes.
In addition, the branch distance from the seed case to each target link can be obtained by calculating the following formula (2):
wherein r is i Denotes the ith target link, t j Denotes the jth seed case,/ i Indicates the number of target links, d (r) i ,t j ) Representing a seed case t j To the target link r i M denotes the target link r i Number of middle branch nodes, p (r) i ,t j M) represents a seed case t j At the target link r i The branch distance of the mth branch node on, norm (x) =1-1.001 -x In order to distance the branches p (r) i ,t j M) normalized to (0, 1)]In the interval of the time interval, representing the target link r i The depth of the mid-branch node m,representing the target link r i Middle dividerDepth of a branch node n, l j The number of seed cases is shown.
In a specific implementation, when calculating the branch distance of the branch node of the seed use case on the target link, the branch distance may be calculated based on the correspondence between the branch predicate of the branch node and the branch distance. The branch predicate is an abstraction of a code branch, that is, a mathematical abstraction of code logic such as if/else/switch/judge in the code, and the branch distance is how to calculate the branch distance for the abstraction.
As an example, the correspondence between the branch predicate and the branch distance is shown in table 1 below, where D is only a constant, a represents a variable at a bytecode level, b represents a decision constant at the bytecode level to determine the branch run, and if | a-b | =0 then 0 else a-b | + D represents that the branch distance is 0 when the branch decision is equal to 0 and | a-b | + D when the branch decision is not equal to 0.
Table 1 correspondence table of branch predicates and branch distances
Branching predicate | Branch distance |
a=b | if|a-b|=0 then 0 else|a-b|+D |
a!=b | if|a-b|!=0 then 0 else|a-b|+D |
a<b | if a-b<0 then 0 else(a-b)+D |
a<=b | if a-b<=0 then 0 else(a-b)+D |
a>b | if b-a<0 then 0 else(b-a)+D |
a>=b | if b-a<=0 then 0 else(b-a)+D |
boolen | if True then 0 else D |
In addition, the calculation process of the fitness score may be expressed as the following formula (3):
wherein,representing individual seed use cases (i.e. seed use case t) 1 -t j ) To respective target links (i.e. target link r) 1 -r i ) Fitness score of (a), d (r) i ,t j ) Representing test cases t j Target link r not covered i The branch distance of (2).
It should be noted that the fitness score from each seed case to each target link can be calculated according to the branch distance and the link depth from each seed case to each target link, and the fitness score calculated by combining the branch distance and the link depth is more accurate, so that parent cases which can be subjected to cross variation through a genetic algorithm can be conveniently and accurately screened out in the follow-up process, and the seed cases are expanded to obtain high-quality test cases.
In an optional implementation manner of this embodiment, determining the screening probability of each seed use case according to the fitness score of each seed use case includes:
and sequencing the seed cases according to the fitness scores, and determining the screening probability of each seed case according to the sequencing result.
It should be noted that, because the fitness scores from each seed case to each target link are different and have different values, such that different seed cases are selected as parent cases, and the quality of the test cases expanded by the genetic algorithm also has different values, so that for each target link, the screening probabilities of each seed case for the target link, that is, the seed case is selected as a parent case under the target link, the probability of the test case corresponding to the target link is expanded, and based on the screening probabilities, the initial test case can be screened from each seed case, where the screened initial test case is the seed case under the target link, which is most suitable for being used as the parent case for expansion.
In practical application, in each iteration, for each target link which includes each node and is not completely covered yet, two seed cases can be selected to expand to obtain a new test case, so that for each target link, the seed cases can be sorted according to the corresponding fitness score, and then, the screening probability that each seed case is selected as a parental case is calculated from the seed case with the highest fitness score until two necessary parental cases are selected.
In specific implementation, the screening probability of each seed case under a certain target link can be obtained by calculating according to the following formula (4):
wherein,representing the target link r i Seed dropping case t j Screening probability, epsilon, of cases screened as parentA small constant value is indicated that is set,and m represents the number of use cases of each seed use case at present.
In the embodiment of the specification, for each target link, based on the sequence of the fitness scores of each seed case, the parent cases used in genetic variation through a genetic algorithm in the next step are screened, the screening probability is calculated according to the fitness scores, and the seed cases with high screening probability are screened to show that the seed cases have better performance in each seed case and are more likely to be selected as the parent cases of the next generation. Therefore, the selected needles in each seed case have high adaptability to the target link, and can be used as parent cases of the next generation with better performance, so that the performance of the parent cases can be improved, and the quality of the test cases expanded based on the parent cases can be improved.
Step 106: and carrying out cross variation on the initial test case according to a case gene pool established in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case.
It should be noted that the genetic algorithm includes operations such as fitness calculation, crossover, mutation, and the like, and the mutation is that a parent gene is mutated, for example, replaced by another gene, and when the mutation is performed, some genes are required to be referred to perform the mutation on the parent gene, thereby defining a gene pool. Wherein, a gene refers to data involved in a genetic algorithm, if a parental relationship exists between two genes, the two genes are parental genes, that is, the parental gene refers to parental data with parental relationship, and the parental data is changed, that is, mutated. The gene pool is a gene set comprising a large number of reference genes, the reference genes refer to reference data provided in the gene pool, the reference genes can provide reference for parent genes to be mutated, namely, some reference genes can be selected from the gene pool, and the parent genes are re-assigned based on the reference genes selected from the gene pool, so that the mutation process is realized.
In this embodiment, the data type may be case data, that is, the gene in this embodiment refers to case data, the parent gene at this time is a parent case having a parent relationship, and when the parent case is changed subsequently, some parameters in the parent case need to be re-assigned, so that the gene pool at this time is a case gene pool, the case gene pool may refer to a set created in advance and containing a large number of reference cases, that is, the gene in the case gene pool is a parameter included in a reference case, the case gene pool may provide a reference for genetic variation of an initial test case, genetic variation is performed based on the gene in the case gene pool, that is, a certain reference case may be selected from the case gene pool, and the parameter of the parent case is re-assigned based on the parameter included in the reference case, so that the reliability of genetic variation is improved, and thus, an extended test case with high quality is obtained.
In an optional implementation manner of this embodiment, the performing cross variation on the initial test case according to a pre-created case gene pool to obtain an extended test case corresponding to the initial test case includes:
selecting a parent case from the initial test cases, and acquiring a set cross attribute;
according to the cross attribute, the parent use case is crossed to obtain an initial expansion use case;
and carrying out variation on the initial expansion case according to a case gene pool created in advance to obtain an expansion test case corresponding to the initial test case.
It should be noted that the initial test cases are cases screened from the seed cases, which have high adaptability and reliability, and all of the initial test cases can be used as parent cases to perform genetic variation to obtain corresponding extended test cases, so that any two of the screened initial test cases can be randomly selected as parent cases to obtain set cross attributes, then the parent cases are crossed according to the cross attributes to obtain initial extended cases, and then the initial extended cases are varied according to a pre-established case gene pool to obtain the extended test cases corresponding to the initial test cases.
The cross attribute refers to an attribute corresponding to a feature parameter that needs to be crossed in a parent use case, and the cross attribute can be set in advance based on a genetic variation requirement.
In the embodiment of the present specification, parent cases may be intersected based on a preset intersection attribute, and then an extended test case corresponding to an initial test case may be obtained by performing variation according to a case gene pool created in advance, so that the quality of the obtained extended test case is improved by performing a cross-variation dual genetic process.
In an optional implementation manner of this embodiment, the parent use case is a tree structure, and nodes in the tree structure are feature parameters included in the parent use case; the step of crossing the parent use case according to the crossing attribute to obtain an initial extended use case comprises the following steps:
determining whether child use cases corresponding to the parent use cases comprise the cross attributes or not according to the cross attributes;
if yes, directly exchanging subtrees corresponding to the target nodes in the parent use case to obtain the initial expansion use case;
if any parent use case does not comprise the target use case, determining the previous node of the target node in the target parent use case as an updating node, exchanging a subtree taking the updating node as a root node in the parent use case, and obtaining the initial extended use case, wherein the target parent use case is the parent use case comprising the target node corresponding to the cross attribute.
It should be noted that each parent use case includes a large number of various feature parameters, so that an attribute corresponding to a feature parameter that needs to be intersected, that is, an intersection attribute, may be preset, and then, based on the intersection attribute, multi-level hierarchical intersection is performed.
In practical application, each parent case may be represented as a tree, and each feature parameter included in the parent case is a node in the tree, so that it may be determined whether each node included in the parent case includes a target node corresponding to a set cross attribute, and if both nodes include the target node corresponding to the set cross attribute, it indicates that both the parent cases include the feature parameter corresponding to the set cross attribute, at this time, a subtree corresponding to the target node in both the parent cases may be directly exchanged, where the subtree is a parent node of the target node and each child node included in the parent node, and an initial extension case is obtained.
In addition, if any parent use case does not include any feature parameter, it indicates that a certain parent use case does not include the feature parameter corresponding to the set cross attribute, and at this time, the subtree corresponding to the target node in the two parent use cases cannot be directly exchanged, so that at this time, in the target parent use case including the target node corresponding to the cross attribute, the previous node of the target node can be determined to be an update node, and the subtree in the two parent use cases, which takes the update node as a root node, is exchanged, so as to obtain the initial extension use case.
If the two parent use cases do not include any feature parameter, it is indicated that the two parent use cases do not include the feature parameter corresponding to the set intersection attribute, and at this time, intersection may not be performed, or nodes in the two parent use cases may be randomly selected to perform intersection, which is not limited in this specification.
For example, fig. 2b is a schematic diagram of use case intersection provided in an embodiment of this specification, and as shown in fig. 2b, a parent use case 1 and a parent use case 2 are respectively represented as structures of two trees, and respective nodes included in the two trees are respective feature parameters included in the parent use case. If the algorithm decides to perform a crossover operation and sets attribute d as the crossover attribute, it will first check whether there is a target node in the two parent cases that corresponds to such attribute. As shown in FIG. 2b, both parent use cases contain a target node D corresponding to the attribute D, so that the subtrees corresponding to the node D can be directly swapped, which will result in the initial extension use case 1 and the initial extension use case 2, i.e., directly replace the parent nodes C1 and C2, and their corresponding child nodes, i.e., swap [ C1, D1, E1, F1] and [ C2, D2, F2]. Otherwise, if the target node corresponding to the cross attribute cannot be found in one parent case, for example, when the cross attribute is attribute E, the parent case 1 includes the target node E corresponding to the attribute E, but the parent case 2 does not include the target node E corresponding to the attribute E, then the previous updated node of the target node may be searched in the target parent case (i.e., the parent case 1), which is node D in fig. 2b, and under a certain possibility, subtrees in the two parent cases, which take node D1 and node D2 as root nodes, will be exchanged to generate the initial expansion case 3 and the initial expansion case 4, as shown in fig. 2b, nodes D1 and D2 do not have child nodes, and thus nodes D1 and D2 are directly exchanged. The above process may be repeated until the swap is performed or the root attribute is reached. For the latter case, the initial augmented use case (i.e., child use case) remains the same as the parent use case.
In the embodiment of the specification, once two parent cases are selected, the cross operation is executed with a certain probability when offspring is generated, a multi-level cross strategy is designed when the cross operation is executed, the variability of initial expansion cases generated by genetic variation of the parent cases is improved, and the richness and the quality of the subsequent expansion test cases are improved.
In an optional implementation manner of this embodiment, the mutating the initial extended use case according to a pre-created use case gene pool to obtain an extended test case corresponding to the initial test case includes:
calculating the mutation rate of a target leaf node in the initial expansion use case based on the pre-created use case gene pool aiming at the target leaf node, wherein the target leaf node is any leaf node in the initial expansion use case;
determining whether the target leaf node is mutated based on the mutation rate;
and if so, acquiring a target gene from a private gene pool corresponding to the target leaf node, and assigning values to the target leaf node according to the target gene to acquire an extended test case corresponding to the initial test case.
It should be noted that after the hierarchical intersection operation is performed, an initial expansion use case may be obtained, and value variation of a combined gene pool may be performed for leaf nodes of the initial expansion use case obtained after the intersection. In specific implementation, for each leaf node in the obtained initial expansion use case, based on a pre-created use case gene pool, a variation rate of the leaf node is calculated, then based on the determined variation rate, whether the leaf node needs to be varied is determined, if necessary, based on a private gene pool corresponding to the leaf node, genes (namely, characteristic parameters) in the leaf node are randomly selected, and the leaf node is re-assigned to obtain the varied expansion test case.
The private gene pool is a gene pool which is shared by each parameter in each use case, namely, the private gene pool corresponding to each node, and the application dimension gene pool (namely, the pre-created use case gene pool) is a set of the private gene pools corresponding to each node of each use case. Each node included in each use case corresponds to a private gene pool, and the private gene pool comprises genes capable of replacing characteristic parameters of the corresponding nodes.
In a specific implementation, the mutation rate of the target leaf node can be obtained by calculating according to the following formula (5):
wherein,is the variation rate of the leaf node m in the initial expansion case i; delta m Is a variation constant;representing the diversity of the two initial extension use cases (i.e. the two parent use cases),representing initial augmentation use case t a And initial expansion use case t b The similarity between the original extension case and the original extension case, the hamming (X, Y) represents the hamming distance between X and Y, Z represents the number of the characteristic parameters included in the original extension case,representInitial expansion use case t a The ith characteristic parameter.
In the embodiment of the description, the leaf node can be mutated based on the private gene pool corresponding to the leaf node included in the initial expansion case, and reference is provided for the characteristic parameter mutation of the initial expansion case based on the private gene pool, so that the variability of the expansion test case generated by genetic mutation is improved, the reliability of the genetic mutation is improved, and the richness and quality of the obtained expansion test case are improved.
In an optional implementation manner of this embodiment, before calculating the mutation rate of the target leaf node based on the pre-created use case gene pool, the method further includes:
obtaining effective characteristics in case execution data corresponding to each interface to be tested;
acquiring an enumeration field and a static field of code scanning;
and constructing a use case gene pool corresponding to the application to be tested according to the effective characteristics, the enumeration field and the static field.
It should be noted that, before calculating the variation rate, a use case gene pool may also be created first, where the use case gene pool is a use case gene set of an application dimension, and is a set composed of private gene pools corresponding to each characteristic parameter of each use case. In the generation of the interface test case, both the master entry of the interface and the mock return value of the sub-call contain a large number of characteristic parameters containing business semantics, so when the parameters are changed, if only simple random variation is relied on, the efficiency is very low.
It should be noted that the source of the use case gene pool includes an effective characteristic field in the use case execution data obtained online, and an enumeration field and a static field of code scanning. The use case is composed of nested key-value key value pairs, the fields are the values in the key value pairs, and all the values possibly corresponding to a certain key are stored in the use case gene pool. The code refers to an execution code of the application to be tested, the enumeration field and the static field refer to certain values which are stored in the code as variables or constants by a programmer when the code is written, and the values are generally in association with certain characteristic parameters in the test case, so that the code can be scanned to obtain the enumeration field and the static field to supplement the gene pool of the use case, and the sufficiency of the characteristic parameters in the gene pool of the use case is improved.
In an optional implementation manner of this embodiment, the use case execution data is composed of nested key value pairs, and each key value corresponding to any key is stored in the use case gene pool;
after the case gene pool corresponding to the application to be tested is constructed according to the valid features, the enumeration field and the static field, the method further comprises the following steps:
and expanding the use case gene pool according to the key value pair of the use case execution data.
It should be noted that, each case execution data used for constructing the case gene pool is stored in the form of key-value key value pairs, so that the genes (i.e., valid fields) in the case gene pool can be supplemented based on the similarity of the key values and the similarity of the value values of the case execution data, so as to extend the valid features (i.e., value values) of the case execution data stored in the case gene pool, so as to improve the sufficiency of the feature parameters in the case gene pool.
In addition, the enumeration field and the static field are used as auxiliary information supplement in the gene pool, and are not expanded.
In an optional implementation manner of this embodiment, the expanding the use case gene pool according to the key-value pair of the use case execution data includes:
calculating a matching value of each key to be supplemented and the key to be matched, selecting the key to be matched with the highest matching value and larger than a confidence threshold value for each key to be supplemented as an extended field corresponding to the key to be supplemented, and fusing the key to be supplemented and the extended field; and/or the presence of a gas in the atmosphere,
determining the cosine distance between the text vector to be supplemented and the vectors of the whole text set, taking the text with the cosine distance smaller than the threshold value as the text to be fused corresponding to the supplement, and fusing the supplement and the text to be fused.
It should be noted that, the first round may be to supplement the key (key) strong similarity matching field through the key value similarity. And calculating the matching score of each key value (key to be supplemented) to be matched and the key value (key to be matched) to be supplemented by a Needleman-Wunsch algorithm, and selecting the key value to be matched with which the matching score is highest and is greater than a confidence threshold value for each key value to be supplemented. The key values to be supplemented are all key values in the case execution data corresponding to the interface to be tested, and the key values to be matched are all key values in the case execution data of the application dimension to be tested.
In addition, the value strong correlation matching field is supplemented through the value similarity in the second pass. Taking each feature set (i.e. a set formed by all genes corresponding to the feature in the example gene pool) in the example gene pool as a text of natural word segmentation, wherein each feature set is equivalent to a text, the whole gene pool formed by all genes in the example gene pool is equivalent to a text set, using TF-IDF algorithm to vectorize the text to obtain a vector of the text and a vector space of the whole text set, calculating the cosine distance between the text vector which has been subjected to the feature transformation of the input/mock point and the whole text set, and taking the text of which the cosine distance is less than a threshold value as the text to be fused. The existing entry/mock point refers to a key-value key value pair contained in the use case execution data which is cleaned from the line currently, and the key value pair can be divided into an entry key value pair and a mock point key value pair from the perspective of an actual system.
For example, fig. 2c is an expanded schematic diagram of a use case gene pool provided in an embodiment of the present specification, and as shown in fig. 2c, a value corresponding to "xxx.xxx.xxx. Key value 1" may be supplemented to a value corresponding to "xxx.xxx. Key value 2" through key value similarity, i.e., key value similarity in the first round, and a value strong similarity matching field may be supplemented to a value corresponding to "xxx.xxx.xxx. Key value 2" through value similarity, i.e., number value similarity in the second round, and "value 1, value 2, and value 3" may be supplemented to a value corresponding to "xxx.xxx.xxx. Key value 2" through value similarity, i.e., key value similarity in the second round.
In the embodiment of the specification, two rounds of expansion can be performed through the similarity of key and value, so that the sufficiency of characteristic parameters in a construction acquisition case gene pool is improved.
It should be noted that, the present solution is an interface test case generation method based on a genetic algorithm, where the genetic algorithm is applied to interface test case generation, and a general architecture is shown in fig. 2d, and includes two core modules: the method comprises the steps of designing a core algorithm, namely a genetic algorithm, which effectively solves the generation characteristics of the Internet interface test case, and designing an algorithm execution environment which can stably and quickly call an interface to be tested of an application to be tested and collect various execution information in the execution process.
As shown in fig. 2d, a seed parameter is prepared, that is, a large amount of case execution data is obtained from the online, the case execution data is input to an algorithm execution environment (that is, a parameter is input), the algorithm execution environment can call, mock, execution monitor, and the like through an interface of an application to be tested, the case execution data input by the execution environment is output, corresponding execution information is output, that is, the genetic algorithm obtains execution information output by the algorithm execution environment, each case execution data is evaluated according to the execution information, an initial test case is selected preferentially, any two initial test cases are selected randomly as parent cases to be crossed, then mutation is performed, a next generation case, that is, an extended test case is obtained, and algorithm iteration is performed continuously. When cross variation is performed, the variation range can be constrained through characteristic parameter analysis (namely, the range, the interval and the association of the characteristic parameters), and the variation weight of each characteristic parameter can be provided through code analysis (namely, parameter weight and control flow).
Fig. 2e is a test case generation architecture diagram provided in an embodiment of the present specification, and as shown in fig. 2e, online case execution data is obtained, and then the case execution data is subjected to cluster screening to obtain a seed case; based on the CFG analysis (i.e., through control flow graph analysis) and the seed use case pre-run, a target link may be determined. Then, based on the seed case and the target link, an MLNO genetic algorithm can be carried out, fitness calculation (including branch distance and link depth, and execution time can be considered) is carried out firstly, then based on the calculated fitness, seed cases are sorted, namely case sorting is carried out based on the fitness optimization, then case crossing is carried out based on the set crossing attribute, case variation is carried out based on genes in a case gene pool, and a new candidate case, namely an expansion test case, is generated. After the expansion test case is generated, iteration can be carried out continuously to obtain a finally expanded test case, the test case is input into the interface to be tested of the application to be tested, the interface to be tested of the application to be tested can be tested, and execution information can be returned to the MLNO algorithm through AGENT in the application to be tested so as to be used for later expansion of the test case.
Fig. 2f is an environment architecture schematic diagram of a genetic algorithm provided in an embodiment of the present specification, and as shown in fig. 2f, a bottom layer technology based on the whole use case generation training environment construction is a java-agent technology, the java-agent is used as an execution main body to control the algorithm, and the life cycle of the algorithm is also interactive control of the java-agent program and an external server through http service of aggregation jetty. The life cycle is shown in FIG. 2g and is divided into 5 life cycles of agen mount, initialization, start algorithm, end algorithm and agen unload.
Wherein, the agent mounting means mounting the java-agent to the java process of the target application. The initialization refers to that the process is divided into two parts, wherein the initialization of a basic object comprises mock range, instrumentation range, tr/http client initialization, seed flow pre-running and the like, and the other part is asm byte code modification. The algorithm starts: initializing a basic function and iteratively operating an algorithm. And (4) finishing the algorithm: and directly ending and ending the time designated by the timer, stopping the operation of the algorithm, acquiring the use case generated by the algorithm, and formatting and returning. Unloading of the agen: and unloading the java-agent from the target process, wherein the normal operation of the application is not influenced after unloading.
It should be noted that the use case execution environment depends on java-agent, the algorithm needs to perform optimization iteration continuously, each iteration needs to provide a stable environment for execution, external data mock, and execution path monitoring, java-agent is a thread mounted in the application program, classes and a loader in the application program can be very easily acquired, and through the acquired classes and the loader, class transformation can be performed by means of injection, so as to achieve the effects of use case execution monitoring and data mock.
Fig. 2h is a schematic diagram of executing a use case according to an embodiment of the present specification, and as shown in fig. 2h, the use case is executed by obtaining a class referenced by a current interface through a java-agent, using fastjson deserialization data as a specific parameter object, and then calling the execute use case through generalized call/http of an rpc interface.
The mock is characterized in that a relatively large number of external calls exist in an interface, for a complete use case, the return values of the external calls are also equal to a part of a use case parameter, so that the whole use case can be correctly run by performing the mock, the original use case and the generated use case in the flow are fastjson serialized character strings, different external calls and frames use different mock means, information is obtained by inserting piles, then a specific object is generated by processing and returned to an upper application program, and the mock means mainly comprises the following steps: the ibatis framework method returns mock: some method return values of the ibaits framework are all generic types, and the actual return type of the method cannot be directly obtained through reflection, so that the type needs to be obtained in advance, the corresponding relation between the sqiid and the actual object type is obtained through code analysis, and then a TypeReference object of the fastjson is generated through a built-in groovy script for deserialization. tr calls mock of some proxy objects: the object is generated by directly acquiring the object method in the proxy class and then returning to the generic type through the reflection acquisition method. The common method returns the value mock: this is in part the generation of objects directly through a single method return value type of reflection acquisition. The method comprises the following steps: the method comprises the steps that a complete use case not only comprises a return value and a join parameter of a main call, but also comprises a return value and a join parameter of a mock point, the return value can be directly generated in the generation of the use case, the join parameter is a result of program execution, the data is recorded, the recording is also performed by adopting stake insertion, and corresponding parameter values are obtained according to a local variable table of a staked method.
In addition, the execution path snooping is also an indispensable part for calculating the branch distance and the branch depth by an algorithm, and because the common if/else branch and the switch branch are not in the expression form of the byte code, the execution path of the program is snooped by adopting a combination of two snooping schemes. jump instruction snooping: before jump (IF _) branching, data in the dup operand stack calculated as branch jumps are represented by the distance of conditional jumps, 0.0 represents jumps, and larger values represent jumps farther away from the jump, false jumps, and vice versa. The method comprises the steps of monitoring a switch instruction, calculating branch distances of all cases, adding an if judgment for each case before the switch, judging the condition value of the switch in a dup operand stack, and then judging through the if, wherein the calculation of the default case needs to be specially processed, because the range of the default is wider and difficult to count, independently generating a switch before the switch to be plugged, jumping to a case Label under the same condition as the original switch, punching two piles before and after the default, respectively counting the conditions of covering and uncovering the default case, and putting the case Label before the two piles, thereby counting the content.
One embodiment of the present specification provides a method for generating an interface test case, which includes acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case; acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information; and carrying out cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case. Under the condition, case execution data corresponding to an interface to be tested of the application to be tested can be obtained, the case execution data is real flow data on a line, a seed case can be constructed through the real flow data on the line, an initial test case is screened out based on the real execution condition of the seed case in the interface to be tested, the initial test case is subjected to cross variation subsequently, and an extended test case corresponding to the initial test case is obtained, so that a large number of test cases corresponding to the interface to be tested of the application to be tested are generated intelligently and automatically, experiments are conducted on the real interface of the real application through the seed case, a large number of test cases are generated efficiently and high in quality, and the coverage rate of the generated test cases on the execution branch of the interface to be tested is high.
Corresponding to the above method embodiment, the present specification further provides an embodiment of a device for generating an interface test case, and fig. 3 illustrates a schematic structural diagram of the device for generating an interface test case provided in an embodiment of the present specification. As shown in fig. 3, the apparatus includes:
an obtaining module 302, configured to obtain case execution data corresponding to an interface to be tested of an application to be tested, perform cluster screening on the case execution data, and obtain a seed case;
a screening module 304, configured to obtain execution information of the seed case at the interface to be tested, and screen an initial test case from the seed case according to the execution information;
a generating module 306 configured to perform cross variation on the initial test case according to a case gene pool created in advance, obtain an extended test case corresponding to the initial test case, and generate a target test case of the interface to be tested according to the initial test case and the extended test case.
Optionally, the obtaining module 302 is further configured to:
determining valid features and structural differences in the use case execution data;
and determining a seed case from the case execution data according to the effective characteristics and the structural difference.
Optionally, the filtering module 304 is further configured to:
generating a control flow chart corresponding to the interface to be tested according to the execution information, and determining an uncovered target link corresponding to the interface to be tested according to the control flow chart;
determining fitness scores of the seed use cases to all target links, and generating fitness vectors of the seed use cases according to all the fitness scores, wherein the value of each dimensionality in the fitness vectors is the fitness score of the seed use cases to the corresponding target link;
aiming at each target link, determining the screening probability of each seed case according to the fitness score of each seed case;
and screening the initial test cases from the seed cases according to the screening probability.
Optionally, the screening module 304 is further configured to:
determining the branch distance and the link depth from the seed use case to each target link;
and determining the fitness score of the seed case to each target link according to the branch distance and the link depth from the seed case to each target link.
Optionally, the screening module 304 is further configured to:
and sequencing the seed cases according to the fitness scores, and determining the screening probability of each seed case according to the sequencing result.
Optionally, the generating module 306 is further configured to:
selecting a parent case from the initial test case, and acquiring a set cross attribute;
according to the cross attribute, the parent use case is crossed to obtain an initial expansion use case;
and carrying out variation on the initial expansion case according to a case gene pool created in advance to obtain an expansion test case corresponding to the initial test case.
Optionally, the parent use case is a tree structure, and nodes in the tree structure are feature parameters included in the parent use case; a generating module 306, further configured to:
determining whether a tree structure corresponding to the parent use case comprises a target node corresponding to the cross attribute or not according to the cross attribute;
if yes, directly exchanging subtrees corresponding to the target nodes in the parent use case to obtain the initial expansion use case;
if any parent use case does not comprise the target use case, determining the previous node of the target node in the target parent use case as an updating node, exchanging a subtree taking the updating node as a root node in the parent use case, and obtaining the initial extended use case, wherein the target parent use case is the parent use case comprising the target node corresponding to the cross attribute.
Optionally, the generating module 306 is further configured to:
calculating the mutation rate of a target leaf node in the initial expansion use case based on the pre-created use case gene pool aiming at the target leaf node, wherein the target leaf node is any node in the initial expansion use case;
determining whether the target leaf node is mutated based on the mutation rate;
and if so, acquiring a target gene from a private gene pool corresponding to the target leaf node, and assigning values to the target leaf node according to the target gene to acquire an extended test case corresponding to the initial test case.
Optionally, the generating module 306 is further configured to:
obtaining effective characteristics in case execution data corresponding to each interface to be tested;
acquiring an enumeration field and a static field of code scanning;
and constructing a use case gene pool corresponding to the application to be tested according to the effective characteristics, the enumeration field and the static field.
Optionally, the use case execution data is composed of nested key value pairs, and each key value corresponding to any key is stored in the use case gene pool; a generating module 306, further configured to:
and expanding the use case gene pool according to the key value pair of the use case execution data.
Optionally, the generating module 306 is further configured to:
calculating a matching value of each key to be supplemented and the key to be matched, selecting the key to be matched with the highest matching value and larger than a confidence threshold value for each key to be supplemented, taking the key to be matched as an expansion field corresponding to the key to be supplemented, and fusing the key to be supplemented and the expansion field; and/or the presence of a gas in the atmosphere,
determining the cosine distance between the text vector to be supplemented and the vectors of the whole text set, taking the text with the cosine distance smaller than the threshold value as the text to be fused corresponding to the supplement, and fusing the supplement and the text to be fused.
One embodiment of the present specification provides an interface test case generation apparatus, which acquires case execution data corresponding to an interface to be tested of an application to be tested, and performs cluster screening on the case execution data to obtain a seed case; acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information; and carrying out cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case. Under the condition, case execution data corresponding to an interface to be tested of the application to be tested can be obtained, the case execution data is real flow data on a line, a seed case can be constructed through the real flow data on the line, an initial test case is screened out based on the real execution condition of the seed case in the interface to be tested, the initial test case is subjected to cross variation subsequently, and an extended test case corresponding to the initial test case is obtained, so that a large number of test cases corresponding to the interface to be tested of the application to be tested are generated intelligently and automatically, experiments are conducted on the real interface of the real application through the seed case, a large number of test cases are generated efficiently and high in quality, and the coverage rate of the generated test cases on the execution branch of the interface to be tested is high.
The foregoing is a schematic scheme of a device for generating an interface test case according to this embodiment. It should be noted that the technical solution of the interface test case generation apparatus and the technical solution of the interface test case generation method belong to the same concept, and details of the technical solution of the interface test case generation apparatus, which are not described in detail, can be referred to the description of the technical solution of the interface test case generation method.
FIG. 4 illustrates a block diagram of a computing device 400 provided in accordance with one embodiment of the present description. The components of the computing device 400 include, but are not limited to, a memory 410 and a processor 420. Processor 420 is coupled to memory 410 via bus 430 and database 450 is used to store data.
Computing device 400 also includes access device 440, access device 440 enabling computing device 400 to communicate via one or more networks 460. Examples of such networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the internet. The Access device 440 may include one or more of any type of Network Interface (e.g., a Network Interface Controller) that may be wired or Wireless, such as an IEEE802.11 Wireless Local Area Network (WLAN) Wireless Interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) Interface, an ethernet Interface, a Universal Serial Bus (USB) Interface, a cellular Network Interface, a bluetooth Interface, a Near Field Communication (NFC) Interface, and so forth.
In one embodiment of the present description, the above-described components of computing device 400, as well as other components not shown in FIG. 4, may also be connected to each other, such as by a bus. It should be understood that the block diagram of the computing device architecture shown in FIG. 4 is for purposes of example only and is not limiting as to the scope of the present description. Those skilled in the art may add or replace other components as desired.
Computing device 400 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., tablet, personal digital assistant, laptop, notebook, netbook, etc.), mobile phone (e.g., smartphone), wearable computing device (e.g., smartwatch, smartglasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or PC. Computing device 400 may also be a mobile or stationary server.
Wherein processor 420 is configured to execute the following computer-executable instructions to implement the following steps:
acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case;
acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information;
and carrying out cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case.
The above is an illustrative scheme of a computing device of the present embodiment. It should be noted that the technical solution of the computing device and the technical solution of the method for generating the interface test case belong to the same concept, and details that are not described in detail in the technical solution of the computing device can be referred to the description of the technical solution of the method for generating the interface test case.
An embodiment of the present specification further provides a computer-readable storage medium, which stores computer instructions, and when the instructions are executed by a processor, the instructions are used to implement the steps of any one of the methods for generating the interface test case.
The above is an illustrative scheme of a computer-readable storage medium of the present embodiment. It should be noted that the technical solution of the storage medium and the technical solution of the method for generating the interface test case belong to the same concept, and details that are not described in detail in the technical solution of the storage medium can be referred to the description of the technical solution of the method for generating the interface test case.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The computer instructions comprise computer program code which may be in the form of source code, object code, an executable file or some intermediate form, or the like. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, read-Only Memory (ROM), random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like.
It should be noted that, for the sake of simplicity, the foregoing method embodiments are described as a series of combinations of acts, but it should be understood by those skilled in the art that the embodiments are not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the embodiments. Further, those skilled in the art should also appreciate that the embodiments described in this specification are preferred embodiments and that acts and modules referred to are not necessarily required for an embodiment of the specification.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
The preferred embodiments of the present specification disclosed above are intended only to aid in the description of the specification. Alternative embodiments are not exhaustive and do not limit the invention to the precise embodiments described. Obviously, many modifications and variations are possible in light of the teaching of the embodiments of the present disclosure. The embodiments were chosen and described in order to best explain the principles of the embodiments and the practical application, to thereby enable others skilled in the art to best understand and utilize the embodiments. The specification is limited only by the claims and their full scope and equivalents.
Claims (14)
1. A method for generating an interface test case comprises the following steps:
acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case;
acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information;
and carrying out cross variation on the initial test case according to a case gene pool established in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case.
2. The method for generating an interface test case according to claim 1, wherein the performing cluster screening on the case execution data to obtain a seed case includes:
determining effective characteristics and structural differences in the case execution data;
and determining a seed use case from the use case execution data according to the effective characteristics and the structural difference.
3. The method for generating the interface test case according to claim 1, wherein the screening the initial test case from the seed case according to the execution information includes:
generating a control flow chart corresponding to the interface to be tested according to the execution information, and determining an uncovered target link corresponding to the interface to be tested according to the control flow chart;
determining fitness scores of the seed use cases to all target links, and generating fitness vectors of the seed use cases according to all the fitness scores, wherein the value of each dimensionality in the fitness vectors is the fitness score of the seed use cases to the corresponding target link;
aiming at each target link, determining the screening probability of each seed case according to the fitness score of each seed case;
and screening the initial test cases from the seed cases according to the screening probability.
4. The method for generating interface test cases according to claim 3, wherein the determining fitness scores of the seed cases to the respective target links includes:
determining the branch distance and the link depth from the seed use case to each target link;
and determining the fitness score of the seed case to each target link according to the branch distance and the link depth from the seed case to each target link.
5. The method for generating interface test cases according to claim 3, wherein the determining the screening probability of each seed case according to the fitness score of each seed case includes:
and sequencing the seed cases according to the fitness scores, and determining the screening probability of each seed case according to the sequencing result.
6. The method for generating an interface test case according to claim 1, wherein the obtaining of the extended test case corresponding to the initial test case by performing cross mutation on the initial test case according to a pre-created case gene pool comprises:
selecting a parent case from the initial test cases, and acquiring a set cross attribute;
according to the crossing attribute, crossing the parent use case to obtain an initial extended use case;
and carrying out variation on the initial expansion case according to a case gene pool created in advance to obtain an expansion test case corresponding to the initial test case.
7. The method for generating interface test cases according to claim 6, wherein the parent case is a tree structure, and nodes in the tree structure are feature parameters included in the parent case; the step of crossing the parent use case according to the crossing attribute to obtain an initial extended use case comprises the following steps:
determining whether a tree structure corresponding to the parent use case comprises a target node corresponding to the cross attribute or not according to the cross attribute;
if yes, directly exchanging subtrees corresponding to the target nodes in the parent use case to obtain the initial expansion use case;
if any parent use case does not comprise the target use case, determining a previous node of the target node in the target parent use case as an updating node, exchanging a subtree taking the updating node as a root node in the parent use case, and obtaining the initial extension use case, wherein the target parent use case is the parent use case comprising the target node corresponding to the cross attribute.
8. The method for generating an interface test case according to claim 6, wherein the obtaining the extended test case corresponding to the initial test case by mutating the initial extended case according to a pre-created case gene pool comprises:
calculating the mutation rate of a target leaf node in the initial expansion use case based on the pre-created use case gene pool aiming at the target leaf node, wherein the target leaf node is any leaf node in the initial expansion use case;
determining whether the target leaf node is mutated based on the mutation rate;
and if so, acquiring a target gene from a private gene pool corresponding to the target leaf node, and assigning values to the target leaf node according to the target gene to acquire an extended test case corresponding to the initial test case.
9. The method for generating interface test cases according to claim 8, wherein before calculating the variability of the target leaf node based on the pre-created case gene pool, the method further comprises:
obtaining effective characteristics in case execution data corresponding to each interface to be tested;
acquiring an enumeration field and a static field of code scanning;
and constructing a use case gene pool corresponding to the application to be tested according to the effective characteristics, the enumeration field and the static field.
10. The method according to claim 9, wherein the case execution data is composed of nested key-value pairs, and each key value corresponding to any key is stored in the case gene pool;
after the construction of the use case gene pool corresponding to the application to be tested according to the valid features, the enumeration field and the static field, the method further comprises the following steps:
and expanding the use case gene pool according to the key value pair of the use case execution data.
11. The method for generating an interface test case according to claim 10, wherein the expanding the case gene pool according to the key-value pair of the case execution data includes:
calculating a matching value of each key to be supplemented and the key to be matched, selecting the key to be matched with the highest matching value and larger than a confidence threshold value for each key to be supplemented as an extended field corresponding to the key to be supplemented, and fusing the key to be supplemented and the extended field; and/or the presence of a gas in the gas,
determining the cosine distance between the text vector to be supplemented and the vectors of the whole text set, taking the text with the cosine distance smaller than the threshold value as the text to be fused corresponding to the supplement, and fusing the supplement and the text to be fused.
12. An apparatus for generating an interface test case, comprising:
the device comprises an obtaining module, a judging module and a judging module, wherein the obtaining module is configured to obtain case execution data corresponding to an interface to be tested of an application to be tested, and perform clustering screening on the case execution data to obtain seed cases;
the screening module is configured to acquire execution information of the seed case at the interface to be tested, and screen an initial test case from the seed case according to the execution information;
and the generating module is configured to perform cross variation on the initial test case according to a case gene pool created in advance to obtain an extended test case corresponding to the initial test case, and generate a target test case of the interface to be tested according to the initial test case and the extended test case.
13. A computing device, comprising:
a memory and a processor;
the memory is to store computer-executable instructions, and the processor is to execute the computer-executable instructions to:
acquiring case execution data corresponding to an interface to be tested of an application to be tested, and performing cluster screening on the case execution data to obtain a seed case;
acquiring execution information of the seed case at the interface to be tested, and screening an initial test case from the seed case according to the execution information;
and carrying out cross variation on the initial test case according to a case gene pool established in advance to obtain an extended test case corresponding to the initial test case, and generating a target test case of the interface to be tested according to the initial test case and the extended test case.
14. A computer-readable storage medium storing computer-executable instructions which, when executed by a processor, implement the steps of the method for generating an interface test case according to any one of claims 1 to 11.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211011460.5A CN115248780A (en) | 2022-08-23 | 2022-08-23 | Interface test case generation method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211011460.5A CN115248780A (en) | 2022-08-23 | 2022-08-23 | Interface test case generation method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115248780A true CN115248780A (en) | 2022-10-28 |
Family
ID=83700448
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211011460.5A Pending CN115248780A (en) | 2022-08-23 | 2022-08-23 | Interface test case generation method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115248780A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116594915A (en) * | 2023-07-17 | 2023-08-15 | 西南交通大学 | Automatic generation method, device, equipment and medium for integrated test cases |
-
2022
- 2022-08-23 CN CN202211011460.5A patent/CN115248780A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116594915A (en) * | 2023-07-17 | 2023-08-15 | 西南交通大学 | Automatic generation method, device, equipment and medium for integrated test cases |
CN116594915B (en) * | 2023-07-17 | 2023-09-29 | 西南交通大学 | Automatic generation method, device, equipment and medium for integrated test cases |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Bavishi et al. | AutoPandas: neural-backed generators for program synthesis | |
Huang et al. | Gamepad: A learning environment for theorem proving | |
Cummins et al. | End-to-end deep learning of optimization heuristics | |
Kaliszyk et al. | Holstep: A machine learning dataset for higher-order logic theorem proving | |
US6282527B1 (en) | Adaptive problem solving method and apparatus utilizing evolutionary computation techniques | |
CN115659281B (en) | Method and device for fusing adaptive acceleration operators | |
Öztürk | Which type of metrics are useful to deal with class imbalance in software defect prediction? | |
CN108491228A (en) | A kind of binary vulnerability Code Clones detection method and system | |
CN110245232A (en) | File classification method, device, medium and calculating equipment | |
CN111767216B (en) | Cross-version depth defect prediction method capable of relieving class overlap problem | |
CN115248780A (en) | Interface test case generation method and device | |
CN112783513B (en) | Code risk checking method, device and equipment | |
John et al. | A graph-based framework for model-driven optimization facilitating impact analysis of mutation operator properties | |
Liu et al. | Learning graph-based code representations for source-level functional similarity detection | |
CN113536308A (en) | Binary code tracing method for multi-granularity information fusion under software gene view angle | |
Zhou et al. | Deeptle: Learning code-level features to predict code performance before it runs | |
CN111966818A (en) | Interactive API code segment recommendation method based on deep learning | |
CN116502648A (en) | Machine reading understanding semantic reasoning method based on multi-hop reasoning | |
CN116974554A (en) | Code data processing method, apparatus, computer device and storage medium | |
CN114297063B (en) | Method and system for automated formal modeling and verification of source code | |
Utkin et al. | Evaluating the impact of source code parsers on ML4SE models | |
CN112749082B (en) | Test case generation method and system based on DE-TH algorithm | |
Ma et al. | Parallel exact inference on multicore using mapreduce | |
Bobde et al. | Software restructuring models for object oriented programming languages using the fuzzy based clustering algorithm | |
Wei | Abstraction mechanism on neural machine translation models for automated program repair |
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 |