CN112597055A - Test case generation method, device, equipment and computer readable storage medium - Google Patents

Test case generation method, device, equipment and computer readable storage medium Download PDF

Info

Publication number
CN112597055A
CN112597055A CN202011643974.3A CN202011643974A CN112597055A CN 112597055 A CN112597055 A CN 112597055A CN 202011643974 A CN202011643974 A CN 202011643974A CN 112597055 A CN112597055 A CN 112597055A
Authority
CN
China
Prior art keywords
test case
generation
population
resource allocation
test
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
CN202011643974.3A
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.)
Shenzhen TCL New Technology Co Ltd
Original Assignee
Shenzhen TCL New 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 Shenzhen TCL New Technology Co Ltd filed Critical Shenzhen TCL New Technology Co Ltd
Priority to CN202011643974.3A priority Critical patent/CN112597055A/en
Publication of CN112597055A publication Critical patent/CN112597055A/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
    • 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/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/004Artificial life, i.e. computing arrangements simulating life
    • G06N3/006Artificial life, i.e. computing arrangements simulating life based on simulated virtual individual or collective life forms, e.g. social simulations or particle swarm optimisation [PSO]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Biomedical Technology (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • Health & Medical Sciences (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a test case generation method, which comprises the following steps: acquiring a source program of a test object; generating an initial test case based on a source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases; determining a final test case population based on the 1 st generation test case population and a genetic algorithm; therefore, the generation time of the test case is shortened, the generation efficiency of the test case is improved, the time consumption of software test is reduced, unexpected test cases can be generated based on the genetic algorithm, the problems of test missing caused by difficulty in newly adding the test cases, unclear development direction and incomplete design of the test cases are effectively solved, and the software quality is guaranteed. The invention also discloses a test case generation device, equipment and a computer readable storage medium, which improve the user experience.

Description

Test case generation method, device, equipment and computer readable storage medium
Technical Field
The present invention relates to the field of software testing, and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for generating a test case.
Background
In recent years, with the rapid development of software technology and the rapid iteration of software, the stability and reliability of software quality become more important, and software testing is taken as a key link for guaranteeing the software quality, so as to find out defects in the software as much as possible in a short time by consuming as little manpower and material resources as possible, so as to repair the software.
In the related art, software is generally tested based on test cases. However, the generation process of the test case is long, the generation efficiency is low, and the software testing process is long.
Disclosure of Invention
The invention mainly aims to provide a test case generation method, a test case generation device, test case generation equipment and a computer readable storage medium, and aims to solve the problems that the time consumption of the existing test case generation process is long, the generation efficiency is low, and the time consumption of the software test process is long.
In order to achieve the above object, the present invention provides a test case generation method, which includes the following steps:
acquiring a source program of a test object;
generating an initial test case based on the source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases;
and determining a final test case population based on the 1 st generation test case population and a genetic algorithm.
Optionally, the step of generating an initial test case based on the source program to obtain a 1 st generation test case population includes:
performing lexical analysis and characteristic value extraction on the source program to obtain a frame of the source program;
and generating an initial test case based on the frame and a preset test case generating function to obtain a 1 st generation test case population.
Optionally, the step of determining a final test case population based on the 1 st generation test case population and the genetic algorithm includes:
determining a target resource allocation scheme based on server resources and an a-th generation test case population, wherein an initial value of a is 1, a is a positive integer, and the server resources comprise at least one server node;
distributing each a-th generation test case in the a-th generation test case population to each server node in the server resources based on the target resource distribution scheme so that each server node processes the distributed a-th generation test case to obtain the fitness of each a-th generation test case;
selecting, crossing and mutating the a-th generation test case in the a-th generation test case population based on the fitness of each a-th generation initial test case to obtain an a + 1-th generation test case population;
and setting a +1, returning to the step based on the server resource and the a-th generation test case population, and determining a target resource allocation scheme to iterate until a preset first iteration stopping condition is met to obtain a final test case population.
Optionally, the step of determining a target resource allocation scheme based on the server resource and the a-th generation test case population includes:
and determining a target resource allocation scheme according to server resources and the a-generation test case population based on an ant colony algorithm taking task completion time as an index, wherein the task completion time is the maximum value of time required by each server node to process the allocated a-generation test case.
Optionally, the step of determining the target resource allocation scheme according to the server resource and the a-th generation test case population based on the ant colony algorithm using the task completion time as the index includes:
respectively determining the processing time of each server node aiming at each a-th generation test case to obtain a processing time matrix;
initializing a pheromone matrix;
and performing iterative search based on the processing time matrix and the pheromone matrix until a preset second iteration stopping condition is met to obtain a target resource allocation scheme.
Optionally, the step of performing iterative search based on the processing time matrix and the pheromone matrix until a preset iteration stop condition is met to obtain a target resource allocation scheme includes:
determining k sets of resource allocation schemes based on a task allocation function, wherein k is a positive integer;
determining task completion time of each resource allocation scheme based on the processing time matrix;
determining a local optimal resource allocation scheme based on task completion time of each resource allocation scheme; updating the pheromone matrix based on the local optimal resource allocation scheme;
and returning to the step of determining k sets of resource allocation schemes based on the task allocation function to perform iteration until a preset second iteration stopping condition is met, so as to obtain a target resource allocation scheme.
Optionally, the step of determining k sets of resource allocation schemes based on the task allocation function includes:
determining m sets of resource allocation schemes based on the pheromone matrix, wherein m is an integer greater than or equal to 1;
determining n sets of resource allocation schemes based on a random allocation strategy, wherein n is an integer greater than or equal to 1, and k is m + n.
Optionally, the preset ant colony iteration stop condition includes: the iteration times reach an ant colony iteration time threshold value, or a global optimal resource allocation scheme is obtained; the ant colony iteration number threshold is determined by the number of the server nodes and the number of the a-th generation test cases.
In order to achieve the above object, the present invention further provides a test case generation device, including:
the acquisition module acquires a source program of a test object;
the generation module is used for generating an initial test case based on the source program to obtain a 1 st generation test case population, and the 1 st generation test case population comprises a plurality of test cases;
and the determining module is used for determining a final test case population based on the 1 st generation test case population and the genetic algorithm.
In addition, in order to achieve the above object, the present invention further provides a test case generating device, including: the test case generation method comprises a memory, a processor and a test case generation program which is stored on the memory and runs on the processor, wherein when the test case generation program is executed by the processor, the steps of the test case generation method are realized.
In addition, in order to achieve the above object, the present invention further provides a computer-readable storage medium, in which a test case generation program is stored, and the test case generation program implements the steps of the test case generation method according to any one of the above items when being executed by a processor.
The technical scheme of the invention adopts a test case generation method, which comprises the following steps: acquiring a source program of a test object; generating an initial test case based on a source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases; determining a final test case population based on the 1 st generation test case population and a genetic algorithm to obtain a test case; compared with a mode of manually compiling test cases, the method has the advantages that the generation time of the test cases can be shortened, the generation efficiency of the test cases is improved, the time consumption of software testing is reduced, in addition, in the process of determining the final test case population based on the genetic algorithm, the test cases can be crossed and varied, unexpected test cases are generated, the problems of test missing caused by difficulty in newly adding the test cases, unclear development direction and incomplete test case design are effectively solved, and the software quality is guaranteed.
Drawings
FIG. 1 is a schematic structural diagram of a test case generating device in a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a test case generating method according to a first embodiment of the present invention;
FIG. 3 is a flowchart illustrating a test case generating method according to a second embodiment of the present invention;
FIG. 4 is a flowchart illustrating a test case generating method according to a third embodiment of the present invention;
FIG. 5 is a flowchart illustrating a test case generation method according to a fourth embodiment of the present invention
Fig. 6 is a block diagram showing a first example of the test case generating apparatus according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic structural diagram of a test case generating device in a hardware operating environment according to an embodiment of the present invention.
The test case generation device may be a User Equipment (UE) such as a Mobile phone, a smart phone, a laptop, a digital broadcast receiver, a Personal Digital Assistant (PDA), a tablet computer (PAD), a handheld device, a vehicle-mounted device, a wearable device, a computing device, a monitoring device, a server or other processing device connected to a wireless modem, a Mobile Station (MS), or the like.
Generally, a test case generation apparatus includes: at least one processor 101, a memory 102, and a test case generation program stored on the memory and executable on the processor, the test case generation program being configured to implement the steps of the test case generation method according to any of the following embodiments.
Processor 101 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and so forth. The processor 101 may be implemented in at least one hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), and a PLA (Programmable Logic Array). The processor 101 may also include a main processor and a coprocessor, where the main processor is a processor for processing data in an awake state, and is also called a Central Processing Unit (CPU); a coprocessor is a low power processor for processing data in a standby state. In some embodiments, the processor 101 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the display screen. The processor 101 may further include an AI (Artificial Intelligence) processor for processing operations related to the test case generation method, so that the test case generation method model may be trained and learned autonomously, thereby improving efficiency and accuracy.
Memory 102 may include one or more computer-readable storage media, which may be non-transitory. Memory 102 may also include high speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In some embodiments, a non-transitory computer-readable storage medium in the memory 102 is used to store at least one instruction for execution by the processor 101 to implement the test case generation method provided by the method embodiments of the present application.
In some embodiments, the test case generating device may further include: a communication interface 103 and at least one peripheral device. The processor 101, memory 102 and communication interface 103 may be connected by a bus or signal lines. Various peripheral devices may be connected to communication interface 103 via a bus, signal line, or circuit board. Specifically, the peripheral device includes: at least one of radio frequency circuitry 104, display screen 105, and power supply 106.
The communication interface 103 can be used to connect at least one peripheral device related to I/O (Input/Output) to the processor 101 and the memory 102. In some embodiments, the processor 101, memory 102, and communication interface 103 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 101, the memory 102 and the communication interface 103 may be implemented on a single chip or circuit board, which is not limited in this embodiment.
The Radio Frequency circuit 104 is used for receiving and transmitting RF (Radio Frequency) signals, also called electromagnetic signals. The radio frequency circuitry 104 communicates with communication networks and other communication devices via electromagnetic signals. The rf circuit 104 converts an electrical signal into an electromagnetic signal for transmission, or converts a received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 104 comprises: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a subscriber identity module card, and so forth. The radio frequency circuitry 104 may communicate with other terminals via at least one wireless communication protocol. The wireless communication protocols include, but are not limited to: metropolitan area networks, various generations of mobile communication networks (2G, 3G, 4G, and 5G), Wireless local area networks, and/or WIFI (Wireless Fidelity) networks. In some embodiments, the rf circuit 104 may further include NFC (Near Field Communication) related circuits, which are not limited in this application.
The display screen 105 is used to display a UI (User Interface). The UI may include graphics, text, icons, video, and any combination thereof. When the display screen 105 is a touch display screen, the display screen 105 also has the ability to capture touch signals on or over the surface of the display screen 105. The touch signal may be input to the processor 101 as a control signal for processing. At this point, the display screen 105 may also be used to provide virtual buttons and/or a virtual keyboard, also referred to as soft buttons and/or a soft keyboard. In some embodiments, the display screen 105 may be one, the front panel of the electronic device; in other embodiments, the display screens 105 may be at least two, respectively disposed on different surfaces of the electronic device or in a folded design; in still other embodiments, the display 105 may be a flexible display, disposed on a curved surface or on a folded surface of the electronic device. Even further, the display screen 105 may be arranged in a non-rectangular irregular pattern, i.e. a shaped screen. The Display screen 105 may be made of LCD (liquid crystal Display), OLED (Organic Light-Emitting Diode), and the like.
The power supply 106 is used to supply power to various components in the electronic device. The power source 106 may be alternating current, direct current, disposable batteries, or rechargeable batteries. When the power source 106 includes a rechargeable battery, the rechargeable battery may support wired or wireless charging. The rechargeable battery may also be used to support fast charge technology. Those skilled in the art will appreciate that the configuration shown in FIG. 1 does not constitute a limitation of the test case generation apparatus and may include more or fewer components than shown, or some components in combination, or a different arrangement of components.
In addition, an embodiment of the present invention further provides a computer-readable storage medium, where a test case generation program is stored on the computer-readable storage medium, and when the test case generation program is executed by a processor, the steps of the test case generation method according to any of the following embodiments are implemented. Therefore, a detailed description thereof will be omitted. In addition, the beneficial effects of the same method are not described in detail. For technical details not disclosed in embodiments of the computer-readable storage medium referred to in the present application, reference is made to the description of embodiments of the method of the present application. It is determined that, by way of example, the program instructions may be deployed to be executed on one computing device or on multiple computing devices at one site or distributed across multiple sites and interconnected by a communication network.
It will be understood by those skilled in the art that all or part of the processes in the method according to any of the embodiments below may be implemented by a computer program to instruct associated hardware, and the test case generation program may be stored in a computer-readable storage medium, and when executed, may include the processes according to the embodiments of the methods described below. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
In the related art, a tester writes a test case based on a test requirement, that is, manually writes the test case. In the test case generation mode, the time consumption is long, the compiling efficiency is low, the cost is high, and due to the limitation of thinking of testers, the test cases are difficult to increase, the development direction of the test cases is not clear, the design of the test cases is not comprehensive, so that comprehensive tests cannot be carried out, the test omission is caused, and the risk of low software quality is caused.
In order to solve the above technical problems, embodiments of the present invention are proposed based on the above hardware configuration.
The embodiment of the test case generation method comprises the following steps:
referring to fig. 2, fig. 2 is a flowchart illustrating a test case generating method according to a first embodiment of the present invention. In the embodiment of the invention, the test case generation method comprises the following steps:
step S21: and acquiring a source program of the test object.
It should be noted that, in the embodiment of the present invention, the test object includes, but is not limited to, various software codes that need to be tested. For example, the test object may be an interface, a page, etc.
In the embodiment of the invention, when the test case of the test object needs to be generated, the source program of the test object is obtained.
In some embodiments, after the test object is generated or updated, the source program of the test object may be acquired to generate a test case corresponding to the test. For example, if the test object is an interface, the source program of the interface may be acquired when an interface is newly added or changed.
Step S22: and generating an initial test case based on the source program to obtain a 1 st generation test case population.
In the embodiment of the invention, after the source program of the test object is obtained, the initial test case is generated based on the source program of the test object, so as to obtain the 1 st generation test case population. It should be noted that the 1 st generation test case population includes a plurality of test cases. The specific number of the test cases included in the 1 st generation test case population can be flexibly set according to actual needs.
In some embodiments, step S22 includes:
step S221: and performing lexical analysis and characteristic value extraction on the source program to obtain a frame of the source program.
In one example, a source program of a test object may be scanned based on a lexical analyzer, and lexical analysis and feature value extraction may be performed to obtain a framework of the source program of the test object.
For example, assuming that the test object is an interface, based on a lexical analyzer, a source program of the interface set is scanned, and lexical analysis and feature value extraction are performed to obtain a path table.
Step S222: and generating an initial test case based on the frame and a preset test case generating function to obtain a 1 st generation test case population.
After the frame of the test object source program is obtained, an initial test case is generated based on the frame and a preset test case generating function, so that a 1 st generation test case population is obtained.
The preset test case generating function can be flexibly set according to actual needs. In one example, the preset test case generation function may be generated by: and obtaining different types of test cases as a sample set, and training based on machine learning and the sample set to obtain a test case generating function.
In some embodiments, after the initial test case is generated based on the framework and the preset test case generation function, the 1 st generation test case population may be obtained directly based on the initial test case.
In some embodiments, after the initial test case is generated based on the frame and the preset test case generation function, the generated initial test case may be screened according to a preset mode, and the 1 st generation test case population may be obtained based on the screened initial test case. The screening mode can be flexibly set according to actual needs, and in one example, the screening mode can be random screening.
Step S23: and determining a final test case population based on the 1 st generation test case population and a genetic algorithm.
It should be understood that Genetic Algorithm (GA) is an Algorithm that searches for an optimal solution in a natural evolution process by computer simulation. The genetic algorithm is a mathematical calculation model developed by taking natural selection of Darwin biological evolution theory and Mendelian genetic compiling theory as an initial reference, and selects individuals meeting the standard according to strategies (fitness) from a population with a certain scale (consisting of random individuals with characteristics), then generates a new population through operations such as selection, intersection, variation and the like, and is approximately optimal after a plurality of iterations.
In the embodiment of the invention, after the 1 st generation test case population is obtained, the final test case population is obtained through the processes of selection, intersection, variation and the like on the basis of a genetic algorithm aiming at the 1 st generation test case population.
The test case generation method provided by the embodiment of the invention comprises the following steps: acquiring a source program of a test object; generating an initial test case based on a source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases; determining a final test case population based on the 1 st generation test case population and a genetic algorithm; compared with a mode of generating test cases by manual compiling, the method has the advantages that the generation time of the test cases can be shortened, the generation efficiency of the test cases is improved, the time consumption of software testing is reduced, in addition, in the process of obtaining the final test case population based on the genetic algorithm, the test cases can be crossed and varied, unexpected test cases are generated, the problems of test case increasing difficulty, unclear development direction and test case design incompleteness caused by the limitation of thinking of testers are effectively solved, and the software quality is guaranteed.
Based on the first embodiment, a second embodiment of the test case generation method of the present invention is provided. Referring to fig. 3, fig. 3 is a flowchart illustrating a test case generating method according to a second embodiment of the present invention. In this embodiment of the present invention, after step S23, the test case generating method may further include the following steps:
step S24: and converting the test cases in the final test case population to obtain the test cases to be executed.
In the embodiment of the invention, the test case in the final test case population is converted after the final test case population is determined to obtain the test case to be executed, considering that the test case in the final test case population may not directly act on the test object to perform the test.
Step S25: and storing the test case to be executed into a preset database.
After the test case to be executed is obtained, the test case to be executed is stored in a preset database, so that when the test object needs to be tested, the test case to be executed is called to test the test object.
The test case generation method provided by the embodiment of the invention generates an initial test case based on a source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases; determining a final test case population based on the 1 st generation test case population and a genetic algorithm; converting the test cases in the final test case population to obtain test cases to be executed; the test cases to be executed are stored in the preset database, so that when the test objects need to be tested subsequently, the corresponding test cases to be executed can be directly called from the preset database for testing, and the testing efficiency is improved.
Based on the first embodiment, a third embodiment of the test case generation method of the present invention is provided. Referring to fig. 4, fig. 4 is a flowchart illustrating a test case generating method according to a third embodiment of the present invention. In the embodiment of the present invention, step S23 includes:
step S231: and determining a target resource allocation scheme based on the server resources and the a-th generation test case population.
Wherein the server resource comprises at least one server node. a is a positive integer, and the initial value of a is 1.
Because the server nodes need to process the test cases in the a-th generation test case population, and the server nodes are limited, in order to reasonably utilize the server resources, a target resource allocation scheme is determined based on the server resources and the a-th generation test case population, and it should be understood that the target resource distribution scheme includes: each server node in the server resource and a corresponding a-th generation test case, wherein the a-th generation test case is a test case in a-th generation test case population.
Step S232: and distributing each a-th generation test case in the a-th generation test case population to each server node in the server resources based on the target resource distribution scheme so that each server node processes the distributed a-th generation test case to obtain the fitness of each a-th generation test case.
After the target resource allocation scheme is obtained, allocating each a-th generation test case in the a-th generation test case population to each server node in the server resources based on the target allocation scheme, and processing the allocated a-th generation test case by each server node to obtain the fitness of each a-th to-be-tested case.
It should be noted that the genetic algorithm includes a fitness function, and in some embodiments, each server node may process the assigned a-th generation test case based on the fitness function to obtain the fitness of each a-th generation test case. The fitness function can be flexibly set according to actual needs. In one example, each server node may process the assigned a-th generation test case to obtain the performability and the coverage rate of each a-th generation test case, so as to determine the fitness of each a-th generation test case according to the coverage rate and the performability. The performability is used for representing whether the test case can be executed or not, and the coverage rate is used for representing the coverage degree of the test case on the functional test of the test object.
Step S233: and selecting, crossing and mutating the a-th generation test case in the a-th generation test case population based on the fitness of each a-th generation initial test case to obtain an a + 1-th generation test case population.
After the fitness of each a-th generation of initial test case is determined, the a-th generation of test cases in the a-th generation of test case population are selected based on the fitness of each a-th generation of initial test case, new test cases are obtained based on the selected a-th generation of test cases through crossing, the a + 1-th generation of test cases are obtained based on the new test cases through variation, and the a + 1-th generation of test case population is obtained.
In some embodiments, the genetic algorithm includes a selection operator, and when the selection is performed on the a-th generation test case in the a-th generation test case population, the a-th generation test case in the a-th generation test case population can be selected based on the selection operator and the fitness of each a-th generation initial test case. The selection operator can be flexibly set according to actual needs. In one example, the selection operator may be: b test cases with higher fitness are selected from the a-th generation test cases, wherein the number of b can be flexibly set according to actual needs. For example, assuming that b is 2, the a-th test case population includes 3 test cases, and the fitness ranks of the test cases are as follows: and if the test case 1 is larger than the test case 2 and the test case 3 is larger than the test case 2, selecting the test case 1 and the test case 2 from the test cases.
In some embodiments, the genetic algorithm includes a crossover operator, and when the selected a-th generation test case is crossed to obtain a new test case, the selected a-th generation test case may be crossed to obtain the new test case based on the crossover algorithm. The intersection strategy corresponding to the intersection operator includes but is not limited to: single point crossing, multiple point crossing, uniform crossing, discrete recombination, etc., it is understood that multiple point crossing refers to randomly setting multiple point crossing in an individual code string, and then performing partial gene block exchange in an interval exchange manner. The specific crossover strategy corresponding to the crossover operator can be flexibly set according to actual needs, and in one example, the crossover operator can be multipoint crossover.
In some embodiments, the genetic algorithm includes a mutation operator, and when mutation is performed based on the new test case to obtain the a +1 th generation test case, the new test case may be mutated based on the mutation algorithm to obtain the a +1 th generation test case. The mutation operator can be flexibly set according to actual needs.
Step S234: and setting a to a +1, and returning to the step S231 to iterate until a preset first iteration stop condition is met to obtain a final test case population.
The preset first iteration stopping condition can be flexibly set according to actual needs. In some embodiment modes, the presetting of the first iteration stop condition may include that the iteration number reaches a preset genetic iteration number threshold, or an optimal solution of a genetic algorithm is obtained (that is, an optimal test case population is obtained). The preset genetic iteration time threshold value can be flexibly set according to actual needs.
And after the a +1 th generation test case population is obtained, setting a to a +1, returning to the step S231 to perform the next iteration until a preset first iteration stopping condition is met, stopping the iteration, and taking the latest obtained test case population as a final test case population. For example, if the iteration is stopped when the iteration number reaches a preset genetic iteration number threshold, taking the test case population obtained in the latest iteration process as the final test case population; and assuming that iteration is stopped when the optimal test case population is obtained, and taking the optimal test case population as a final test case population.
The test case generation method provided by the embodiment of the invention comprises the following steps: acquiring a source program of a test object; generating an initial test case based on a source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases; determining a target resource allocation scheme based on server resources and the a-th generation test case population; distributing each a-th generation test case in the a-th generation test case population to each server node in server resources based on a target resource distribution scheme so that each server node processes the distributed a-th generation test case to obtain the fitness of each a-th generation test case; selecting, crossing and mutating the a-th generation test case in the a-th generation test case population based on the fitness of each a-th generation initial test case to obtain an a + 1-th generation test case population; and setting a +1, returning to the step of determining a target resource allocation scheme based on the server resource and the a-th generation test case population, and iterating until a preset first iteration stopping condition is met to obtain a final test case population, so that the utilization of the server resource is maximized, and the test case generation time is shortened.
Based on the third embodiment, a fourth embodiment of the test case generation method of the present invention is provided. Referring to fig. 5, fig. 5 is a flowchart illustrating a test case generating method according to a fourth embodiment of the present invention. In the embodiment of the present invention, step S231 includes: and determining a target resource allocation scheme according to the server resources and the a-th generation test case population based on the ant colony algorithm taking the task completion time as an index.
It should be noted that, in the embodiment of the present invention, each server node processes the assigned test cases in parallel, and therefore, the task completion time is the maximum value of the time required for each server node to process the assigned a-th generation test case. For example, suppose that a server resource includes 3 server nodes, the a-th generation test case population includes 10 test cases, and test cases 1 to 3 are allocated to the first server node; and 4-8 test cases are distributed to the second server node, 9-10 test cases are distributed to the third server node, and if the time consumed by the first server node for processing the test cases 1-3 is 3 minutes, the time consumed by the second server node for processing the test cases 4-8 is 5 minutes, and the time consumed by the third server node for processing the test cases 9-10 is 2 minutes, the task completion time is 5 minutes.
It should be understood that the Ant Colony Algorithm (ACA) is a probabilistic Algorithm used to find an optimal path. The ant colony algorithm is derived from the phenomenon that the shortest path is found in the foraging process of an ant colony, in the process of searching food, at the beginning, as pheromones are not on the ground, the walking paths of ants are random, the ants can release a substance called pheromone in the walking process to identify the walking paths of the ants, as time goes on, a plurality of ants find the food, at the moment, a plurality of paths from caves to the food exist, and as the behavior tracks of the ants are distributed randomly, the number of the ants on the short path is more than that of the ants on the long path in unit time, so that the higher the concentration of the pheromone left by the ants is, and the shortest path can be determined according to the concentration of the pheromone. It can be seen that the ant colony algorithm is an enhanced learning mechanism, and converges to an optimal path after repeated iterations through continuous updating of pheromones. The basic idea for solving the optimization problem by the ant colony algorithm is as follows: the feasible solution of the problem to be optimized is represented by the walking paths of the ants, all paths of the whole ant colony form a solution space of the problem to be optimized, the quantity of pheromones released by ants with shorter paths is large, the concentration of the pheromones accumulated on the shorter paths is gradually increased along with the advance of time, the number of the ants selecting the paths is increased, finally, the whole ants are concentrated on the optimal path under the action of positive feedback, and the corresponding optimal solution of the problem to be optimized is provided at the moment.
In order to reduce task completion time and improve test case generation speed, in the embodiment of the invention, an ant colony algorithm takes the task completion time as an index, and a target resource allocation scheme is determined according to server resources and the a-th generation test case population based on the ant colony algorithm; namely, based on the ant colony algorithm, the server resources are subjected to load balancing, so that the processing time of each server node on the a-th generation test case is shortest, and the test case generation time is saved. That is to say, in the embodiment of the present invention, a feasible solution of the problem to be optimized by the ant colony algorithm is a resource allocation scheme, a solution space of the problem to be optimized is all resource allocation schemes, the resource allocation scheme with shorter task completion time has a larger amount of pheromones, and as time advances, the pheromone concentration accumulated in the resource allocation scheme with shorter task completion time gradually increases, so that the solution is concentrated on the resource allocation scheme with the shortest task completion time under the action of positive feedback, and at this time, the solution corresponds to an optimal solution of the problem to be optimized.
In some embodiments, step S231 may include the steps of:
step S2311: and respectively determining the processing time of each server node aiming at each a-th generation test case to obtain a processing time matrix.
In the embodiment of the invention, aiming at each a-th generation test case, according to the processing capacity of each server node, the processing time required by each server node for processing the a-th to-be-tested case is respectively determined (namely, the processing time required by each server node for processing each a-th generation test case is determined), so that a processing time matrix is obtained according to the processing time.
For example, suppose that the a-th generation test case population includes 3 test cases, the server resource includes 2 server nodes, and the processing time for processing the test case 1, the processing time for processing the test case 2, and the processing time for processing the test case 3 by the first server node are respectively determined; and respectively determining the processing time of the second server node for processing the test case 1, the processing time of the second server node for processing the test case 2 and the processing time of the second server node for processing the test case 3 to generate a processing time matrix. The processing time matrix TimeMatrix is a two-dimensional matrix, and TimeMatrix [ i ] [ j ] represents the processing time required for allocating the ith test case to the jth server node for processing.
Step S2312: the pheromone matrix is initialized.
It should be understood that the ant colony algorithm includes a pheromone matrix, and in the embodiment of the present invention, based on the number of the a-th generation test cases and the number of the server nodes, the pheromone matrix is generated and initialized. It should be noted that, in the embodiment of the present invention, the pheromoneMatrix is a two-dimensional matrix, and pheromoneMatrix [ i ] [ j ] indicates the pheromone concentration corresponding to the path that assigns the ith test case to the jth server node. The specific manner of initializing the pheromone matrix can be flexibly set according to actual needs, and in one example, the pheromone matrix is initialized by setting the value of each element in the pheromone matrix to 1.
Step S2313: and performing iterative search based on the processing time matrix and the pheromone matrix until a preset second iteration stopping condition is met to obtain a target resource allocation scheme.
The second iteration stopping condition can be flexibly set according to actual needs. In some embodiments, the second stop iteration condition may include: the iteration times reach an ant colony iteration time threshold, or a global optimal solution (i.e., a global optimal resource allocation scheme, i.e., a resource allocation scheme with the shortest task completion time, at which time, the ant colony algorithm converges) is obtained. The ant colony iteration time threshold value can be flexibly set according to actual needs. In an example, considering that too many iterations cause excessive time and resource overhead, and thus cannot satisfy scheduling of massive tasks, but too few iterations result in a longer task completion time of the resource scheduling scheme, therefore, the ant colony iteration number threshold may be determined according to the number of server nodes and the number of a-th generation test cases, where the ant colony iteration number threshold may be positively correlated with the number of server nodes and the number of a-th generation test cases, that is, the greater the number of server nodes and the number of a-th generation test cases, the greater the ant colony iteration number threshold.
And after the processing time matrix and the pheromone matrix are obtained, iterative search is carried out, iteration is stopped when a preset second iteration stopping condition is met, and the latest obtained resource allocation scheme is used as a target resource allocation scheme.
The test case generation method provided by the embodiment of the invention is based on the ant colony algorithm taking the task completion time as an index, and determines the target resource allocation scheme with the shortest task completion time according to the server resources and the a-th generation test case population, namely, based on the ant colony algorithm, so that the test case generation time is maximally shortened.
Based on the fourth embodiment, a fifth embodiment of the test case generation method of the present invention is provided. In the embodiment of the present invention, step S2313 includes:
step 1: and determining k sets of resource allocation schemes based on a task allocation function, wherein k is a positive integer.
And k is similar to the number of ants in the ant colony algorithm, and the value of k can be flexibly set according to actual needs. In one example, k is equal to the number of server nodes in the server resource.
The ant colony algorithm comprises a task allocation function, and the task allocation function can be flexibly set according to actual needs.
In the embodiment of the invention, the server resources are distributed based on the task distribution function, so that a plurality of sets of resource distribution schemes are obtained, and different resource distribution schemes are obtained.
In some embodiments, to avoid the occurrence of the stalling phenomenon, the task allocation function includes two task allocation strategies: performing allocation and random classification strategies based on the pheromone matrix; when k sets of resource allocation schemes are determined based on the task allocation function, m sets of resource allocation schemes (namely, tasks are allocated to nodes with high pheromone concentration for processing) are determined based on the pheromone matrix; and determining n sets of resource allocation schemes based on the random allocation strategy. Wherein m and n are integers greater than or equal to 1, k is m + n, and the specific values of m and n can be flexibly set according to actual needs.
Step 2: and determining the task completion time of each resource allocation scheme based on the processing time matrix.
Since the processing time matrix includes the processing time of each server node for each a-th generation test case, based on the processing time matrix and the resource allocation scheme, the task completion time corresponding to the resource allocation scheme can be determined.
And step 3: and determining a local optimal resource allocation scheme based on the task completion time of each resource allocation scheme.
And taking the resource allocation scheme with the shortest task completion time in the k sets of resource allocation schemes as the optimal resource allocation scheme in the iteration process, namely the local optimal resource allocation scheme.
And 4, step 4: and updating the pheromone matrix based on the local optimal resource allocation scheme.
In the embodiment of the invention, the pheromone matrix is updated based on the local optimal resource allocation scheme; the specific updating mode can be flexibly set according to actual needs.
In one example, the pheromone concentration of an element corresponding to the locally optimal resource allocation scheme in the pheromone matrix may be increased. For example, if the 1 st test case is allocated to the 2 nd server node in the local optimal allocation scheme, the pheromone matrix [1] [2] pheromone concentration is increased.
In some embodiments, the pheromone concentration range [ tau ] is set in advance according to actual needsminmax]Based on the local optimal resource allocation scheme, in the process of updating the pheromone matrix, if the pheromone concentration corresponding to a certain element exceeds the range, the pheromone concentration of the element is reset to tauminOr τmax(if the pheromone concentration is lower than τminThen reset to τmin(ii) a If the pheromone concentration is higher than taumaxThen reset to τmax)。
And 5: and (4) returning to the step (1) for iteration until a preset second iteration stopping condition is met, so as to obtain a target resource allocation scheme.
And (4) returning to the step (1) for iteration until the iteration times reach a preset second iteration stopping condition so as to obtain a target resource allocation scheme. For example, if iteration is stopped when the iteration number reaches the ant colony iteration number threshold, the local optimal resource allocation scheme obtained in the latest iteration process is used as a target resource allocation scheme; and if the iteration is stopped when the global optimal resource allocation scheme is obtained, taking the global optimal resource allocation scheme as a target resource allocation scheme.
According to the test case generation method provided by the embodiment of the invention, in each iteration process, the optimal resource allocation scheme is selected based on the task completion time, so that the task completion time of the finally determined target resource allocation scheme is shorter, and the test case generation efficiency is improved.
Test case generation apparatus embodiment:
referring to fig. 6, fig. 6 is a block diagram of a first embodiment of a test case generating apparatus according to the present invention, where the test case generating apparatus includes:
the obtaining module 61 obtains a source program of the test object.
The generating module 62 is configured to generate an initial test case based on the source program to obtain a 1 st generation test case population, where the 1 st generation test case population includes a plurality of test cases.
And a determining module 63, configured to determine a final test case population based on the 1 st generation test case population and the genetic algorithm.
It should be noted that the test case generation apparatus may further optionally include a corresponding module to implement other steps of the test case generation method.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for causing a terminal device to execute the method according to the embodiments of the present invention.
The above description is only an alternative embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications and equivalents of the present invention, which are made by the contents of the present specification and the accompanying drawings, or directly/indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (11)

