Test case generation method and device for software aging, equipment and medium
Generating test cases with aging theme genes through genetic algorithm and metaheuristic technology solves the problem of lack of pertinence in software aging detection in the existing technology, and achieves efficient and accurate software aging detection.
Patent Information
- Application Number
- CN202310845239.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-10
- Publication Date
- 2025-01-24
AI Technical Summary
The existing software aging detection methods are not targeted, which leads to a long detection process and is difficult to locate aging defects.
By obtaining the initial species group, the evolution of the genetic algorithm, generating test cases with aging theme genes, and using the meta -inspirational technology to generate multiple types of groups to optimize test cases to improve the adaptability of aging indicators.
A fast and efficient testing of test cases for software aging can be achieved, which can cause software aging faster and provide reapable test cases, which significantly improves the detection efficiency and accuracy.
Smart Images

Figure CN119357036A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of application detection technology, and in particular to a method, device, equipment and medium for generating test cases for software aging. Background Art
[0002] With the continuous upgrading and iteration of software systems, the internal structure of the software becomes more and more complex, and the factors that cause software aging also become more and more complex.
[0003] It is necessary to detect the factors that cause software aging, and then improve the software based on the aging factors. Software aging can be detected by stress testing. There are two main test cases used in stress testing. The first is to use tools to generate random event sequences as test cases; the second is to use fixed test case scripts. The test cases in the script mainly rely on the tester to build.
[0004] Using the above test cases to perform aging detection on software lacks specificity for aging defects, resulting in a long detection process and difficulty in locating aging defects. Summary of the invention
[0005] The embodiment of the present application provides a method, device, equipment and medium for generating test cases for software aging. The technical solution is as follows:
[0006] According to one aspect of the present application, a method for generating test cases for software aging is provided, the method comprising:
[0007] Obtain an i-th generation population, the i-th generation population includes at least two individuals, each individual includes a test sequence formed by at least two chromosomes, each chromosome corresponds to a test case, and each chromosome includes at least an aging theme gene, the aging theme gene is used to indicate a behavior pattern associated with a software aging fault, and i is a positive integer;
[0008] Performing an evolution operation on the i-th generation population to obtain a subsequent generation population;
[0009] Performing software testing on the test sequences in each individual in the i-th generation population and the offspring population to obtain fitness evaluation of each individual, wherein the fitness evaluation at least includes an aging index;
[0010] Sorting the individuals based on the fitness evaluation to obtain a plurality of sorted individuals;
[0011] Selecting the i+1 generation population from the sorted multiple individuals;
[0012] The above steps are iterated until an iteration end condition is met, and a test case for the software aging is obtained based on the population after the iteration ends.
[0013] According to another aspect of the present application, a test case generation device for software aging is provided, the device comprising:
[0014] An acquisition module is used to acquire an i-th generation population, wherein the i-th generation population includes at least two individuals, each individual includes a test sequence formed by at least two chromosomes, each of the chromosomes corresponds to a test case, and each of the chromosomes includes at least an aging theme gene, wherein the aging theme gene is used to indicate a behavior pattern associated with a software aging fault, and i is a positive integer;
[0015] An evolution module, used for performing an evolution operation on the i-th generation population to obtain a subsequent generation population;
[0016] A testing module, used to perform software testing on the test sequences in the i-th generation population and each individual in the offspring population to obtain fitness evaluation of each individual, wherein the fitness evaluation includes at least an aging index;
[0017] A sorting module, used for sorting the individuals based on the fitness evaluation to obtain a plurality of sorted individuals;
[0018] A selection module, used for selecting the i+1 generation population from the sorted multiple individuals;
[0019] A determination module is used to iterate the steps executed by the above modules until an iteration end condition is met, and to obtain a test case for the software aging based on the population after the iteration ends.
[0020] According to another aspect of the present application, a computer device is provided, which includes a processor and a memory connected to the processor, wherein program instructions are stored in the memory, and when the processor executes the program instructions, a test case generation method for software aging as provided in various aspects of the present application is implemented.
[0021] According to another aspect of the present application, a computer-readable storage medium is provided, in which program instructions are stored. When the program instructions are executed by a processor, a test case generation method for software aging as provided in various aspects of the present application is implemented.
[0022] According to another aspect of the present application, a computer program product (or computer program) is provided, wherein the computer program product (or computer program) includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in various optional implementations of the above-mentioned test case generation method for software aging.
[0023] According to another aspect of the present application, a chip is provided, which includes a programmable logic circuit and / or program instructions. When the chip is running, it is used to implement the test case generation method for software aging provided in various aspects of the present application.
[0024] The beneficial effects brought by the technical solution provided by the embodiments of the present application may include:
[0025] The test case generation method for software aging provided in the present application utilizes metaheuristic technology to iteratively generate multiple populations. By continuously iterating the populations, the optimal individuals for multiple objectives including aging indicators are found, thereby generating test cases that can be used for software aging testing in a targeted manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly introduce the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 A schematic diagram showing the composition of an individual (i.e., a test kit) provided by an exemplary embodiment of the present application is shown;
[0028] Figure 2 A flowchart of a test case generation method for software aging provided by an exemplary embodiment of the present application is shown;
[0029] Figure 3 A flowchart of a test case generation method for software aging provided by an exemplary embodiment of the present application is shown;
[0030] Figure 4 A block diagram of a test case generation device for software aging provided by an exemplary embodiment of the present application is shown;
[0031] Figure 5 A schematic diagram of the structure of a computer device provided by an exemplary embodiment of the present application is shown. DETAILED DESCRIPTION
[0032] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0033] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0034] In the description of the present application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In the description of the present application, it should be noted that, unless otherwise clearly specified and limited, the terms "connected" and "connected" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" means two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0035] With the continuous upgrading and iteration of software systems, the internal structure of the software becomes more and more complex, and the factors that cause software aging also become more and more complex.
[0036] It is necessary to detect the factors that cause software aging, and then improve the software based on the aging factors. Software aging can be detected by stress testing. There are two main test cases used in stress testing. The first is to use tools to generate random event sequences as test cases. Using this test case to perform software aging detection is time-consuming and weak in targeting aging defects. In addition, the sequence of generated test cases is too long, which is impractical for debugging. In reality, it is unlikely that the sequence will be too long. The second is to use fixed test case scripts. The construction of test cases in the script mainly depends on the tester's understanding of aging defects. Over-reliance on the tester's experience will also cause the test to usually focus on one or two paths.
[0037] Using the above test cases to perform aging detection on software lacks specificity for aging defects, resulting in a long detection process and difficulty in locating aging defects.
[0038] In order to solve the above technical problems, the present application provides a test case generation method for software aging. For detailed method implementation, please refer to the following embodiments.
[0039] The technical contents involved in this application are explained.
[0040] The common behaviors extracted from software aging failures, and each time the common behaviors are executed, the performance parameters related to the software aging failures, such as system response time, application delay time, amount of memory occupied, etc., are detected. After repeating the common behaviors for multiple times, multiple detection results are obtained. The above multiple detection results are all within the specified parameter range. The common behaviors are the minimum transformation loop. For example, jump from the first page to the second page, and then return from the second page to the first page, repeat the entry and return operations, and the memory remains unchanged. Then the above process of jumping from the first page to the second page and then returning from the second page to the first page is a minimum transformation loop. The operation loop corresponding to the minimum transformation loop does not contain irrelevant redundant operations.
[0041] In the method provided in the present application, based on the above-mentioned minimum transformation cycle, the representation of the problem, the evolution rules, and the fitness evaluation are defined.
[0042] · Problem statement
[0043] An indivisible independent operation event is defined as an atomic gene, which is used to implement a certain function in the software; multiple atomic genes constitute a theme gene, which is used to implement a higher-level function than the atomic gene. There is an aging theme gene in the theme gene, which can be composed of at least one atomic gene and at least one theme gene. The aging theme gene is used to represent the behavior mode of software aging failure, and the sequence of the executed operation events is the minimum transformation cycle.
[0044] Atomic genes and subject genes represent test events in a test case. A chromosome represents a test case. In the embodiments provided in the present application, a chromosome is composed of at least one subject gene, or at least one atomic gene and at least one subject gene, and at least one subject gene includes an aging subject gene. An individual represents a test suite, and an individual is composed of one or more chromosomes.
[0045] For example, Figure 1As shown, an individual is composed of n chromosomes, namely chromosome 1, chromosome 2, chromosome 3, ..., chromosome n, where n is an integer greater than 3. Chromosome 1 is composed of m+1 theme genes, namely theme gene 1, theme gene 2, theme gene 3, ..., theme gene m, and aging theme gene, where m is an integer greater than 3. Taking theme gene 2 as an example, theme gene 2 is composed of L atomic genes, and these L atomic genes can be alleles. For example, alleles can be used to indicate different operating events that realize the same function. The aging theme gene can be composed of a cyclic sequence of atomic gene 1 and atomic gene 2.
[0046] Evolution rules
[0047] Individuals and chromosomes can cross over and mutate with a certain probability. A single chromosome can also evolve by disrupting its own gene sequence, such as disrupting the order of atomic genes and theme genes within the chromosome.
[0048] Fitness evaluation
[0049] The fitness of the test suite is evaluated from multiple factors, including factors related to software aging failures, such as code coverage, sequence length, and aging revelation degree.
[0050] Code coverage is a metric in software testing that describes the proportion and degree of source code in a program that is tested. The resulting proportion is called code coverage. In order to measure the degree to which a test suite tests software, one or more different coverage criteria are used. Coverage criteria may include: basic coverage criteria, such as function coverage, instruction coverage, judgment coverage, condition coverage, condition / judgment coverage, etc.; modified condition / judgment coverage criteria; multiple condition coverage criteria; other coverage criteria, such as path coverage, loop coverage, parameter value coverage, entry / end point coverage, etc.
[0051] Sequence length refers to gene length. For example, the sequence length of a test suite is the gene length in the test suite, the sequence length of a test case is the gene length in the test case, and the sequence length of a chromosome is the gene length in the chromosome.
[0052] The degree of aging disclosure (ie, aging index) is represented by performance parameters reflecting aging failures, such as system response time when executing a test suite, and / or application delay time, and / or amount of memory occupied, and / or freezes and other parameters.
[0053] In the method provided in the present application, a target search is performed based on the representation of the problem, the evolution rules, and the fitness evaluation, and the search target is a test suite with a large code coverage, a short sequence length of test cases, and a large degree of aging disclosure.
[0054] Figure 2 A flowchart of a test case generation method for software aging provided by an exemplary embodiment of the present application is shown. The method can be applied to a computer device. The method includes:
[0055] Step 210, obtaining the i-th generation population, the i-th generation population includes at least two individuals, each individual includes a test sequence formed by at least two chromosomes, each chromosome corresponds to a test case, and each chromosome includes at least an aging theme gene, and the aging theme gene is used to indicate a behavior pattern associated with software aging failure.
[0056] Wherein, i is a positive integer. When the value of i is 1, the first generation population is the initial population. Optionally, the initial population is randomly generated, for example, based on executable events in the software (such as executable operation events in the software), a test sequence is randomly generated as a test case. Alternatively, the initial population is set by a tester, such as a test sequence set by a tester for an executable event in the software as a test case. Exemplarily, a chromosome includes atomic gene 1 and theme gene 2 in sequence, atomic gene 1 is a page rotation event, and theme gene 2 is a form filling event. When the value of i is an integer greater than 1, the i-th generation population is evolved from the previous generation population, as described in steps 220 to 250 below.
[0057] Each chromosome contains an aging theme gene, which is a gene related to software aging failure. Exemplarily, executing the aging theme gene once and / or repeatedly will cause the software to have an aging failure. Optionally, the computer device can extract the aging theme gene based on the common behavior pattern in the software aging failure. Optionally, the computer device extracts multiple candidate behavior patterns with common characteristics in the software aging failure; among the multiple candidate behavior patterns, the target behavior pattern with a metamorphosis relationship on the aging index when repeatedly executed is extracted as the aging theme gene. The metamorphosis relationship means that when a certain behavior pattern is repeatedly executed, the performance parameters related to the software aging failure detected belong to a specified parameter range, that is, when a certain behavior pattern is repeatedly executed, the performance parameters related to the software aging failure detected will fluctuate within a controllable parameter range, that is, the behavior pattern is said to have a metamorphosis relationship on the aging index. For example, the behavior pattern of repeatedly executing from the first page to the second page and then returning from the second page to the first page will not change the amount of memory occupied, and it is certain that this behavior pattern has a metamorphosis relationship on the aging index.
[0058] Optionally, for each chromosome of the at least two chromosomes included in each individual, the logical relationship between events in the chromosome conforms to the logical relationship between events executable in the software. For example, two adjacent events in the chromosome are a page zoom event and a form filling event on the page, respectively. In the software, the page zoom event can be executed first, and then the form filling event can be executed on the zoomed page.
[0059] Optionally, for at least two chromosomes included in each individual, the logical relationship between the events connected between adjacent chromosomes conforms to the logical relationship between the events executable in the software. For example, in two adjacent chromosomes, the first connection event in the previous chromosome and the second connection event in the next chromosome are respectively a touch event on the first page and an event of entering the second page. Executing the touch event on the first page can enter the second page.
[0060] Optionally, a logic model can be constructed based on the logical relationship between executable events in the software, and the logic model can be used to determine whether the logical relationship between events in the chromosome and / or the logical relationship between events connected between adjacent chromosomes conform to the logical relationship between executable events in the software. For example, if the event is an operation event on an interface, an interface model can be constructed based on the jump logic between various interfaces in the software, and then based on the interface model, it can be determined whether the interface jump logic corresponding to the operation event in the chromosome conforms to the jump logic between interfaces in the software, or whether the interface jump logic corresponding to the operation event connected between chromosomes conforms to the jump logic between interfaces in the software.
[0061] Optionally, the aging subject gene is a minimal metamorphosis loop.
[0062] Step 220, performing evolution operations on the i-th generation population to obtain a subsequent generation population.
[0063] Exemplarily, the computer device uses a meta-heuristic algorithm to perform an evolution operation on the i-th generation population to obtain a subsequent generation population. Optionally, the meta-heuristic algorithm includes but is not limited to one of the following: a genetic algorithm, a simulated annealing algorithm, an ant colony optimization algorithm, a particle swarm algorithm, a differential evolution algorithm, an iterative greedy algorithm, and an artificial neural network algorithm.
[0064] Optionally, taking the meta-heuristic algorithm as an example of a genetic algorithm, the computer device performs an evolution operation in the genetic algorithm on the i-th generation population to obtain a descendant population. Exemplarily, the computer device randomly generates a random number; when the random number is less than the crossover probability, a crossover operation is performed on two individuals in the i-th generation population to generate a first descendant individual to join the descendant population; when the random number is greater than the crossover probability and less than the probability sum, a mutation operation is performed on an individual in the i-th generation population according to the mutation probability to generate a second descendant individual to join the descendant population; when the random number is greater than the probability sum, a replication operation is performed on an individual in the i-th generation population to generate a third descendant individual to join the descendant population; wherein the probability sum is the sum of the crossover probability and the mutation probability.
[0065] Exemplarily, the random number is a natural number in the natural number interval greater than or equal to 0 and less than or equal to 1.
[0066] Step 230, performing software testing on the test sequences in each individual in the i-th generation population and the subsequent generation population to obtain fitness evaluation of each individual, wherein the fitness evaluation at least includes an aging index.
[0067] Optionally, the computer device performs software testing on the test sequences in each individual in the i-th generation population and the offspring population, and monitors multiple optimization targets corresponding to each individual; based on the multiple optimization targets corresponding to each individual, a fitness evaluation of each individual is obtained; wherein the multiple optimization targets include: an aging index and other indicators, the other indicators include at least one of a code coverage index and a sequence length index, the code coverage index is used to indicate the proportion of the code being tested, and the sequence length index is used to indicate the sequence length of the test case in the current individual or the sequence length of the current individual.
[0068] In the process of software testing of the test sequence in each individual in the i-th generation population and the offspring population, the type of each chromosome in the test sequence is determined; when the type of the chromosome is a non-aging theme gene, the test case corresponding to the chromosome is executed on the tested software; when the type of the chromosome is an aging theme gene, the test case corresponding to the chromosome is repeatedly executed on the tested software until the maximum repetition time; during the software testing process, multiple optimization targets corresponding to each individual are monitored, and based on the multiple optimization targets corresponding to each individual, the fitness evaluation of each individual is obtained.
[0069] Optionally, after each test case is executed, the tested software is restarted; or, after each test case is executed, the tested software is initialized. By restarting or initializing the test software, it is ensured that the execution environment of each test case executed by the test software is the same, so that the fitness evaluation corresponding to each test case is more accurate and reasonable.
[0070] Step 240, sorting each individual based on the fitness evaluation to obtain a plurality of sorted individuals.
[0071] The computer device sorts the individuals in descending order of fitness evaluation to obtain a plurality of sorted individuals.
[0072] Optionally, the computer device performs non-dominated sorting of each individual based on the Pareto dominance relationship based on the fitness evaluation to obtain the Pareto level of each individual, and calculates the crowding degree of each individual based on the Pareto dominance relationship to obtain the crowding degree of each individual; sorts each individual in order from high to low Pareto level, and sorts them in descending order of crowding degree in the same Pareto level to obtain multiple sorted individuals.
[0073] The Pareto Dominance relationship is described as follows.
[0074] Pareto optimal solution, also known as Pareto efficiency, refers to an ideal state of resource allocation, assuming that a group of people and allocable resources change from one allocation state to another, without making anyone worse off. The Pareto optimal state means that there is no room for more Pareto improvements; in other words, Pareto improvement is the path and method to achieve Pareto optimality. Pareto optimality is the "ideal kingdom" of fairness and efficiency. Among them, the multiple individuals in the population in this embodiment can be regarded as the above-mentioned "group of people".
[0075] Pareto solutions are also called non-dominated solutions. If there is no other decision variable that can dominate a decision variable, then the decision variable is called a non-dominated solution. When there are multiple objectives, due to the conflict and incomparability between objectives, a solution is the best in one objective and may be the worst in other objectives. These solutions that will inevitably weaken at least one other objective function while improving any objective function are called Pareto solutions or non-dominated solutions. A set of optimal solutions to a set of objective functions is called a Pareto optimal set. The surface formed by the optimal set in space is called a Pareto frontier. The concept of a non-dominated solution for multiple objectives is defined as: Assuming that for any two solutions S1 and S2, S1 is better than S2 for all objectives, then we say that S1 dominates S2. If S1 is not dominated by other solutions, then S1 becomes a non-dominated solution, also called a Pareto solution.
[0076] Pareto rank In a set of solutions, the Pareto value of a non-dominated solution is defined as 1. The non-dominated solution is deleted from the solution set, and the Pareto rank of the remaining solution is defined as 2. By analogy, the Pareto rank of all solutions in the solution set can be obtained.
[0077] Exemplarily, the Pareto dominance algorithm includes: generating a set of initial solutions, such as solutions of multiple optimization objectives corresponding to each individual is a set of initial solutions; and screening out the Pareto optimal solution set by calculating the dominance relationship of each solution.
[0078] Optionally, the Pareto-dominated algorithm includes but is not limited to one of the following: a non-dominated sorting genetic algorithm II (NSGA-II) algorithm, a multi-objective evolutionary algorithm (MOEA), and a multi-objective evolutionary algorithm based on decomposition (MOEA / D). Where the NSGA-II algorithm is used, the solutions can be sorted according to the dominance relationship, and the crowding distance is used to maintain the diversity of the solutions.
[0079] Step 250, selecting the i+1th generation population from the sorted individuals.
[0080] Optionally, the computer device selects the first H individuals from the sorted multiple individuals to form the i+1th generation population, where H is an integer greater than 1.
[0081] Step 260, iterate the above steps until the iteration end condition is met, and obtain the test case for software aging based on the population after the iteration ends.
[0082] Optionally, an iteration number threshold is set in the computer device, and the iteration end condition includes that the iteration number is greater than or equal to the iteration number threshold; and / or, an iteration duration threshold is set in the computer device, and the iteration end condition includes that the iteration duration is greater than or equal to the iteration duration threshold.
[0083] Optionally, the above steps are iterated until the iteration end condition is met, and the individual ranked first is determined from the population after the iteration ends; the test case sequence in the individual ranked first is determined as the test case sequence obtained for software aging.
[0084] Optionally, the above steps are iterated until the iteration end condition is met, and the individuals ranked in the top K positions are determined from the population after the iteration ends; the test case sequence among the individuals ranked in the top K positions is determined as the test case sequence for software aging, where K is an integer greater than 1.
[0085] Exemplarily, determining an individual from a population after the iteration may be determining the first or top K individuals from each population generated during the iteration, or determining the first or top K individuals from a population generated last during the iteration, or determining one or more individuals whose fitness evaluation meets the requirements from each population generated during the iteration.
[0086] In summary, the test case generation method for software aging provided in this embodiment uses metaheuristic technology to iteratively generate multiple populations, and through continuous iteration of the population, finds the individuals with the best multiple objectives including aging indicators, thereby generating test cases that can be used for software aging testing in a targeted manner.
[0087] Secondly, the aging theme genes in the test cases have a transformation relationship in terms of indicators, forming a minimum transformation cycle, which ensures that the aging theme genes can accurately reveal the degree of software aging during the software aging test process.
[0088] For example, Figure 3 As shown, taking the meta-heuristic algorithm as a genetic algorithm as an example, the test case generation method for software aging provided in this application is illustrated.
[0089] Before generating test cases for software aging, first perform the following three steps:
[0090] Identify the system F and the software to be tested A.
[0091] Determine the following parameters of the genetic algorithm:
[0092] The crossover probability P is set to "0.6-0.9" for example;
[0093] Mutation probability Q, for example, set to "0.0001~0.2";
[0094] The upper limit of genetic generation Gmax (i.e., the threshold of the number of iterations) is set, for example, to 20 to 100.
[0095] The parameters of the above genetic algorithm can be preset by the tester.
[0096] Determine the atomic gene list R, the aging theme gene list AO, the other theme gene list O, and the maximum repetition time Tmax.
[0097] The atomic gene list R includes atomic genes corresponding to executable events in the software to be tested A. Optionally, the atomic gene list R includes atomic genes corresponding to all executable events in the software to be tested A. Optionally, the atomic genes in the atomic gene list R are atomic genes randomly generated based on executable events in the software to be tested A, such as randomly extracting some executable events from the executable events in the software to be tested A to determine them as atomic genes, and adding the randomly determined atomic genes to the atomic gene list R.
[0098] Optionally, the theme gene list (including other main gene list O and aging theme gene list AO, other theme genes refer to theme genes other than aging theme genes) includes theme genes corresponding to theme events composed of executable events in the software A to be tested, wherein a theme event is composed of multiple executable events around a theme, such as a touch event and an editing event can constitute a form-filling theme event. Aging theme genes refer to theme genes in theme genes that are related to software aging failures. The maximum repetition time refers to the maximum duration of repeated execution of aging theme genes. Optionally, other theme gene list O includes all other theme genes supported by the software A to be tested; the aging theme gene list AO includes all aging theme genes supported by the software A to be tested.
[0099] Optionally, the theme genes supported by the software under test A refer to theme genes that satisfy the interface model W of the software under test A, and the interface model W is constructed based on the jump logic of each interface in the software under test A. The theme genes supported by the software under test A are theme genes that allow the software under test A to execute.
[0100] Optionally, the gene list and repetition duration can be preset by the tester. Alternatively, the gene list can also be randomly generated by a program; for example, the atomic genes in the atomic gene list R are randomly generated by a computer device based on executable events in the software to be tested A; for another example, the theme genes in the theme gene list are generated based on theme events in the software to be tested A.
[0101] Exemplarily, the software A to be tested is a browser, and the atomic genes are determined to be touch, slide, track, keyboard event, navigation, main navigation, start activity, rotation, zoom, and system operation (such as "volume mute"); the theme gene is determined to be filling in a form; and the aging theme gene is determined to be an event from state a to state b and then back to state a.
[0102] It should be noted that the execution order of the above three steps is not limited in the embodiments of the present application.
[0103] Generating test cases for software aging includes the following steps:
[0104] 1) Install the software A to be tested in the system F, and run the software A to be tested to generate an aging test case for the software A to be tested.
[0105] Exemplarily, the system is an Android system, the software to be tested is a browser, and the computer device can use an APK (Android application PacKage) compilation tool to install it.
[0106] 2) Initialize the initial population of the genetic algorithm (first generation population), the interface model M of the software to be tested A, and the test report C.
[0107] Test report C is a report for reflecting fitness evaluation. Optionally, test report C includes aging indicators, other indicators and videos, and other indicators include at least one of code coverage indicators and test case sequence length indicators. Alternatively, test report C includes an aging report, a coverage report and a video. Among them, the aging report is a report for reflecting aging indicators, the coverage report is a report for reflecting code coverage indicators, and the video is a video for showing interface changes when executing atomic genes and / or subject genes.
[0108] The computer device stores the initialized initial population in a database.
[0109] The computer device initializes the parameters of the genetic algorithm, that is, after determining the crossover probability P, mutation probability Q, and upper limit Gmax (i.e., the number of iterations threshold) of the genetic algorithm, the initial population of the genetic algorithm is initialized by the test generator 306. Exemplarily, in the process of generating the initial population by the test generator 306, the determined subject gene is judged as an aging subject gene. Exemplarily, the aging subject gene judger 307 is used to determine whether the subject gene is an aging subject gene, and whether the subject gene meets the minimum metamorphosis cycle.
[0110] For example, the software A to be tested is a browser, and the atomic genes are determined to be touch, slide, track, keyboard event, navigation, main navigation, start activity, rotation, zoom, system operation (such as "volume mute"); the theme gene is determined to be filling in a form; the aging theme gene is determined to be an event from state a to state b and then back to state a. The initial population can be composed of multiple individuals, and chromosome 1 in the individual can be {start activity, touch, keyboard event, touch, system operation, touch, fill in form, ..., touch}, and chromosome 2 can be {start activity, rotation, slide, touch, zoom, touch, navigation, touch, ..., slide}.
[0111] 3) Execute the test sequence in each individual to perform software testing and monitor multiple optimization goals corresponding to each individual.
[0112] For the initial population, each individual in the initial population is obtained from the database 301, and the test sequence in each individual is executed to perform software testing, and multiple optimization targets corresponding to each individual are monitored.
[0113] The computer device obtains each individual in the initial population from the database 301, interprets the atomic gene and the theme gene in each individual through the gene interpreter 302, edits the atomic gene and the theme gene into a language executable by the software A to be tested, and the software A to be tested executes the above language to realize software testing of the test sequence in each individual.
[0114] During the software testing process, if the event E in the test sequence in each individual is E∈R or E∈O, then the event E is executed; if E∈AO, then the event E is repeatedly executed until the execution time is greater than or equal to the maximum repetition time. After executing event E, the interface model W of the test software A is also initialized to ensure that when the interface model W is used to judge the logical relationship between adjacent events, the judgment environment provided by the interface model W used by each individual is the same or similar.
[0115] During the execution of the test sequences in each individual, the aging monitor 303 monitors data related to software aging failures, such as aging indicators and code coverage indicators, and stores the monitored data related to software aging failures in the database 301 .
[0116] 4) Obtaining data related to software aging failures from the database 301, such as multiple optimization targets corresponding to each individual; obtaining the fitness evaluation of each individual based on the multiple optimization targets corresponding to each individual through the fitness extractor 305.
[0117] 5) After executing a test case, the test software A is initialized or regenerated, that is, the state of the test software A is restored to the state before the test; the test report C is updated.
[0118] The computer device obtains data related to software aging failures from the database 301, such as aging indicators and code coverage indicators, and generates a test report C based on the data related to software aging failures through the test report generator 304, such as generating an aging report, a coverage report and a video.
[0119] Exemplarily, the interface changes of the test software A when executing the test sequence in each individual are recorded to obtain a screen recording video. The above video can be a video clip related to the software aging failure in the above screen recording video, such as a video clip when executing a certain aging theme gene.
[0120] Exemplarily, based on the data related to software aging faults obtained from individual tests, the content on test report C can be updated. After testing an individual, the data related to software aging faults obtained from the individual test is filled into test report C. Alternatively, for each individual, a test report C is generated.
[0121] Optionally, the data related to software aging faults includes multiple optimization objectives corresponding to each individual.
[0122] 6) The test generator 306 performs an evolutionary operation of the genetic algorithm on the i-th generation population to obtain an offspring population.
[0123] Exemplarily, during the generation process of the offspring population, the test generator 306 selects and mutates individuals through the genetic algorithm to generate the offspring population.
[0124] The computer device randomly generates a natural number u in [0, 1]; when u < P, two individuals are randomly determined from the previous generation population, and a crossover operation is performed on these two individuals, and the generated offspring are added to the offspring population; when P ≤ u < P + Q, a randomly determined individual from the previous generation population is shuffled in chromosome order, and a single-point crossover mutation is performed on the P chromosomes internally in units of genes, and the mutated individual is added to the offspring population; when u > ≥ P + Q, one or more individuals are randomly replicated from the previous generation population and added to the offspring population. The steps for executing the offspring population are as in 3)-5).
[0125] Exemplarily, during the process of the test generator 306 generating the offspring population, an aging theme gene judgment is performed on the determined theme gene. Exemplarily, the aging theme gene judge 307 determines whether the theme gene is an aging theme gene and judges whether the theme gene conforms to the minimum metamorphic loop.
[0126] 7) The i-th generation population and the offspring population are merged, and each individual is sorted based on fitness evaluation to obtain multiple sorted individuals.
[0127] Exemplarily, the computer device performs non-dominated sorting based on the Pareto dominance relationship on each individual through the test replay device 308 based on fitness evaluation to obtain the Pareto rank of each individual, and calculates the crowding degree of each individual based on the Pareto dominance relationship to obtain the crowding degree of each individual; each individual is sorted in descending order of Pareto rank, and in the same Pareto rank, sorted in descending order of crowding degree to obtain multiple sorted individuals.
[0128] 8) Select the (i + 1)-th generation population from the multiple sorted individuals.
[0129] Exemplarily, the computer device selects a specified number of individuals from the sorted individuals and adds them to the (i+1) generation population.
[0130] The computer device selects the i+1th generation population through the test replay device 308, and passes the individuals in the i+1th generation population to the gene interpreter. The gene interpreter interprets the genes and encodes them into executable instructions for the test software A, thereby realizing software testing based on the individuals in the i+1th generation population.
[0131] 9) Check whether the current genetic generation reaches Gmax. If so, end the search and generation of test cases; if not, return to execute steps 3)-8).
[0132] In summary, the test case generation method for software aging provided in this embodiment utilizes metaheuristic technology to iteratively generate multiple populations, and through continuous iteration of the populations, finds the individuals with the best multiple objectives including aging indicators, thereby generating test cases that can be used for software aging testing in a targeted manner. These test cases can induce software aging phenomena more quickly and provide reproducible test cases.
[0133] Secondly, the aging theme genes in the test cases have a transformation relationship in terms of indicators, forming a minimum transformation cycle. The aging theme gene pattern participates in the composition of chromosomes, namely test cases together with atomic genes and theme genes, making the composition of test cases more targeted at software aging defects.
[0134] In addition, the goal of aging revelation degree is added to the search-based multi-objective optimization. By monitoring and calculating the aging indicator data, the test cases are guided to develop in the direction we expect. Reports and videos that can analyze aging data are also provided.
[0135] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0136] Figure 4 The structural block diagram of a test case generation device for software aging provided by an exemplary embodiment of the present application is shown. The test case generation device for software aging can be implemented as all or part of a terminal through software, hardware, or a combination of both. The device includes:
[0137] The acquisition module 401 is used to acquire an i-th generation population, wherein the i-th generation population includes at least two individuals, each individual includes a test sequence formed by at least two chromosomes, each chromosome corresponds to a test case, and each chromosome includes at least an aging theme gene, wherein the aging theme gene is used to indicate a behavior pattern associated with a software aging fault, and i is a positive integer;
[0138] An evolution module 402 is used to perform an evolution operation on the i-th generation population to obtain a subsequent generation population;
[0139] A testing module 403 is used to perform software testing on the test sequences in each individual in the i-th generation population and the offspring population to obtain fitness evaluation of each individual, wherein the fitness evaluation at least includes an aging index;
[0140] A sorting module 404 is used to sort the individuals based on the fitness evaluation to obtain a plurality of sorted individuals;
[0141] A selection module 405 is used to select the i+1 generation population from the sorted multiple individuals;
[0142] The determination module 406 is used to iterate the steps executed by the above modules until the iteration end condition is met, and obtain the test case for the software aging based on the population after the iteration end.
[0143] In some embodiments, the testing module 403 is used to:
[0144] Performing software testing on the test sequences in the i-th generation population and each individual in the offspring population, and monitoring a plurality of optimization objectives corresponding to each individual;
[0145] Based on the multiple optimization objectives corresponding to the individuals, obtaining the fitness evaluation of the individuals;
[0146] Among them, the multiple optimization objectives include: the aging index and other indicators, the other indicators include at least one of a code coverage index and a test case sequence length index, the code coverage index is used to indicate the proportion of the code being tested, and the test case sequence length index is used to indicate the length of the test case in the current individual.
[0147] In some embodiments, the testing module 403 is used to:
[0148] In the process of performing software testing on the test sequences in the i-th generation population and each individual in the offspring population, determining the type of each chromosome in the test sequences;
[0149] In the case where the type of the chromosome is a non-aging theme gene, executing a test case corresponding to the chromosome on the tested software;
[0150] In the case where the type of the chromosome is the aging theme gene, repeatedly executing the test case corresponding to the chromosome on the tested software until a maximum repetition time;
[0151] During the software testing process, multiple optimization targets corresponding to each individual are monitored.
[0152] In some embodiments, the device further includes a restart module 407;
[0153] The restart module 407 is used to restart the tested software after each test case is executed.
[0154] In some embodiments, the evolution module 402 is configured to:
[0155] Randomly generate a random number;
[0156] When the random number is less than the crossover probability, a crossover operation is performed on two individuals in the i-th generation population to generate a first offspring individual to join the offspring population;
[0157] When the random number is greater than the crossover probability and less than the probability sum, a mutation operation is performed on an individual in the i-th generation population according to the mutation probability to generate a second offspring individual to join the offspring population;
[0158] When the random number is greater than the probability sum, a copy operation is performed on an individual in the i-th generation population to generate a third offspring individual to join the offspring population;
[0159] The probability sum is the sum of the crossover probability and the mutation probability.
[0160] In some embodiments, the determination module 406 is configured to:
[0161] Iterate the above steps until the iteration end condition is met, and determine the individual ranked first from the population after the iteration ends;
[0162] The test case sequence in the individual ranked first is determined as the test case sequence obtained for the software aging.
[0163] In some embodiments, the sorting module 404 is used to:
[0164] Based on the fitness evaluation, the individuals are sorted according to the Pareto dominance relationship to obtain the Pareto level of each individual, and the crowding degree of each individual is calculated according to the Pareto dominance relationship to obtain the crowding degree of each individual;
[0165] The individuals are sorted in descending order of the Pareto level, and in the same Pareto level, they are sorted in descending order of the crowding degree to obtain a plurality of sorted individuals.
[0166] In some embodiments, the apparatus further includes an extraction module 408;
[0167] The extraction module 408 is used to extract the aging theme gene based on the common behavior patterns in the software aging failures.
[0168] In some embodiments, the extraction module 408 is used to:
[0169] Extract multiple candidate behavior patterns with common characteristics in software aging failures;
[0170] Among the plurality of candidate behavior patterns, a target behavior pattern having a transformation relationship on the aging index when repeatedly executed is extracted as the aging theme gene.
[0171] It should be noted that: the test case generation device for software aging provided in the above embodiment only uses the division of the above functional modules as an example when executing the test case generation method for software aging. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the test case generation device for software aging provided in the above embodiment and the test case generation method embodiment for software aging belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0172] Figure 5 A schematic diagram of the structure of a computer device provided by an exemplary embodiment of the present application is shown. The computer device may be a server that executes a test case generation method for software aging as provided in the present application. Specifically:
[0173] The computer device 700 includes a central processing unit (CPU) 701, a system memory 704 including a random access memory (RAM) 702 and a read only memory (ROM) 703, and a system bus 705 connecting the system memory 704 and the central processing unit 701. The computer device 700 also includes a basic input / output system (I / O system) 706 for facilitating information transmission between various components in the computer, and a large-capacity storage device 707 for storing an operating system 713, application programs 714, and other program modules 715.
[0174] The basic input / output system 706 includes a display 708 for displaying information and an input device 709 such as a mouse and a keyboard for user inputting information. The display 708 and the input device 709 are connected to the central processing unit 701 through an input / output controller 710 connected to the system bus 705. The basic input / output system 706 may also include an input / output controller 710 for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input / output controller 710 also provides output to a display screen, a printer, or other types of output devices.
[0175] The mass storage device 707 is connected to the central processing unit 701 through a mass storage controller (not shown) connected to the system bus 705. The mass storage device 707 and its associated computer readable media provide non-volatile storage for the computer device 700. That is, the mass storage device 707 may include a computer readable medium (not shown) such as a hard disk or a compact disc read only memory (CD-ROM) drive.
[0176] Computer readable media may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer readable instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, Erasable Programmable Read Only Memory (EPROM), Electrically Erasable Programmable Read Only Memory (EEPROM), Flash memory or other solid-state storage technologies, CD-ROM, Digital Versatile Disc (DVD) or Solid State Drive (SSD), other optical storage, cassettes, tapes, disk storage or other magnetic storage devices. Among them, random access memory may include resistance random access memory (ReRAM) and dynamic random access memory (DRAM). Of course, those skilled in the art will know that computer storage media are not limited to the above. The above-mentioned system memory 704 and large-capacity storage device 707 can be collectively referred to as memory.
[0177] According to various embodiments of the present application, the computer device 700 can also be connected to a remote computer on the network through a network such as the Internet. That is, the computer device 700 can be connected to the network 712 through the network interface unit 711 connected to the system bus 705, or the network interface unit 711 can be used to connect to other types of networks or remote computer systems (not shown).
[0178] The above-mentioned memory also includes one or more programs, and the one or more programs are stored in the memory and are configured to be executed by the CPU to implement the test case generation method for software aging as described above.
[0179] An embodiment of the present application also provides a computer-readable storage medium, which stores at least one instruction, and the at least one instruction is loaded and executed by a processor to implement the test case generation method for software aging as described in the above embodiments.
[0180] Optionally, the computer readable storage medium may include: a read only memory (ROM), a random access memory (RAM), a solid state drive (SSD), or an optical disk, etc. Among them, the random access memory may include a resistance random access memory (ReRAM) and a dynamic random access memory (DRAM).
[0181] An embodiment of the present application also provides a computer program product (or computer program), which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned test case generation method for software aging provided in the above embodiments.
[0182] According to another aspect of the present application, a chip is provided, which includes a programmable logic circuit and / or program instructions. When the chip is running, it is used to implement the test case generation method for software aging as described in the above embodiments.
[0183] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0184] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0185] The above description is only an illustrative embodiment that can be implemented in the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.
Claims
1. A test case generation method for software aging, characterized in that: The method comprises: Obtain an i-th generation population, the i-th generation population includes at least two individuals, each individual includes a test sequence formed by at least two chromosomes, each chromosome corresponds to a test case, and each chromosome includes at least an aging theme gene, the aging theme gene is used to indicate a behavior pattern associated with a software aging fault, and i is a positive integer; Performing an evolution operation on the i-th generation population to obtain a subsequent generation population; Performing software testing on the test sequences in each individual in the i-th generation population and the offspring population to obtain fitness evaluation of each individual, wherein the fitness evaluation at least includes an aging index; Sorting the individuals based on the fitness evaluation to obtain a plurality of sorted individuals; Selecting the i+1th generation population from the sorted multiple individuals; The above steps are iterated until an iteration end condition is met, and a test case for the software aging is obtained based on the population after the iteration ends.
2. The method according to claim 1, characterized in that The performing software testing on the test sequences in each individual in the i-th generation population and the offspring population to obtain fitness evaluation of each individual includes: Performing software testing on the test sequences in the i-th generation population and each individual in the offspring population, and monitoring a plurality of optimization objectives corresponding to each individual; Based on the multiple optimization objectives corresponding to the individuals, obtaining the fitness evaluation of the individuals; Among them, the multiple optimization objectives include: the aging index and other indicators, the other indicators include at least one of a code coverage index and a test case sequence length index, the code coverage index is used to indicate the proportion of the code being tested, and the test case sequence length index is used to indicate the length of the test case in the current individual.
3. The method according to claim 2, characterized in that The performing software testing on the test sequences in each individual in the i-th generation population and the offspring population, and monitoring the multiple optimization targets corresponding to each individual, includes: In the process of performing software testing on the test sequences in the i-th generation population and each individual in the offspring population, determining the type of each chromosome in the test sequences; In the case where the type of the chromosome is a non-aging theme gene, executing a test case corresponding to the chromosome on the tested software; In the case where the type of the chromosome is the aging theme gene, repeatedly executing the test case corresponding to the chromosome on the tested software until a maximum repetition time; During the software testing process, multiple optimization targets corresponding to each individual are monitored.
4. The method according to claim 3, characterized in that The method further comprises: After each test case is executed, the tested software is restarted.
5. The method according to any one of claims 1 to 4, characterized in that: The step of performing an evolution operation on the i-th generation population to obtain a subsequent generation population includes: Randomly generate a random number; When the random number is less than the crossover probability, a crossover operation is performed on two individuals in the i-th generation population to generate a first offspring individual to join the offspring population; When the random number is greater than the crossover probability and less than the probability sum, a mutation operation is performed on an individual in the i-th generation population according to the mutation probability to generate a second offspring individual to join the offspring population; When the random number is greater than the probability sum, a copy operation is performed on an individual in the i-th generation population to generate a third offspring individual to join the offspring population; The probability sum is the sum of the crossover probability and the mutation probability.
6. The method according to claim 5, characterized in that The iterating the above steps until the iteration end condition is met, and obtaining the test case for the software aging based on the population after the iteration end, includes: Iterate the above steps until the iteration end condition is met, and determine the individual ranked first from the population after the iteration ends; The test case sequence in the individual ranked first is determined as the test case sequence obtained for the software aging.
7. The method according to any one of claims 1 to 5, characterized in that: The step of sorting the individuals based on the fitness evaluation to obtain a plurality of sorted individuals includes: Based on the fitness evaluation, the individuals are sorted according to the Pareto dominance relationship to obtain the Pareto level of each individual, and the crowding degree of each individual is calculated according to the Pareto dominance relationship to obtain the crowding degree of each individual; The individuals are sorted in descending order of the Pareto level, and in the same Pareto level, they are sorted in descending order of the crowding degree to obtain a plurality of sorted individuals.
8. The method according to claim 1, characterized in that The method further comprises: Based on the common behavior patterns in software aging failures, the aging theme genes are extracted.
9. The method according to claim 5, characterized in that The extraction of the aging theme gene based on the common behavior pattern in the software aging failure includes: Extract multiple candidate behavior patterns with common characteristics in software aging failures; Among the plurality of candidate behavior patterns, a target behavior pattern having a transformation relationship on the aging index when repeatedly executed is extracted as the aging theme gene.
10. A test case generation device for software aging, characterized in that: The device comprises: An acquisition module is used to acquire an i-th generation population, wherein the i-th generation population includes at least two individuals, each individual includes a test sequence formed by at least two chromosomes, each of the chromosomes corresponds to a test case, and each of the chromosomes includes at least an aging theme gene, wherein the aging theme gene is used to indicate a behavior pattern associated with a software aging fault, and i is a positive integer; An evolution module, used for performing an evolution operation on the i-th generation population to obtain a subsequent generation population; A testing module, used to perform software testing on the test sequences in the i-th generation population and each individual in the offspring population to obtain fitness evaluation of each individual, wherein the fitness evaluation includes at least an aging index; A sorting module, used for sorting the individuals based on the fitness evaluation to obtain a plurality of sorted individuals; A selection module, used for selecting the i+1 generation population from the sorted multiple individuals; A determination module is used to iterate the steps executed by the above modules until an iteration end condition is met, and a test case for the software aging is obtained based on the population after the iteration ends.
11. A computer device, characterized in that: The computer device includes a processor and a memory connected to the processor, wherein program instructions are stored in the memory, and when the processor executes the program instructions, the test case generation for software aging as described in any one of claims 1 to 9 is implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and when the program instructions are executed by a processor, the test case generation for software aging as described in any one of claims 1 to 9 is implemented.
13. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the test case generation for software aging as described in any one of claims 1 to 9.