CN110879776A - Test case generation method and device - Google Patents

Test case generation method and device Download PDF

Info

Publication number
CN110879776A
CN110879776A CN201811037094.4A CN201811037094A CN110879776A CN 110879776 A CN110879776 A CN 110879776A CN 201811037094 A CN201811037094 A CN 201811037094A CN 110879776 A CN110879776 A CN 110879776A
Authority
CN
China
Prior art keywords
test case
generation
case set
tested code
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201811037094.4A
Other languages
Chinese (zh)
Inventor
魏乔
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201811037094.4A priority Critical patent/CN110879776A/en
Publication of CN110879776A publication Critical patent/CN110879776A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Abstract

The invention discloses a method and a device for generating a test case, and relates to the technical field of computers. One embodiment of the method comprises: obtaining a test case set generation model based on binary relation expression of the tested code parameters, wherein the binary relation expression indicates whether discrete value pairs formed by discrete values of any two tested code parameters need to be included in a test case; and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set. The implementation method can be used for modeling the whole test case set, avoids the situation of local optimization during model solving, can obtain an accurate global optimal test case set, and is low in calculation complexity.

Description

Test case generation method and device
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for generating a test case.
Background
Most of the current test cases (referring to test input data) are manually written by testers, the time spent on designing the test cases accounts for about 40% of the whole test life cycle according to statistics, and the time spent on designing the test cases is more obvious along with the deep popularization of automatic tests. Therefore, in order to improve the automation degree of the test, shorten the test life cycle and improve the working efficiency of the tester, and meanwhile, in order to ensure the effectiveness of the test, the automatic generation of the high-quality and high-efficiency test case is very important.
The automatic test case generation schemes, such as the generation of test case sets by using a particle swarm algorithm, a greedy algorithm, a genetic algorithm, an ant colony algorithm, and the like, all have certain disadvantages. For example, the particle swarm algorithm is easy to fall into local optimization in the process of solving the test case set, and the current particle swarm algorithm is mainly applied to solving a single case, so that the overall control of the test case set is omitted; the greedy algorithm mainly uses a greedy strategy to find a feasible solution of the test case, and although the efficiency is higher, the optimal solution cannot be found; the genetic algorithm needs to encode and decode the problem, is complex in calculation and is easy to fall into early (namely, the algorithm falls into local optimum too early and is difficult to jump out of the local optimum to the global optimum).
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the existing scheme neglects the overall control of the test case set, is easy to fall into local optimum, cannot obtain an accurate optimum solution, and has high calculation complexity.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for generating a test case, which can perform modeling on an entire test case set, avoid trapping in local optimization during model solution, obtain an accurate globally optimal test case set, and have low computational complexity.
To achieve the above object, according to an aspect of the embodiments of the present invention, a method for generating a test case is provided.
A method for generating a test case comprises the following steps: obtaining a test case set generation model based on binary relation expression of the tested code parameters, wherein the binary relation expression indicates whether discrete value pairs formed by discrete values of any two tested code parameters need to be included in a test case; and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set.
Optionally, before the step of obtaining the test case set generation model based on the binary relation representation of the tested code parameters, the method includes: and judging whether the key features of the tested code are consistent with the key features of the code in the test requirement document through static analysis of the tested code, and reading the discrete value of the parameter of the tested code when the comparison is consistent.
Optionally, the step of reading the discrete value of the measured code parameter includes: and generating discrete values of the tested code parameters according to the value rules of the tested code parameters and the key characteristics of the tested code.
Optionally, the step of determining an optimal solution of the test case set generation model by using an intelligent optimization algorithm includes: determining the optimal solution of the test case set generation model by a simulated annealing particle swarm algorithm, wherein the optimal solution comprises the following steps: the velocity update of the i +1 th generation particles is achieved based on: the method comprises the following steps of (1) substituting values of an individual fitness value, an ith generation particle speed, a self-cognition learning factor, a social cognition learning factor, a random number subjected to uniform distribution, an ith generation particle position and a global optimal value of an ith generation particle; the position update of the i +1 th generation particle is realized based on the following items: the (i + 1) th generation particle velocity and the (i) th generation particle position; wherein one test case represents one particle.
Optionally, after the step of determining an optimal solution of the test case set generation model by using an intelligent optimization algorithm to obtain the first test case set, the method includes: testing the tested code by using the first test case set to obtain the coverage of the returned code; and when the coverage of the return codes is smaller than a preset threshold value, carrying out test case compensation on the first test case set according to a compensation rule to obtain a second test case set.
According to another aspect of the embodiments of the present invention, an apparatus for generating a test case is provided.
A test case generation device comprises: the model construction module is used for obtaining a test case set generation model based on binary relation representation of the tested code parameters, wherein the binary relation representation indicates whether discrete values formed by discrete values of any two tested code parameters need to be included in a test case or not; and the case generating module is used for determining the optimal solution of the test case set generating model through an intelligent optimization algorithm so as to obtain a first test case set.
Optionally, the system further comprises a static analysis module, configured to: and judging whether the key features of the tested code are consistent with the code key features in the test requirement document or not by statically analyzing the tested code.
Optionally, the system further comprises a data generating module, configured to: and generating discrete values of the tested code parameters according to the value rules of the tested code parameters and the key characteristics of the tested code.
Optionally, the use case generation module is further configured to: determining the optimal solution of the test case set generation model by a simulated annealing particle swarm algorithm, wherein the optimal solution comprises the following steps: the velocity update of the i +1 th generation particles is achieved based on: the method comprises the following steps of (1) substituting values of an individual fitness value, an ith generation particle speed, a self-cognition learning factor, a social cognition learning factor, a random number subjected to uniform distribution, an ith generation particle position and a global optimal value of an ith generation particle; the position update of the i +1 th generation particle is realized based on the following items: the (i + 1) th generation particle velocity and the (i) th generation particle position; wherein one test case represents one particle.
Optionally, the system further includes a use case compensation module, configured to: testing the tested code by using the first test case set to obtain the coverage of the returned code; and when the coverage of the return codes is smaller than a preset threshold value, carrying out test case compensation on the first test case set according to a compensation rule to obtain a second test case set.
According to yet another aspect of an embodiment of the present invention, an electronic device is provided.
An electronic device, comprising: one or more processors; the memory is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the test case generation method provided by the invention.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer-readable medium, on which a computer program is stored, which, when executed by a processor, implements the test case generation method provided by the present invention.
One embodiment of the above invention has the following advantages or benefits: obtaining a test case set generation model based on binary relation expression of the tested code parameters, wherein the binary relation expression indicates whether discrete value pairs formed by discrete values of any two tested code parameters need to be included in a test case; and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set. The modeling can be performed on the whole test case set, the model is prevented from falling into local optimization during solving, more accurate inertial weight can be obtained, an accurate global optimal test case set is obtained, and the calculation complexity is low.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of main steps of a test case generation method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a solution flow of a test case suite generation model according to an embodiment of the invention;
FIG. 3 is a schematic diagram of main modules of a test case generation apparatus according to an embodiment of the present invention;
FIG. 4 is a block diagram of an overall framework of an automatic test case generation system according to one embodiment of the invention;
FIG. 5 is a schematic diagram of an interface automation architecture according to one embodiment of the invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 7 is a schematic block diagram of a computer system suitable for use with a server implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of main steps of a test case generation method according to an embodiment of the present invention.
As shown in fig. 1, the method for generating a test case according to the embodiment of the present invention mainly includes the following steps S101 to S102.
Step S101: and obtaining a test case set generation model based on the binary relation expression of the tested code parameters.
The code parameter under test (also referred to as a reference) includes M dimensions (M ≧ 1, where the dimension values for different code parameters under test may differ), among N (N ≧ 1) code parameters under test (reference)
Figure BDA0001791150900000061
In (c), Φ represents a set of entries,
Figure BDA0001791150900000062
and expressing all discrete value sets obtained by the ith entry according to equivalent class division, boundary values, special values and other modes. By thetaiRepresents the ith (i is more than or equal to 1 and less than or equal to N) code parameter to be tested
Figure BDA0001791150900000063
Number of discrete values of (a). The binary relation expression of the tested code parameters indicates whether a discrete value pair formed by the discrete values of any two tested code parameters needs to be included in a test case or notThe body can be denoted as rlkWherein r islk0 means that the discrete value pair formed by the ith discrete value of the ith parameter and the kth discrete value of the jth parameter does not need to be covered (i.e., does not need to be included in a test case); r islk1 denotes that the discrete value pair formed by the ith discrete value of the ith parameter and the kth discrete value of the jth parameter needs to be covered (i.e. needs to be included in a test case), and 1 ≦ l ≦ θi,1≤k≤θj
The test case set generation model is obtained as follows:
Figure BDA0001791150900000064
wherein R represents a binary relation of any two parameters, thetaiAnd thetajRespectively represents the number of discrete values of the ith (i is more than or equal to 1 and less than or equal to N) parameter and the jth (j is more than or equal to 1 and less than or equal to N) parameter, Ri(i=1,2,…θi) Namely a test case.
The embodiment of the invention converts the automatic generation problem of the software test case into the combination optimization problem, and aims to find the minimum test case set capable of covering the requirement to the maximum extent. In software testing, defects are usually caused by one parameter or a combination of two parameters, and the defects caused by the combination of three parameters are fewer. Therefore, the problem of solving the minimum test case set with N M-dimensional (each parameter entry may have different dimensions) entries can be summarized as solving the pairing set coverage problem, and it is necessary to ensure that each parameter pair appears in the test case at least once.
The objective function of the minimum test case set in the test case set generation model is as follows:
Figure BDA0001791150900000065
limited by:
Figure BDA0001791150900000071
and (4) solving an optimal solution (the minimum test case set which covers the requirement to the maximum extent) for the model, namely the first test case set.
Based on the binary relation expression of the tested code parameters, before the test case set generation model is obtained, whether the key features of the tested code are consistent with the key features of the code in the test requirement document or not can be judged through static analysis on the tested code, and the discrete values of the tested code parameters are read when the key features of the tested code are consistent with the key features of the code in the test requirement document. The code key features in the test requirement document are key features of the tested code acquired by scanning the test requirement document. The key features of the code to be tested can comprise the key features of the method function of the code to be tested, such as input and output parameters, parameter constraints and the like.
Taking the interface test as an example, the specific process of the static analysis may include: scanning an interface requirement document to obtain information of Maven (a project management tool) dependence, Jsf (JavaServer Faces, a standard framework for constructing JavaWeb application) configuration, method entry and exit parameters, parameter constraint and the like of an interface to be tested of a program; and performing static scanning and analysis on the tested code source program related to the operation, and acquiring the key characteristics of the interface of the function to be tested, such as the input parameter, the output parameter, the parameter constraint and the like, while ensuring the quality of the static code. Through the comparison of interface requirement documents and code scanning results, whether the tested codes have parameter verification omission or not can be preliminarily checked, and requirement change or function omission during development can be prevented. When the two are compared and consistent, the method can provide a reference for the generation of the test case. Generally, the writing format of the interface requirement document and the setting of parameters in the program require setting of unified rules with relevant responsible personnel, for example, notes or other methods capable of being uniformly resolved can be used.
The discrete value of the measured code parameter can be generated according to the value rule of the measured code parameter and the key characteristics of the measured code.
Taking the interface test as an example, the basic data types of the code parameters to be tested (entry parameters, entry parameters of the interface to be tested in the interface test) generally include a numerical type, a character string type, an array or a linked list, and the use cases of the basic data types are designed with certain rules to be searchable, for example, the use cases of each entry parameter are obtained by using methods such as equivalence class division, a boundary value method, a special value method and the like. Therefore, the value-taking rule of the common basic data type is made into a data set, and on the basis, the discrete values of the input parameters are generated by analyzing the parameter types and the constraint conditions of the parameters of the target interface.
Step S102: and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set.
The embodiment of the invention can determine the optimal solution of the test case set generation model by simulating the annealing particle swarm algorithm, the embodiment of the invention obtains the optimization algorithm by utilizing the simulated annealing factor on the basis of the particle swarm algorithm, so that the local optimization can be probabilistically skipped, and the optimization algorithm comprises the following steps:
the velocity update of the i +1 th generation particles is achieved based on: the method comprises the following steps of (1) substituting values of an individual fitness value, an ith generation particle speed, a self-cognition learning factor, a social cognition learning factor, a random number subjected to uniform distribution, an ith generation particle position and a global optimal value of an ith generation particle;
and the position update of the i +1 th generation particle is realized based on the following items: the (i + 1) th generation particle velocity and the (i) th generation particle position. Wherein one test case represents one particle.
Specifically, the updating of the particle velocity and position can be achieved by:
vi+1=ω·(vi+c1·r1·(pi-xi)+c2·r2·(p'g-xi))
xi+1=xi+vi+1
wherein the content of the first and second substances,
Figure BDA0001791150900000081
is a velocity compression factor, vi+1And xi+1Respectively the velocity and position of the (i + 1) th generation particle, c1Is a self-cognitive learning factor, c2Social cognitive learning factor, r1、r2To be random numbers, p 'obeying a uniform distribution'gIs a substitute value for the global optimum value.
According to the optimization of the embodiment of the invention, more accurate inertial weight can be obtained, so that an accurate optimal solution is obtained, and the accuracy of code testing is further improved.
The solving process of the test case set generation model is specifically shown in fig. 2. Firstly, parameter initialization is carried out, including determining the population size E and the maximum iteration number CiterTemperature shrinkage factor β (i.e., the step size of temperature decay), the objective function of the smallest test case set in the test case set generation model is:
Figure BDA0001791150900000091
limited by:
Figure BDA0001791150900000092
randomly initializing location x of a populationiAnd velocity vi(i=1,2,…Citer) And initial temperature ti
Then solving the test case set generation model, and recording the individual fitness value as piAnd finally, the global optimal value obtained through selection is recorded as pgEach particle is learned according to the historical experience of the particle, and the objective function value is calculated to obtain an individual fitness value piCalculating the optimal objective function value obtained from all the particles to obtain a global optimal value pgThen, the individual adaptation value is calculated by the following formula:
Figure BDA0001791150900000093
determining a velocity compression factor ω:
Figure BDA0001791150900000094
c1and c2Is a learning factor, wherein c1Is a self-cognitive learning factor, c2Social recognitionLearning factors are known; m is the number of particles participating in calculation, namely the size of the population; omega is the inertial weight and usually takes on a value in the range of [0,1 ]]The larger ω is, the stronger the global search capability of the algorithm.
Generating a random number sigma and searching with sum (Tmit) as a sub-target function, wherein sigma < sum (Tmit (j)) is used as a judgment condition for ending the search, when sigma is larger than or equal to sum (Tmit (j)), j is j +1, the search is continued, and when sigma < sum (Tmit (j)), the current optimal position, namely the optimal value, which meets the condition is obtained and is used as pgAlternative value of p'g:p'g=xiThus, an iterative update of population position and velocity is performed:
vi+1=ω·(vi+c1·r1·(pi-xi)+c2·r2·(p'g-xi))
xi+1=xi+vi+1
wherein v isi+1And xi+1Respectively the velocity and position of the (i + 1) th generation particle, c1Is a self-cognitive learning factor, c2Social cognitive learning factor, r1、r2To be random numbers, p 'obeying a uniform distribution'gAnd finally obtaining the optimal solution which is a first test case set for the substitute value of the global optimal value.
And determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set, and then testing the tested code by using the first test case set to obtain the coverage of the returned code. The return code coverage refers to whether the return result completely covers all return types after the test case is executed. The return code in the interface test refers to an output value of the calling interface. And when the coverage of the return codes is smaller than a preset threshold value, carrying out test case compensation on the first test case set according to a compensation rule to obtain a second test case set. To ensure the accuracy of the test, the preset threshold is usually set to 100%.
The test case compensation is mainly performed because the test cases obtained through the test case set generation model lose a defect case (i.e., a test case corresponding to a defect caused by a combination of three or more parameters) caused by a small-probability multi-parameter combination, so that the test case compensation can be performed when the return codes do not cover fully (the return codes do not cover the return code values which should be covered fully), so as to ensure the accuracy of the test. In addition, when the boundary value is lost or is in the state of testing the interface robustness, the user can add a specific compensation test case. The test case compensation can be automatically executed or can be manually executed by a tester according to experience.
Under the ideal condition, the compensation rule can perform static analysis on the tested code so as to automatically generate a compensated test case, but the compensation test case can also be manually added by a user in consideration of cost and efficiency problems and small probability of case loss.
The embodiment of the invention is based on the binary relation expression of the tested code parameters, aims at the modeling of the whole test case set, ensures that the assignment of one particle is one test case instead of a certain parameter in one test case when the optimization solution is carried out, thereby ensuring that the result of the test case set is more accurate.
Fig. 3 is a schematic block diagram of a device for generating test cases according to an embodiment of the present invention.
As shown in fig. 3, a test case generation apparatus 300 according to an embodiment of the present invention mainly includes: a model building module 301 and a use case generating module 302.
The model building module 301 is configured to obtain a test case set generation model based on a binary relation representation of the tested code parameters, where the binary relation representation indicates whether a discrete value pair formed by discrete values of any two tested code parameters needs to be included in a test case.
The case generating module 302 is configured to determine an optimal solution of the test case set generating model through an intelligent optimization algorithm to obtain a first test case set.
The device 300 for generating a test case may further include a configuration module, which includes configuring basic parameters for running a test, for example, obtaining a basic configuration of a source program of an interface to be tested, loading related documents and codes into a system, and providing a data source for the static analysis module; setting parameters of the heuristic optimization algorithm, including population size, initialization of maximum iteration number, and annealing factor (simulated annealing factor, i.e. temperature factor t introduced above)i) The setting of (c), etc.
The device 300 for generating a test case may further include a data generating module, configured to: and generating discrete values of the measured code parameters according to the value rules of the measured code parameters and the key characteristics of the measured code. Taking interface test as an example, the value-taking rules of basic data types commonly used by the tested code parameters can be made into a data set, and on the basis, the discrete values of the tested code parameters are generated by analyzing the parameter types and the constraint conditions of the parameters of the target interface. In addition, the embodiment of the invention directly establishes the use case table according to the key factors (namely the tested code parameters) of the test case, and stores each generated optimal test case set (namely the first test case set), so that the content in the MySQL (relational database management system) database is directly read by annotating the @ dataProvider during the execution of the automatic test, and the conversion of the csv or excel format is not performed any more.
The test case generation apparatus 300 may further include a data reading module, configured to read discrete values of the code parameter under test.
The apparatus 300 for generating a test case may further include a static analysis module configured to: and judging whether the key features of the tested code are consistent with the code key features in the test requirement document or not by statically analyzing the tested code. When the comparison is consistent, the data reading module reads the discrete values of the tested code parameters for the model building module 301 and the use case generating module 302 to use.
The use case generation module 302 may be specifically configured to: determining the optimal solution of a test case set generation model by a simulated annealing particle swarm algorithm, wherein the optimal solution comprises the following steps:
the velocity update of the i +1 th generation particles is achieved based on: the method comprises the following steps of (1) substituting values of an individual fitness value, an ith generation particle speed, a self-cognition learning factor, a social cognition learning factor, a random number subjected to uniform distribution, an ith generation particle position and a global optimal value of an ith generation particle; the position update of the i +1 th generation particle is realized based on the following items: the (i + 1) th generation particle velocity and the (i) th generation particle position; wherein one test case represents one particle.
Specifically, the updating of the particle velocity and position can be achieved by:
vi+1=ω·(vi+c1·r1·(pi-xi)+c2·r2·(p'g-xi))
xi+1=xi+vi+1
wherein the content of the first and second substances,
Figure BDA0001791150900000121
is a velocity compression factor, vi+1And xi+1Respectively the velocity and position of the (i + 1) th generation particle, c1Is a self-cognitive learning factor, c2Social cognitive learning factor, r1、r2To be random numbers, p 'obeying a uniform distribution'gIs a substitute value for the global optimum value.
The test case generation apparatus 300 may further include a case compensation module configured to: testing the tested code by utilizing the first test case set to obtain the coverage of the returned code; and when the coverage of the return codes is smaller than a preset threshold value, carrying out test case compensation on the first test case set according to a compensation rule to obtain a second test case set.
Taking the interface test as an example, the device 300 for generating test cases may be embodied as an automatic test case generation system as shown in fig. 4.
The integral framework of the test case automatic generation system comprises: a basic configuration module (corresponding to the configuration module of the device 300), a static analysis module (corresponding to the static analysis module of the device 300), a data collection and generation module (corresponding to the data generation module of the device 300), a test case generation module, an algorithm implementation module, an interface program dynamic execution module, and a compensation module.
The test case generation module is used for realizing the corresponding functions of the model construction module 301 of the test case generation device 300, and is combined with the data reading module and the algorithm realization module to realize the corresponding functions of the case generation module 302. Specifically, after the test case set generation module constructs the test case set generation model, the drive algorithm implementation module solves the constructed test case set generation model to obtain a first test case set, wherein the discrete value of the required input parameter of the interface to be tested is read from the data set and the generation module by the data reading module.
The above-mentioned interface program dynamic execution module is combined with the compensation module to realize the corresponding functions of the case compensation module of the test case generation apparatus 300. Specifically, the interface program dynamic execution module may design an interface code template according to the unified interface characteristics, bring the obtained interface Maven dependencies, Jsf configurations, method parameters, and the like into the template, and generate a test script (i.e., an interface test script) used for the operation; and when the coverage of the return code is less than a preset threshold value, the compensation module is introduced, so that the compensation module performs test case compensation on the first test case set according to a compensation rule to obtain a second test case set. In addition, when the boundary value is lost or is in a condition of testing the interface robustness and the like, the user can add a specific compensation test case.
Based on the above descriptions of the modules, the overall structure of the interface automation of the present embodiment is shown in fig. 5. In the embodiment of the invention, the csv or excel format file is not used any more by introducing the case, and the MySQL database is directly read, so that the operation can be simplified, and the errors of file analysis or conversion can be avoided.
Software tests can be classified into static tests and dynamic tests according to whether programs are executed or not, and can be classified into white box tests and black box tests according to whether code structures are deeply studied or not, and gray box tests are arranged between the white box tests and the black box tests. The automatic test case generation system provided by the embodiment of the invention is mainly designed by combining the static test method, the dynamic test method and the gray box test method. The embodiment of the invention is not only suitable for interface test, but also can be used for unit test and integrated test.
The detailed implementation of the test case generation apparatus in the embodiment of the present invention has been described in detail in the above test case generation method, and therefore, the repeated content is not described here.
Fig. 6 shows an exemplary system architecture 600 of a test case generation method or a test case generation apparatus to which an embodiment of the present invention can be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a server 605. The network 604 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. The terminal devices 601, 602, 603 may have installed thereon various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 601, 602, 603. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for generating a test case according to the embodiment of the present invention is generally executed by the server 605, and accordingly, the device for generating a test case is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use in implementing a server according to embodiments of the present application. The server shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program executes the above-described functions defined in the system of the present application when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor comprises a model building module and a use case generating module. The names of the modules do not form a limitation on the modules themselves under certain conditions, for example, the model building module can also be described as a "module for generating a model based on a binary relation representation of tested code parameters to obtain a test case set.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: obtaining a test case set generation model based on binary relation expression of the tested code parameters, wherein the binary relation expression indicates whether discrete value pairs formed by discrete values of any two tested code parameters need to be included in a test case; and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set.
According to the technical scheme of the embodiment of the invention, a test case set generation model is obtained based on the binary relation expression of the tested code parameters, wherein the binary relation expression indicates whether discrete value pairs formed by the discrete values of any two tested code parameters need to be included in a test case; and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set. The modeling can be performed on the whole test case set, the model is prevented from falling into local optimization during solving, more accurate inertial weight can be obtained, an accurate global optimal test case set is obtained, and the calculation complexity is low.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (12)

1. A method for generating a test case is characterized by comprising the following steps:
obtaining a test case set generation model based on binary relation expression of the tested code parameters, wherein the binary relation expression indicates whether discrete value pairs formed by discrete values of any two tested code parameters need to be included in a test case;
and determining the optimal solution of the test case set generation model through an intelligent optimization algorithm to obtain a first test case set.
2. The method of claim 1, wherein the step of obtaining the test case suite generation model based on the binary relation representation of the tested code parameters is preceded by:
and judging whether the key features of the tested code are consistent with the key features of the code in the test requirement document through static analysis of the tested code, and reading the discrete value of the parameter of the tested code when the comparison is consistent.
3. The method of claim 2, wherein the step of reading the discrete values of the code parameter under test is preceded by the step of:
and generating discrete values of the tested code parameters according to the value rules of the tested code parameters and the key characteristics of the tested code.
4. The method of claim 1, wherein the step of determining an optimal solution for the test case suite generation model via an intelligent optimization algorithm comprises:
determining the optimal solution of the test case set generation model by a simulated annealing particle swarm algorithm, wherein the optimal solution comprises the following steps:
the velocity update of the i +1 th generation particles is achieved based on: the method comprises the following steps of (1) substituting values of an individual fitness value, an ith generation particle speed, a self-cognition learning factor, a social cognition learning factor, a random number subjected to uniform distribution, an ith generation particle position and a global optimal value of an ith generation particle;
the position update of the i +1 th generation particle is realized based on the following items: the (i + 1) th generation particle velocity and the (i) th generation particle position;
wherein one test case represents one particle.
5. The method of claim 1, wherein the step of determining an optimal solution for the test case suite generation model by an intelligent optimization algorithm to obtain the first test case suite comprises:
testing the tested code by using the first test case set to obtain the coverage of the returned code;
and when the coverage of the return codes is smaller than a preset threshold value, carrying out test case compensation on the first test case set according to a compensation rule to obtain a second test case set.
6. An apparatus for generating a test case, comprising:
the model construction module is used for obtaining a test case set generation model based on binary relation representation of the tested code parameters, wherein the binary relation representation indicates whether discrete values formed by discrete values of any two tested code parameters need to be included in a test case or not;
and the case generating module is used for determining the optimal solution of the test case set generating model through an intelligent optimization algorithm so as to obtain a first test case set.
7. The apparatus of claim 6, further comprising a static analysis module to:
and judging whether the key features of the tested code are consistent with the code key features in the test requirement document or not by statically analyzing the tested code.
8. The apparatus of claim 7, further comprising a data generation module to:
and generating discrete values of the tested code parameters according to the value rules of the tested code parameters and the key characteristics of the tested code.
9. The apparatus of claim 6, wherein the use case generation module is further configured to:
determining the optimal solution of the test case set generation model by a simulated annealing particle swarm algorithm, wherein the optimal solution comprises the following steps:
the velocity update of the i +1 th generation particles is achieved based on: the method comprises the following steps of (1) substituting values of an individual fitness value, an ith generation particle speed, a self-cognition learning factor, a social cognition learning factor, a random number subjected to uniform distribution, an ith generation particle position and a global optimal value of an ith generation particle;
the position update of the i +1 th generation particle is realized based on the following items: the (i + 1) th generation particle velocity and the (i) th generation particle position;
wherein one test case represents one particle.
10. The apparatus of claim 6, further comprising a use case compensation module configured to:
testing the tested code by using the first test case set to obtain the coverage of the returned code;
and when the coverage of the return codes is smaller than a preset threshold value, carrying out test case compensation on the first test case set according to a compensation rule to obtain a second test case set.
11. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method recited in any of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201811037094.4A 2018-09-06 2018-09-06 Test case generation method and device Pending CN110879776A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811037094.4A CN110879776A (en) 2018-09-06 2018-09-06 Test case generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811037094.4A CN110879776A (en) 2018-09-06 2018-09-06 Test case generation method and device

Publications (1)

Publication Number Publication Date
CN110879776A true CN110879776A (en) 2020-03-13

Family

ID=69727383

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811037094.4A Pending CN110879776A (en) 2018-09-06 2018-09-06 Test case generation method and device

Country Status (1)

Country Link
CN (1) CN110879776A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111367780A (en) * 2020-03-30 2020-07-03 西安芯瞳半导体技术有限公司 Performance test method and device of GPU (graphics processing Unit) and computer storage medium
CN111597118A (en) * 2020-05-26 2020-08-28 上海复深蓝软件股份有限公司 Test case generation method and device, computer equipment and storage medium
CN112445702A (en) * 2020-11-09 2021-03-05 北京思特奇信息技术股份有限公司 Automatic testing method and system based on ant colony algorithm
CN113535565A (en) * 2021-07-19 2021-10-22 工银科技有限公司 Interface use case generation method, device, equipment, medium and program product
CN114968828A (en) * 2022-08-02 2022-08-30 树优(宁波)科技有限公司 Performance test method, platform, equipment and storage medium for optimization algorithm

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111367780A (en) * 2020-03-30 2020-07-03 西安芯瞳半导体技术有限公司 Performance test method and device of GPU (graphics processing Unit) and computer storage medium
CN111367780B (en) * 2020-03-30 2024-02-09 芯瞳半导体技术(山东)有限公司 GPU performance test method and device and computer storage medium
CN111597118A (en) * 2020-05-26 2020-08-28 上海复深蓝软件股份有限公司 Test case generation method and device, computer equipment and storage medium
CN112445702A (en) * 2020-11-09 2021-03-05 北京思特奇信息技术股份有限公司 Automatic testing method and system based on ant colony algorithm
CN113535565A (en) * 2021-07-19 2021-10-22 工银科技有限公司 Interface use case generation method, device, equipment, medium and program product
CN113535565B (en) * 2021-07-19 2022-10-04 工银科技有限公司 Interface use case generation method, device, equipment and medium
CN114968828A (en) * 2022-08-02 2022-08-30 树优(宁波)科技有限公司 Performance test method, platform, equipment and storage medium for optimization algorithm

Similar Documents

Publication Publication Date Title
CN110879776A (en) Test case generation method and device
CN110852421B (en) Model generation method and device
CN110263938B (en) Method and apparatus for generating information
CN109447156B (en) Method and apparatus for generating a model
CN113536081B (en) Data center data management method and system based on artificial intelligence
CN111340220B (en) Method and apparatus for training predictive models
US20170308620A1 (en) Making graph pattern queries bounded in big graphs
CN110381101B (en) API gateway control system, control method, equipment and medium
CN110363427A (en) Model quality evaluation method and apparatus
CN109976999B (en) Method and device for measuring coverage rate of test cases
CN111353601A (en) Method and apparatus for predicting delay of model structure
CN111368973A (en) Method and apparatus for training a hyper-network
CN110309142B (en) Method and device for rule management
CN113238740A (en) Code generation method, code generation device, storage medium, and electronic apparatus
CN113448821B (en) Method and device for identifying engineering defects
CN111026629A (en) Method and device for automatically generating test script
CN116204428A (en) Test case generation method and device
US9519864B1 (en) Method and system for identifying dependent components
CN110471708B (en) Method and device for acquiring configuration items based on reusable components
CN113052509A (en) Model evaluation method, model evaluation apparatus, electronic device, and storage medium
CN113743425A (en) Method and device for generating classification model
CN112231299A (en) Method and device for dynamically adjusting feature library
CN111353585A (en) Structure searching method and device of neural network model
CN111582482B (en) Method, apparatus, device and medium for generating network model information
CN113468053B (en) Application system testing method and device

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