1. A test case generation method is characterized by comprising the following steps:
acquiring a source program of a test object;
generating an initial test case based on the source program to obtain a 1 st generation test case population, wherein the 1 st generation test case population comprises a plurality of test cases;
and determining a final test case population based on the 1 st generation test case population and a genetic algorithm.
2. The method for generating test cases according to claim 1, wherein the step of generating initial test cases based on the source program to obtain a 1 st-generation test case population comprises:
performing lexical analysis and characteristic value extraction on the source program to obtain a frame of the source program;
and generating an initial test case based on the frame and a preset test case generating function to obtain a 1 st generation test case population.
3. The test case generation method of claim 1 or 2, wherein the step of determining a final test case population based on the 1 st generation test case population and a genetic algorithm comprises:
determining a target resource allocation scheme based on server resources and an a-th generation test case population, wherein an initial value of a is 1, a is a positive integer, and the server resources comprise at least one server node;
distributing each a-th generation test case in the a-th generation test case population to each server node in the server resources based on the target resource distribution scheme so that each server node processes the distributed a-th generation test case to obtain the fitness of each a-th generation test case;
selecting, crossing and mutating the a-th generation test case in the a-th generation test case population based on the fitness of each a-th generation initial test case to obtain an a + 1-th generation test case population;
and setting a +1, returning to the step based on the server resource and the a-th generation test case population, and determining a target resource allocation scheme to iterate until a preset first iteration stopping condition is met to obtain a final test case population.
4. The method for generating test cases according to claim 3, wherein the step of determining the target resource allocation plan based on the server resources and the a-th generation test case population comprises:
and determining a target resource allocation scheme according to server resources and the a-generation test case population based on an ant colony algorithm taking task completion time as an index, wherein the task completion time is the maximum value of time required by each server node to process the allocated a-generation test case.
5. The method for generating test cases according to claim 4, wherein the step of determining the target resource allocation plan based on the ant colony algorithm using the task completion time as an index according to the server resources and the a-th generation test case population includes:
respectively determining the processing time of each server node aiming at each a-th generation test case to obtain a processing time matrix;
initializing a pheromone matrix;
and performing iterative search based on the processing time matrix and the pheromone matrix until a preset second iteration stopping condition is met to obtain a target resource allocation scheme.
6. The method for generating test cases according to claim 5, wherein the step of performing iterative search based on the processing time matrix and the pheromone matrix until a preset iteration stop condition is satisfied to obtain a target resource allocation scheme includes:
determining k sets of resource allocation schemes based on a task allocation function, wherein k is a positive integer;
determining task completion time of each resource allocation scheme based on the processing time matrix;
determining a local optimal resource allocation scheme based on task completion time of each resource allocation scheme; updating the pheromone matrix based on the local optimal resource allocation scheme;
and returning to the step of determining k sets of resource allocation schemes based on the task allocation function to perform iteration until a preset second iteration stopping condition is met, so as to obtain a target resource allocation scheme.
7. The test case generation method of claim 6, wherein the step of determining k sets of resource allocation schemes based on the task allocation function comprises:
determining m sets of resource allocation schemes based on the pheromone matrix, wherein m is an integer greater than or equal to 1;
determining n sets of resource allocation schemes based on a random allocation strategy, wherein n is an integer greater than or equal to 1, and k is m + n.
8. The test case generation method according to claim 5, wherein the preset ant colony iteration stop condition includes: the iteration times reach an ant colony iteration time threshold value, or a global optimal resource allocation scheme is obtained; the ant colony iteration time threshold is determined according to the number of the server nodes and the number of the a-th generation test cases.
9. A test case generation apparatus, comprising:
the acquisition module acquires a source program of a test object;
the generation module is used for generating an initial test case based on the source program to obtain a 1 st generation test case population, and the 1 st generation test case population comprises a plurality of test cases;
and the determining module is used for determining a final test case population based on the 1 st generation test case population and the genetic algorithm.
10. A test case generation device, characterized by comprising: a memory, a processor and a test case generation program stored on the memory and running on the processor, the test case generation program when executed by the processor implementing the steps of the test case generation method according to any of claims 1-8.
11. A computer-readable storage medium, on which a test case generation program is stored, which, when executed by a processor, implements the steps of the test case generation method according to any one of claims 1 to 8.
CN202011643974.3A 2020-12-30 2020-12-30 Test case generation method, device, equipment and computer readable storage medium Pending CN112597055A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011643974.3A CN112597055A (en) 2020-12-30 2020-12-30 Test case generation method, device, equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011643974.3A CN112597055A (en) 2020-12-30 2020-12-30 Test case generation method, device, equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN112597055A true CN112597055A (en) 2021-04-02

