Test case generation method, tested software testing method and device

By crossing and mutating the first type of test cases with many coverage features and supplementary test cases, the test case collection is dynamically generated, which solves the problem of difficulty in generating effective test cases when software updates are frequent, and achieves efficient testing and testing of modified codes. Test case validity.

CN113297059BActive Publication Date: 2024-08-30ZHEJIANG TMALL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010389413.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-05-10
Publication Date
2024-08-30
Estimated Expiration
2040-05-10

AI Technical Summary

Technical Problem

The existing technology is difficult to automatically generate effective test cases for testing the software update part (modified code), and cannot meet the testing needs of frequent software updates.

Method used

By crossing and mutating the first type of test cases with more coverage features and the second type of test cases with less coverage features that can be supplemented, a new set of test cases is dynamically generated, and through fitness calculation and excellence judgment, Ensure the validity of generated test cases.

Benefits of technology

It realizes effective testing of software modification code, reduces the redundancy of test cases, improves testing efficiency, and can automatically generate test cases for software update parts, ensuring the effectiveness of test cases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113297059B
    Figure CN113297059B
Patent Text Reader

Abstract

Disclosed are a method for generating a test case, a method for testing software under test, and a device. Test execution step: driving the software under test to execute the test cases in the test case set; case analysis step: analyzing the code of the software under test covered by the test case, and adding the test cases covering the new modified code to the modified code test case set; fitness calculation step: performing fitness calculation based on the code covered by the test case; new case generation step: performing crossover and mutation on the test cases with high quality based on the value range of the feature of the modified code; performing the steps of test execution, case analysis, and fitness calculation on the test cases in the new test case set, and when the quality of the test cases in the new test case set is lower than the preset quality threshold, the modified code test case set is used as the output result. Thus, a test case for testing the modified code can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of software testing, and in particular to a method for generating a test case, and a method and device for testing tested software. Background Art

[0002] A test case is a set of test inputs, execution conditions, and expected results compiled for a test objective to verify whether the software meets a specific requirement.

[0003] The writing of test cases is usually done manually. Specifically, the tester confirms the changed functions, changed data, data values, etc. of the software under test, designs a complete set of test cases, and finally drives the software under test to run the test cases for testing.

[0004] At present, the method of manually writing test cases can no longer meet the testing needs of increasingly frequent software updates. Therefore, how to automatically generate test cases that can test the updated parts (modified codes) of the software is a technical problem that urgently needs to be solved. Summary of the invention

[0005] A technical problem to be solved by the present disclosure is how to automatically generate test cases for testing the updated part (ie, modified code) of the software when software updates are increasingly frequent.

[0006] According to a first aspect of the present disclosure, a method for generating a test case is provided, comprising: a test execution step: driving the software under test to execute the test cases in a pre-constructed test case set, obtaining the code of the software under test covered by the test cases, wherein the test cases are divided into a first category of test cases and a second category of test cases, and the first category of test cases covers more features of the modified code of the software under test than the second category of test cases; a case analysis step: analyzing the code of the software under test covered by the second category of test cases, and adding the second category of test cases covering the new modified code of the software under test to the modified code test case set; a fitness calculation step: performing fitness calculation based on the coverage of the code of the software under test by the second category of test cases, and determining the quality of the second category of test cases; a new case generation step: based on the value range of the features of the modified code obtained in advance, crossing and mutating the second category of test cases with high quality with the first category of test cases, and obtaining a new test case set; performing the test execution, case analysis, and fitness calculation steps on the test cases in the new test case set, and when the quality of the test cases in the new test case set is lower than a preset quality threshold, using the modified code test case set as the output result

[0007] According to the second aspect of the present disclosure, a method for generating test cases is also provided, including: a test execution step: driving the software under test to execute the test cases in the test case set, and obtaining the code of the software under test covered by the test cases; a test case analysis step: analyzing the code of the software under test covered by the test cases, and adding the test cases covering the new modified code of the software under test to the modified code test case set; a fitness calculation step: performing fitness calculation based on the test cases covering the code of the software under test, and determining the quality of the test cases; a new test case generation step: based on the value range of the features of the modified code obtained in advance, crossing and mutating the test cases with high quality to obtain a new test case set; executing the test execution, case analysis, and fitness calculation steps on the test cases in the new test case set, and when the quality of the test cases in the new test case set is lower than a preset quality threshold, the modified code test case set is used as the output result.

[0008] According to the third aspect of the present disclosure, a testing method for the software under test is also provided, comprising: using the method described in the first aspect or the second aspect of the present disclosure to obtain a test case for testing the modified code of the software under test; driving the software under test to execute the test case to test the modified code of the software under test.

[0009] According to the fourth aspect of the present disclosure, a test case generation device is also provided, including: a test execution module, used to drive the software under test to execute test cases in a pre-constructed test case set, and obtain the code of the software under test covered by the test cases, wherein the test cases are divided into a first category of test cases and a second category of test cases, and the first category of test cases covers more features of the modified code of the software under test than the second category of test cases; a case analysis module, used to analyze the code of the software under test covered by the second category of test cases, and add the second category of test cases that cover the new modified code of the software under test to the modified code test case set; a fitness calculation module, used to perform fitness calculation based on the coverage of the software under test code by the second category of test cases, and determine the first category of test cases. The excellence of the second category of test cases; a new case generation module, which is used to cross and mutate the second category of test cases with high excellence with the first category of test cases based on the value range of the characteristics of the modified code obtained in advance, so as to obtain a new test case set; an excellence judgment module, wherein the generation device performs the test execution, case analysis, and fitness calculation operations on the test cases in the new test case set, and the excellence judgment module is used to judge whether the excellence of the test cases in the new test case set is lower than a preset excellence threshold. When the excellence judgment module determines that the excellence of the test cases in the new test case set is lower than the preset excellence threshold, the modified code test case set is used as the output result.

[0010] According to a fifth aspect of the present disclosure, a device for generating test cases is also provided, comprising: a test execution module, used to drive the software under test to execute the test cases in the test case set, and obtain the code of the software under test covered by the test cases; a case analysis module, used to analyze the code of the software under test covered by the test cases, and add the test cases covering the new modified code of the software under test to the modified code test case set; a fitness calculation module, used to perform fitness calculation based on the test cases covering the code of the software under test, and determine the quality of the test cases; a new case generation module, used to cross and mutate the test cases with high quality based on the value range of the characteristics of the modified code obtained in advance, and obtain a new test case set; a quality judgment module, the generation device performs the test execution, case analysis, and fitness calculation operations on the test cases in the new test case set, the quality judgment module is used to judge whether the quality of the test cases in the new test case set is lower than a preset quality threshold, and when the quality judgment module determines that the quality of the test cases in the new test case set is lower than the preset quality threshold, the modified code test case set is used as the output result.

[0011] According to the sixth aspect of the present disclosure, a testing device for the software under test is also provided, including: a test case generation module, used to use the method described in the first aspect or the second aspect of the present disclosure to obtain a test case for testing the modified code of the software under test; a testing module, used to drive the software under test to execute the test case to test the modified code of the software under test.

[0012] According to the seventh aspect of the present disclosure, a computing device is also provided, including: a processor; and a memory on which executable code is stored, and when the executable code is executed by the processor, the processor executes the method described in the first aspect or the second aspect of the present disclosure.

[0013] According to the eighth aspect of the present disclosure, a non-temporary machine-readable storage medium is also provided, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the method described in the first aspect or the second aspect of the present disclosure.

[0014] Therefore, the present invention obtains a new test case set by multiplying a first test case with more coverage features and a second test case that does not cover as many features as the first test case but can complement the first test case as parents, and selects test cases with high excellence from the new test cases as new parents for multiplication, so that test cases for testing the modified code of the software under test can be automatically generated in a dynamic manner, and the validity of the generated test cases can be guaranteed by driving the software under test to execute the generated new test cases during the whole process. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.

[0016] Figure 1 A schematic flowchart of a method for generating a test case according to an embodiment of the present disclosure is shown.

[0017] FIG. 2A to FIG. 2C A schematic diagram of a new use case generation process according to an embodiment of the present disclosure is shown.

[0018] Figure 3 A schematic diagram showing the cross-coding of two encoded test cases is shown.

[0019] Figure 4 A schematic diagram showing the principles of a test case generation method according to an embodiment of the present disclosure is shown.

[0020] Figure 5 A schematic structural diagram of a test case generation device according to an embodiment of the present disclosure is shown.

[0021] Figure 6 A schematic structural diagram of a testing device for tested software according to an embodiment of the present disclosure is shown.

[0022] Figure 7 A schematic diagram of the structure of a computing device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0023] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0024] The present disclosure aims to analyze the code changes of the software under test, and automatically generate test cases for testing the code changes of the software under test by a dynamic method, and in the process of case generation, the validity of each generated test case can be ensured by automatically driving the software under test.

[0025] Figure 1 A schematic flowchart of a method for generating a test case according to an embodiment of the present disclosure is shown. Figure 1 The method shown can be implemented in software by a computer program or executed by a specially configured computing device. Figure 1 The method shown.