Family

ID=75206687

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011643974.3A Pending CN112597055A (en) 2020-12-30 2020-12-30 Test case generation method, device, equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN112597055A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114116452A (en) * 2021-10-29 2022-03-01 北京达佳互联信息技术有限公司 Test case generation method and device, electronic equipment and storage medium
CN115687158A (en) * 2022-12-28 2023-02-03 北京邮电大学 Protocol software testing method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114116452A (en) * 2021-10-29 2022-03-01 北京达佳互联信息技术有限公司 Test case generation method and device, electronic equipment and storage medium
CN115687158A (en) * 2022-12-28 2023-02-03 北京邮电大学 Protocol software testing method and device
CN115687158B (en) * 2022-12-28 2023-03-10 北京邮电大学 Protocol software testing method and device

Similar Documents

Publication Publication Date Title
US11733693B2 (en) Data acquisition method and apparatus
CN107220076B (en) A kind of method for recovering internal storage and device
CN112597055A (en) Test case generation method, device, equipment and computer readable storage medium
CN105094305A (en) Method for identifying user behavior, user equipment and behavior identification server
CN112333057B (en) Intelligent household equipment distribution network testing method and device, executive machine and storage medium
KR20220009682A (en) Method and system for distributed machine learning
CN110879776A (en) Test case generation method and device
CN111464352A (en) Call link data processing method and device
CN113378067B (en) Message recommendation method, device and medium based on user mining
CN112883036A (en) Index creation method, device, storage server and storage medium
CN117435306A (en) Cluster container expansion and contraction method, device, equipment and storage medium
CN104239594A (en) Artificial environment model, Agent model and modeling method of Agent model
CN113392018B (en) Traffic distribution method and device, storage medium and electronic equipment
CN111274249A (en) User image data storage optimization method, device and readable storage medium
CN109195186A (en) A kind of network slice access intensified learning method based on evolutionary Game
CN113971455A (en) Distributed model training method and device, storage medium and computer equipment
CN109597660B (en) Application configuration or service updating method and device, storage medium and terminal equipment
CN115858473A (en) Data interaction method and device based on training system and object storage system
CN114978974B (en) Wireless communication module testing method, device, equipment and storage medium
CN115375193B (en) Method, device and equipment for optimizing double-target production scheduling and readable storage medium
CN116843016A (en) Federal learning method, system and medium based on reinforcement learning under mobile edge computing network
CN114266324B (en) Model visualization modeling method and device, computer equipment and storage medium
CN113886688B (en) Method, device, terminal equipment and storage medium for predicting association relation of objects
CN113225234B (en) Asset detection method, device, terminal equipment and computer readable storage medium
CN115499315A (en) OTA (over the air) upgrading task execution method and device and electronic equipment

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