[0026] 1. Test execution steps

[0027] The software under test can be driven to execute the test cases in the pre-constructed test case set to obtain the code of the software under test covered by the test cases. The test cases in the test case set are divided into a first category of test cases and a second category of test cases, and the first category of test cases covers more features of the modified code of the software under test than the second category of test cases. As an example, the first category of test cases may refer to test cases that cover all features of the modified code of the software under test, and the second category of test cases may refer to test cases that cover some features of the modified code of the software under test.

[0028] A test case is a set of test inputs, execution conditions, and expected results compiled for a specific purpose, used to verify whether the software meets a specific requirement. By driving the software under test to execute the test cases in the pre-constructed test case set, the code coverage of each test case in the test case set can be obtained, that is, the code of the software under test covered by the test case. The code of the software under test covered by the test case refers to the code execution part of the software under test in the process of driving the software under test to execute the test case.

[0029] The modified code of the software under test refers to the part of the code that has changed compared to the previous version of the software under test, that is, the part of the code that has been updated. The features of the modified code of the software under test are the features related to the modified code. Taking the modified code as an update to an interface as an example, the features of the modified code are the features related to the interface, such as interface parameters, data types and other features. The features of the modified code have a range of values. The features of the modified code of the software under test and the range of the features can be obtained by analyzing the software under test.

[0030] Some or even all of the test cases in the test case set can be taken from existing test cases. That is, the test case set can be constructed from existing test cases. As an example, based on the characteristics of the modified code of the software under test, the first type of test cases and the second type of test cases can be obtained from the existing test case set to construct the test case set.

[0031] The test cases in the existing use case set may be the use cases that have been executed by the software under test (such as the previous version of the software under test), that is, the code of the software under test covered by the test cases in the existing use case set is known. Based on the code coverage of the test cases in the existing use case set, the use case features such as applicable scenarios and keywords, and the features of the modified code of the software under test, the coverage of the features of the modified code by the test cases in the existing use case set can be analyzed, that is, whether the test cases cover the features of the modified code of the software under test and how many features of the modified code are covered. Based on the coverage of the features of the modified code by the test cases, the test cases in the existing use case set that cover more features of the modified code of the software under test (such as covering all features) can be determined as the first category of test cases, and the other test cases in the existing use case set can be determined as the second category of test cases.

[0032] 2. Use case analysis steps

[0033] Analyze the code of the software under test covered by the second category test cases, and add the second category test cases covering the new modified code of the software under test to the modified code test case set.

[0034] In the test execution step, the code of the software under test covered by the test case in the test case set can be obtained by driving the software under test to execute the test case. The modified code of the software under test covered by the test case can be determined by comparing the code of the software under test covered by the test case with the modified code of the software under test.

[0035] A modified code test case set refers to a collection of test cases used to test the modified code of the software under test. The test cases in the modified code test case set are all test cases used to test the modified code of the software under test. In order to avoid redundant and useless test cases in the modified code test case set as much as possible, the test cases added to the modified code test case set may refer to test cases that cover the new modified code of the software under test. The new modified code is the modified code that is not covered by the test cases in the modified code test case set.

[0036] The test cases in the modified code test case set have been executed by the software under test, so the modified code covered by the test cases in the modified code test case set can be known. In the test execution step, the second type of test cases have been executed by the software under test, and the code of the software under test covered by the second type of test cases is also known. Therefore, the modified code covered by the second type of test cases can be first determined based on the modified code of the software under test and the code of the software under test covered by the second type of test cases, and then the modified code covered by the second type of test cases is compared with the modified code covered by the test cases in the modified code test case set to determine whether the second type of test cases covers the new modified code. If the new modified code is covered, the second type of test cases are added to the modified code test case set, otherwise they are not added.

[0037] As an example, when adding test cases to the modified code test case set, you can give priority to adding test cases that cover more new modified codes. For example, the first category of test cases covers more features of the modified code of the tested software than the second category of test cases. Therefore, you can give priority to selecting test cases that cover the new modified code from the first category of test cases and add them to the modified code test case set. If there are no test cases that cover the new modified code in the first category of test cases, then select test cases that cover the new modified code from the second category of test cases and add them to the modified code test case set. In this way, while the modified code test case set can achieve coverage testing of the modified code of the tested software, the number of test cases in the modified code test case set can be minimized.

[0038] 3. Fitness calculation steps

[0039] Fitness calculation is performed based on the second type of test cases covering the code of the tested software to determine the quality of the second type of test cases. The quality is used to characterize the quality of the test case as a parent in participating in reproduction. The fitness calculation step can be performed based on a preset fitness function, and the goals of the fitness calculation function include: the more the test case covers the modified code, the higher the quality; the test case covers the modified code not covered by other test cases, the higher the quality. The specific expression form of the fitness calculation function is not limited in this disclosure.

[0040] 4. Steps for generating new use cases

[0041] Based on the value range of the features of the modified code obtained in advance, the second category of test cases with high excellence are crossed and mutated with the first category of test cases to obtain a new test case set.

[0042] The new test case generation process is to use the genetic algorithm to take the second type of test cases with high quality and the first type of test cases as parents, and obtain the offspring through genetic operations such as crossover and mutation.

[0043] In the present disclosure, new test cases can be obtained through two methods: directed genetics and non-directed genetics. Directed genetics refers to crossover and mutation of the parts of the first and second test cases related to the features of the modified code; non-directed genetics refers to probability selection of the parts of the first and second test cases where crossover and mutation occur. Non-directed genetics has a probability of occurring in parts that do not belong to the features of the modified code, generating invalid test cases, so directed genetics can be preferred. When using non-directed genetics, in order to improve the efficiency of evolution, a high priority can be set for the features of the modified code to increase the probability that crossover and mutation act on the features of the modified code.

[0044] Taking directed genetics as an example, crossover may refer to the random recombination of the parts of the first and second test cases related to the features of the modified code to generate new test cases that are different from both the first and second test cases. Crossover may be a single-point crossover or a multi-point crossover. Mutation may refer to reassigning the values ​​of the features related to the modified code in the test case according to the value range of the features of the modified code. Mutation may act on the first or second test cases alone. Mutation may also be combined with a crossover operation, for example, mutation may act on the offspring obtained after the crossover operation to obtain a mutated offspring.

[0045] FIG. 2A to FIG. 2C A schematic diagram of a new use case generation process according to an embodiment of the present disclosure is shown.

[0046] like Figure 2A As shown, the first type of test cases covers the features: data1, data2, data3, parameter 1, parameter 2, and parameter 3, and the second type of test cases covers the features: data1, parameter 1, and parameter 2.

[0047] First, we can obtain the gene bit list of the first type of test case and the gene bit list of the second type of test case. The number of bits in the gene bit list is the same as the number of features, and each bit corresponds to a feature. For example, the first bit in the gene bit list corresponds to data1, the second bit corresponds to data2, the third bit corresponds to data3, the fourth bit corresponds to parameter 1, the fifth bit corresponds to parameter 2, and the sixth bit corresponds to parameter 3. The value of each bit in the gene bit list is used to characterize the value of the feature corresponding to the bit in the test case. A value of null indicates that the test case does not cover the feature corresponding to the bit.

[0048] like Figure 2BAs shown, the 3rd to 6th positions in the gene position list can be selected as the crossover positions with probability. Therefore, the values ​​of the 3rd to 6th positions in the first type of test cases can be cross-replaced with the values ​​of the corresponding positions in the second type of test cases to obtain offspring 1 and offspring 2. Offspring 1 and offspring 2 are new test cases.

[0049] like Figure 2C As shown in the figure, after obtaining offspring 1 and offspring 2, the values ​​of one or more features in the offspring can be mutated according to the value range of the features. For example, for offspring 1, a new value value10 can be obtained according to the value range of parameter 2, and value10 can replace value9 to obtain the mutated offspring 1; for offspring 2, a new value value11 can be obtained according to the value range of parameter 1, and value11 can replace value4 to obtain the mutated offspring 2.

[0050] Taking directed genetics as an example, the present disclosure can encode the test case according to the value range of the feature of the modified code, and the code of the test case consists of the first digit characters, and the code is used to characterize the value of the feature of the modified code in the test case.

[0051] Encoding a test case refers to using a code to characterize the value of the features of the modified code (i.e., the changed features) in the test case. In other words, when encoding a test case, the values ​​of the features in the test case that are not related to the modified code can be ignored, and only the values ​​of the features in the test case that are related to the modified code are encoded. The number of bits of the encoding of different test cases is the same, and each combination of values ​​of the features of the modified code should have a unique code. The encoding method can be, but is not limited to, binary encoding.

[0052] Taking binary encoding as an example, suppose that a feature A of the modified code is a Boolean variable, and the value space of the variable is "true" and "false". If the value is "false", it can be encoded as "0", and if the value is "true", it can be encoded as "1". Taking into account that a certain feature may not exist in the test case, the value space of the feature can also include null values, and the null value is used to represent that the value of the feature in the test case is empty. Therefore, when encoding the test case, if the test case does not include a certain feature of the modified code, it can be encoded as a null value. Still taking feature A as an example, if the test case does not have the value of feature A, it can be encoded as "00", if feature A exists and the value is "false", it can be encoded as "01", and if feature A exists and the value is "true", it can be encoded as "10".

[0053] The number of bits corresponding to a single feature can be set by the value space and precision requirements. Assuming that the value range of a feature is D = [a, b] and the precision requirement is d, in order to achieve this precision, D should be (ba)*10 d The number of digits m can be a minimum integer that satisfies (ba)*10 d ≤2 m -1. Thus, each value of the feature can be represented as a 0-1 string of length m. The present disclosure will not elaborate on the conversion method between the string and the actual value.

[0054] Therefore, when the second category test cases with high excellence are crossed and mutated with the first category test cases to generate new cases, one or more characters of corresponding digits in the encoding of the first category test cases and the encoding of the second category test cases can be cross-replaced; and / or the values ​​of one or more characters of digits in the encoding of the test cases can also be changed, where the test cases can be the parent generation (such as the first category test cases / the second category test cases) or the offspring (i.e., the new test cases) obtained by reproduction based on the parent generation.

[0055] like Figure 3 As shown, the values ​​of the features of the modified codes in use case 1 and use case 2 can be respectively represented as binary codes of a certain number of digits. The characters of one or more corresponding digits (such as the 2nd digit, 3rd digit, 5th digit and the second to last digit as shown in the figure) in the binary codes of use case 1 and use case 2 can be cross-replaced. Cross-replacement refers to exchanging the code value of a specific digit in use case 1 with the code value of the corresponding digit in use case 2. Optionally, before and / or after cross-replacement, the code value of one or more digits in the use case can also be mutated to change the code value.

[0056] As an example, in the new test case generation step, the test case can also be mutated based on the value range of the features with high importance in the modified code. That is, the values ​​of the features with high importance in the test case are mutated, wherein the mutated test case can be a parent test case or a child test case. In this way, the population directed evolution process can be accelerated and the evolution efficiency can be improved.

[0057] The test case set can be regarded as the initial population, and the new test case set obtained according to the new case generation step can be regarded as the new population obtained by directed inheritance of the initial population. As an example, the second type of test cases with high quality can also be added to the new test case set, so that the reproduction rights of excellent individuals can be retained based on the elite retention strategy to improve the breeding effect of future generations. Among them, the features covered by the first type of test cases are higher than those of the second type of test cases, so the first type of test cases can also be added to the new test case set as excellent individuals.

[0058] For the test cases in the new test case set, the above steps of test execution, case analysis, and fitness calculation can be performed. When the above steps are performed on the test cases in the new test case set, the first type of test case set and the second type of test case are no longer distinguished. That is, the first type of test case and the second type of test case in the above steps are just two test cases in the new test case set.

[0059] Specifically, in the test execution step: drive the software under test to execute the test cases in the new test case set, and obtain the code of the software under test covered by the test cases; in the case analysis step: analyze the code of the software under test covered by the test cases in the new test case set, and add the test cases covering the new modified code of the software under test to the modified code test case set; in the fitness calculation step: perform fitness calculation based on the test cases in the new test case set covering the code of the software under test, and determine the quality of the test cases; new case generation step: based on the value range of the features of the modified code obtained in advance, cross and mutate the test case pairs with high quality to obtain a new test case set. For details about each step, please refer to the relevant description above.

[0060] After obtaining a new test case set, it can be determined whether the quality of the test cases in the new test case set is lower than a preset quality threshold. When the quality of the test cases in the new test case set is lower than the preset quality threshold, the modified code test case set is used as the output result. Optionally, when the quality of the test cases in the new test case set obtained N times in a row are all lower than the preset quality threshold, the modified code test case set is used as the output result. The output result can be provided to the user (such as a tester), and the user implements coverage testing of the modified code based on the test cases in the modified code test case set.

[0061] As an example, in the process of iterative reproduction based on a new set of test cases, the reproduction rights of test cases with high excellence in each generation can be retained, thereby improving the breeding effect of future generations.

[0062] Figure 4 A schematic diagram showing the principles of a test case generation method according to an embodiment of the present disclosure is shown.

[0063] 1. Construction of the initial population

[0064] Analyze the existing use case library and extract the features covered by the use cases. The features may include: applicable scenarios, keywords, code coverage, etc.

[0065] Analyze the modified code of the software under test, extract the features related to the modified code (ie, the change features), and determine the value range of the change features based on the feature analysis.

[0066] According to the features and changing features covered by the use cases, determine the queen bee seed in the existing use case library (corresponding to the existing use case library set mentioned above) or the queen bee seed set consisting of multiple queen bee seeds. Among them, the queen bee seed corresponds to the first type of test case mentioned above, which refers to the use case that covers as many (such as all) changing features as possible, and extracts other use cases in the use case set (corresponding to the second type of test case mentioned above). The other use cases cover fewer changing features than the queen bee seed, and together with the queen bee seed or the queen bee seed set, they are used as the initial population. The initial population is also the pre-constructed test case set mentioned above.

[0067] 2. Cultivation

[0068] Cultivate the changed features to obtain a new population (i.e., a new set of test cases).

[0069] The cultivation process is as follows:

[0070] 2.1 Perceiving Code Coverage

[0071] Drive the software under test to execute the test cases in the initial population, and collect the code of the software under test covered by the execution of each test case.

[0072] 2.2 Fitness Function

[0073] The fitness function refers to the standard used to distinguish the good and bad individuals in a group determined according to the objective function, so as to select the best and the worst for the test case individuals. The fitness calculation can be performed based on the code covered by the test case to determine the quality of the test cases of non-queen seeds (i.e., the second type of test cases). In the present disclosure, the fitness function has two core goals: first, to cover as much modified code as possible; second, to cover as much new modified code as possible that has not been covered by existing test cases.

[0074] The test cases that cover the new code changes of the tested software can be added to the modified function test case set. The modified function test case set is also the modified code test case set mentioned above.

[0075] 2.3 Use Case Extraction

[0076] Test cases with high quality (second type of test cases) are extracted and reproduced with queen bee seeds (first type of test cases) to produce a new generation of population. The new generation of population is also the new test case set mentioned above. The reproduction process corresponds to the new case generation step mentioned above. For the implementation of the reproduction process, please refer to the description of the new case generation step above, which will not be repeated here. Queen bee seeds and test cases with high quality can be added to the new population (i.e., the new test case set) as excellent individuals to retain the reproduction rights of excellent individuals, thereby improving the breeding effect of future generations.

[0077] 3. Iterative reproduction

[0078] A new generation of population (i.e., a new set of test cases) can be cultivated iteratively. In the reproduction process of the new population, queen bee seeds are no longer distinguished, but the same generation population is cultivated and reproduced.

[0079] After each round of iterative reproduction, it is determined whether the algorithm stopping condition is reached. The algorithm stopping condition can be set to when the quality of all use cases in the new generation population is lower than a certain threshold, then the algorithm ends. After the algorithm ends, the set of test cases for the changed functions is provided to the user as the final generated result.

[0080] As an example, in the process of cultivation (propagation), the present disclosure can focus on the changed functions of the tested software, and improve the generation efficiency of test cases for the modified code of the tested software by targeted cultivation of the features of the modified code, and automatically generate effective test cases for the modified code, without redundancy in the generated results, and without manual intervention in the effectiveness. Therefore, the present disclosure is particularly suitable for daily iterative testing of software.

[0081] The present disclosure also proposes a method for generating test cases, including: a test execution step: driving the software under test to execute the test cases in the test case set, and obtaining the code of the software under test covered by the test cases; a test case analysis step: analyzing the code of the software under test covered by the test cases, and adding the test cases that cover the new modified code of the software under test to the modified code test case set; a fitness calculation step: performing fitness calculation based on the test cases covering the code of the software under test, and determining the quality of the test cases; a new test case generation step: based on the value range of the features of the modified code obtained in advance, crossover and mutation of the test cases with high quality to obtain a new test case set; performing the test execution, case analysis, and fitness calculation steps on the test cases in the new test case set, and when the quality of the test cases in the new test case set is lower than the preset quality threshold, the modified code test case set is used as the output result. In this embodiment, the test cases in the test case set can be taken from existing test cases, that is, the test case set can be constructed based on the existing test cases, and the constructed test case set can be regarded as the initial population, combined with the above Figure 1 The difference between the described embodiments is that the test cases in the test case set in this embodiment may not distinguish between the first type of test cases and the second type of test cases, such as test cases that cover more features. For details of each step, please refer to the above description, which will not be repeated here.

[0082] The present disclosure also proposes a testing method for the software under test, including: using the test case generation method of the present disclosure to obtain a test case for testing the modified code of the software under test; driving the software under test to execute the test case to test the modified code of the software under test.

[0083] The test case generation method disclosed in the present invention may also be implemented as a test case generation device. Figure 5 The structure diagram of the test case generation device according to an embodiment of the present disclosure is shown. The functional modules of the generation device 500 can be implemented by hardware, software or a combination of hardware and software that implements the principles of the present invention. It can be understood by those skilled in the art that Figure 5 The functional modules described can be combined or divided into sub-modules to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional modules described herein.

[0084] The following is a brief description of the functional modules that the generating device 500 may have and the operations that each functional module may perform. For the details involved, please refer to the relevant description above and will not be repeated here.

[0085] See also Figure 5 The test case generation device 500 includes a test execution module 510, a case analysis module 520, a fitness calculation module 530, a new case generation module 540 and a quality judgment module 550.

[0086] In one embodiment of the present disclosure, the test execution module 510 is used to drive the software under test to execute the test cases in the pre-constructed test case set, and obtain the code of the software under test covered by the test cases, wherein the test cases are divided into the first category of test cases and the second category of test cases, and the first category of test cases covers more features of the modified code of the software under test than the second category of test cases. For the operations that the test execution module 510 can perform and the related details, please refer to the description of the test execution steps above.

[0087] The use case analysis module 520 is used to analyze the code of the tested software covered by the second type of test cases, and add the second type of test cases covering the new modified code of the tested software to the modified code test case set. For the operations that the use case analysis module 520 can perform and the related details, please refer to the description of the use case analysis step above.

[0088] The fitness calculation module 530 is used to perform fitness calculation based on the second type of test cases covering the code of the tested software, and determine the quality of the second type of test cases. For the operations that the fitness calculation module 530 can perform and the related details, please refer to the description of the fitness calculation steps above.

[0089] The new test case generation module 540 is used to cross and mutate the second type of test cases with high quality with the first type of test cases based on the value range of the feature of the modified code obtained in advance, so as to obtain a new test case set. For the operations that can be performed by the new test case generation module 540 and related details, please refer to the description of the new test case generation step above.

[0090] The test case generation device 500 can use the test execution module 510, the case analysis module 520, the fitness calculation module 530, and the new case generation module 540 to perform the test execution, case analysis, and fitness calculation operations on the test cases in the new test case set.

[0091] After obtaining a new test case set each time, the quality judgment module 550 can determine whether the quality of the test cases in the new test case set is lower than the preset quality threshold. When the quality judgment module 550 determines that the quality of the test cases in the new test case set is lower than the preset quality threshold, the modified code test case set can be used as the output result.

[0092] In another embodiment of the present disclosure, the test execution module 510 is used to drive the software under test to execute the test cases in the test case set, and obtain the code of the software under test covered by the test cases. Different from the above embodiment, the test cases in the test case set in this embodiment may not distinguish between the first type of test cases and the second type of test cases. The case analysis module 520 is used to analyze the code of the software under test covered by the test cases, and add the test cases covering the new modified code of the software under test to the modified code test case set. The fitness calculation module 530 is used to perform fitness calculation based on the test case coverage of the code of the software under test to determine the quality of the test case; the new case generation module 540 is used to cross and mutate the test cases with high quality based on the value range of the feature of the modified code obtained in advance, and obtain a new test case set. The test case generation device 500 can use the test execution module 510, the case analysis module 520, the fitness calculation module 530, and the new case generation module 540 to perform the test execution, case analysis, and fitness calculation operations on the test cases in the new test case set. After obtaining a new test case set each time, the quality judgment module 550 can determine whether the quality of the test cases in the new test case set is lower than the preset quality threshold. When the quality judgment module 550 determines that the quality of the test cases in the new test case set is lower than the preset quality threshold, the modified code test case set can be used as the output result.

[0093] The tested software testing method disclosed in the present invention may also be implemented as a tested software testing device. Figure 6The structure diagram of the testing device of the tested software according to one embodiment of the present disclosure is shown. Among them, the functional modules of the testing device 600 of the tested software can be implemented by hardware, software or a combination of hardware and software that implements the principles of the present invention. It can be understood by those skilled in the art that Figure 6 The functional modules described can be combined or divided into sub-modules to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional modules described herein.

[0094] The following briefly describes the functional modules that the testing device 600 for the tested software may have and the operations that each functional module may perform. For the details involved, please refer to the relevant description above and will not be repeated here.

[0095] See also Figure 6 The testing device 600 of the tested software includes a test case generating module 610 and a testing module 620 .

[0096] The test case generation module 610 is used to use the test case generation method described in the present disclosure to obtain a test case for testing the modified code of the tested software. The functional modules that the test case generation module 610 may include can be seen in the above combined Figure 5 Description of the test case generation device: That is, the test case generation module 610 can be equivalent to the test case generation device mentioned above.

[0097] The testing module 620 is used to drive the software under test to execute test cases to test the modified code of the software under test.

[0098] Figure 7 A schematic diagram of the structure of a computing device that can be used to implement the above-mentioned test case generation method or tested software testing method according to an embodiment of the present disclosure is shown.

[0099] See also Figure 7 , the computing device 700 includes a memory 710 and a processor 720 .

[0100] The processor 720 may be a multi-core processor or may include multiple processors. In some embodiments, the processor 720 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, the processor 720 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).

[0101] The memory 710 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 720 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 710 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 710 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (e.g., DVD-ROM, double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.

[0102] The memory 710 stores executable codes. When the executable codes are processed by the processor 720, the processor 720 can execute the test case generation method or the test method of the tested software mentioned above.

[0103] The test case generation method, the tested software testing method, the test case generation device, the tested software testing device and the computing device according to the present disclosure have been described in detail above with reference to the accompanying drawings.

[0104] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present invention.

[0105] Alternatively, the present invention may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present invention.

[0106] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.

[0107] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0108] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terms used herein are selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A method for generating a test case, comprising: Test execution step: driving the software under test to execute test cases in a pre-constructed test case set to obtain the code of the software under test covered by the test cases, wherein the test cases are divided into a first category of test cases and a second category of test cases, and the first category of test cases covers more features of the modified code of the software under test than the second category of test cases; Use case analysis step: Analyze the code of the software under test covered by the second type of test cases, and add the second type of test cases that cover the new modified code of the software under test to the modified code test case set; Fitness calculation step: Perform fitness calculation based on the second type of test cases covering the code of the tested software to determine the quality of the second type of test cases; New test case generation step: based on the pre-obtained value range of the feature of the modified code, cross and mutate the second type of test cases with relatively high excellence with the first type of test cases to obtain a new test case set; The test execution, case analysis, and fitness calculation steps are performed on the test cases in the new test case set. When the quality of the test cases in the new test case set is lower than a preset quality threshold, the modified code test case set is used as the output result.

2. The method of claim 1, wherein: Also includes: The second type of test cases with relatively high excellence are added to the new test case set.

3. The method of claim 2, wherein: The fitness calculation step is performed based on a preset fitness function, wherein the objectives of the fitness calculation function include: the more modified codes are covered by the test cases, the higher the quality is; the more modified codes are covered by the test cases that are not covered by other test cases, the higher the quality is.

4. The method of claim 2, wherein: In the new test case generation step, the test cases are mutated based on the value ranges of relatively more important features in the modified code.

5. The method according to any one of claims 1 to 4, wherein: Also includes: Analyze the software under test to obtain the characteristics of the modified code of the software under test and the value range of the characteristics.

6. The method according to any one of claims 1 to 4, wherein: Also includes: Based on the characteristics of the modified code of the software under test, the first category of test cases and the second category of test cases are obtained from the existing use case set, and the software under test has executed the use cases in the existing use case library.

7. A software testing method, comprising: Using the method of any one of claims 1 to 6, obtaining a test case for testing the modified code of the software under test; The software under test is driven to execute the test case to test the modified code of the software under test.

8. A test case generation device, comprising: A test execution module is used to drive the software under test to execute test cases in a pre-constructed test case set, and obtain the code of the software under test covered by the test cases, wherein the test cases are divided into a first category of test cases and a second category of test cases, and the first category of test cases covers more features of the modified code of the software under test than the second category of test cases; A use case analysis module is used to analyze the code of the tested software covered by the second type of test cases, and add the second type of test cases covering the new modified code of the tested software to the modified code test case set; A fitness calculation module, used to perform fitness calculation based on the second type of test cases covering the code of the tested software, and determine the quality of the second type of test cases; A new case generation module is used to cross and mutate the second type of test cases with relatively high quality with the first type of test cases based on the value range of the characteristics of the modified code obtained in advance, to obtain a new test case set as the input of the test execution module, until the quality judgment module determines that the quality of the test cases in the new test case set output by the fitness calculation module is lower than the preset quality threshold, and then use the modified code test case set as the output result.

9. A testing device for tested software, comprising: A test case generation module, used to obtain a test case for testing the modified code of the software under test using the method described in any one of claims 1 to 6; The test module is used to drive the software under test to execute the test case to test the modified code of the software under test.

10. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 7.

11. A cloud server having executable codes deployed thereon, which, when executed by a processor of the cloud server, cause the processor to execute the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Test case precise recommendation method, device and system, equipment and storage medium

    CN107515826A

  • Combination accelerated test case generation method based on genetic method and symbol execution

    CN109344057A