CN113778865A - Self-adaptive random generation method for test case of metamorphic test - Google Patents
Self-adaptive random generation method for test case of metamorphic test Download PDFInfo
- Publication number
- CN113778865A CN113778865A CN202110994979.9A CN202110994979A CN113778865A CN 113778865 A CN113778865 A CN 113778865A CN 202110994979 A CN202110994979 A CN 202110994979A CN 113778865 A CN113778865 A CN 113778865A
- Authority
- CN
- China
- Prior art keywords
- input
- test
- mtc
- metamorphic
- test case
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Test And Diagnosis Of Digital Computers (AREA)
Abstract
A self-adaptive generation method for a test case of metamorphic testing comprises the following steps: (1) initializing; (2) checking whether all partitions of all parameters are covered; (3) selecting uncovered partitions, and randomly generating a metamorphic test case set; (4) calculating the distance between the initial input and the subsequent input; (5) taking a group of metamorphic test inputs with the largest distance as candidate inputs; (6) calculating an anomaly score for the candidate input relative to the result set; (7) and (5) removing the candidate input with the abnormal score smaller than the threshold value, if the candidate input set is empty, returning to the step (3), and if not, returning to the step (2). The invention supports metamorphic testing, and automatically generates a test case until all input partitions at least contain one test input; the method supports the difference measurement of initial test input and subsequent test input, supports the difference measurement of test input and result set, and improves the possibility of finding defects and supports small data sets, and the measurement result is not influenced by parameter dimension.
Description
Technical Field
The invention relates to a self-adaptive random generation method of a test case, in particular to a self-adaptive random generation method of a test case of metamorphic testing.
Background
Scientific calculation and industrial design software such as numerical simulation nuclear design and safety analysis software, aeronautical engine dynamic design simulation software and the like are adopted, and the problem that an expected result is difficult to construct or the construction cost is extremely high generally exists because complicated partial differential equations need to be solved and no analytic solution exists, so that the problem is called the Oracle problem of software testing. The traditional test method verifies the tested program by directly comparing an actual result with an expected result, so that the Oracle problem makes it difficult to implement sufficient test on the software, the sufficient test is lacked, and the software quality is difficult to ensure.
Metamorphic Testing (MT) is one of the currently accepted effective methods for solving the Oracle problem, and it indirectly performs verification by examining whether Metamorphic Relations (MR) are satisfied between input and output when a program is executed multiple times. For example, assuming that the program under test p implements the sine function sin, the relationship given by the periodic, available degeneracy of sin: sin (x) ═ sin (x +2 pi), a random value x1 is generated as an initial Test Case (Source Test Case, STC), x2 is derived from x1+2 pi as a subsequent Test Case (Follow-up Test Case, FTC), p (x1) is compared with p (x2), if equal, p passes the Test, otherwise p fails the Test.
The Metamorphic Test Case (MTC) is composed of a group of Test cases (STC, FTC), when the Metamorphic relation is a binary relation, the MTC comprises an STC and an FTC, when the Metamorphic relation is an n-element relation, the MTC comprises an STC and n-1 FTCs, and obviously, the execution times of Metamorphic tests are higher than those of the traditional Test method. In order to reduce the testing cost and improve the testing effectiveness, it is very important to select a test case with higher possibility of identifying defects.
Research shows that the software defect distribution has aggregation, and three types of software defect distribution modes under a two-dimensional input domain are shown in the attached figure 1.
If a test case does not find a defect, then a test case that is far away from it will be easier to detect a defect than a nearby test case. Therefore, the most important problem of the test case generation method is to keep the test case difference as much as possible.
The test case generation method mainly comprises a special value method and a random value method, wherein the special value method needs the tester to have richer field knowledge of the tested software, and the random value method does not depend on prior knowledge and is widely applied to metamorphic testing, but the test coverage rate cannot be effectively improved.
An Adaptive Random Testing (ART) is inspired by a defect distribution mode, and a candidate test case which is the largest distance from an executed test case is selected from randomly generated test input. However, this method has three disadvantages: (1) the existing self-adaptive random generation method does not support the difference measurement of the structure; (2) for a program with multiple input parameters (high-dimensional input), the distance calculation amount is large; (3) when there is a large difference in the dimension of the input parameter, the calculation result based on the distance or density depends on the parameter with a large value, such as n-dimensional input { x1, x2, …, xn }, and the value ranges of x1 and x2 are (0,1) (-100,10000), respectively, then the influence of x2 on the distance is significantly greater than that of x1, and is easily influenced by the dimension of the input parameter.
Disclosure of Invention
The invention aims to solve the technical problem of overcoming the defects of the prior art and provide a test case self-adaptive random generation method which has a wide application range and supports metamorphic testing without being influenced by dimensions.
The technical scheme adopted by the invention for solving the technical problem is that the self-adaptive random generation method of the test case of the metamorphic test comprises the following steps:
the method comprises the following steps: initialization: the method comprises the steps of firstly analyzing an input field according to a design document of the tested program, identifying an equivalence class, dividing the input field into n disjoint areas according to the equivalence class, wherein the input field is divided into n disjoint areas according to the equivalence class, for example, the input X consisting of n parameters is { X1, X2.., xn }, and the input field of X1 is [0,100 []Are divided into [0,20 ], [20,50 ], [50,100]Three areas, other input parameters and so on, initializing result set CRTC(Result Test Case, RTC), if there is an executed Test Case, copy to CRTCOtherwise, randomly generating a batch of input C according to the input fieldRTC;
Step two: check if all partitions for all parameters have been covered: stopping the generation process if all the partitions of all the input parameters of the program under test are covered by at least one test input, and outputting CRTCOtherwise, executing the next step;
step three: selecting uncovered partitions, and randomly generating a metamorphic test case set: randomly generating k MTC, and establishing an MTC set CMTC;
Step four: calculating the distance of the initial input from the subsequent input: calculating CMTCThe distance D between the STC of each MTC and the FTCsf;
Step five: taking a group of MTC with the largest distance as a candidate test input set CCTC(Candidate Test Case,CTC);
Step six: computing each MTC relative result set C using an isolated forest algorithmRTCIs given an abnormality score SA(Anomaly Score);
Step seven: from CCTCRemoving MTC with score less than threshold when if CCTCIf the test result is null, returning to the step three, otherwise inputting the candidate testCCTCPut into result set CRTCAnd returning to the step two.
Further, in the third step, the method for establishing the metamorphic test case set comprises the following steps: randomly selecting one partition from each input parameter to generate an initial Test input (Source Test Case, STC), obtaining a subsequent Test input (Follow-up Test Case, FTC) according to a Metamorphic relation, forming a Metamorphic Test Case (MTC) by the two, and so on.
Further, in the fourth step, the distance D is calculatedsfThe formula of (1) is:where n is the number of input parameters and i is the input parameter number.
Further, in the sixth step, an abnormality score S is calculatedAThe formula of (1) is:wherein x is MTC, using CRTCConstructing an orphan forest as a training set, h (x) is the height of x in the orphan tree, E (h (x)) is the average of h (x), C (n) is CRTCThe average height of the isolated tree when the test input equals n, for normalizing h (x), SAA closer to 1 indicates a larger degree of abnormality.
The invention has the following positive effects:
(1) supporting metamorphic testing, and automatically generating test cases until all the input domain partitions are covered by at least one test case;
(2) supporting the difference measurement of metamorphic test cases, using the distance D between STC and FTCsfThe difference degree of a single MTC is expressed, the fact that most of the MTC is binary MR and only comprises one FTC is considered, so that the calculation cost is low, and only two test cases participate in calculation, so that the dimension influence is low;
(3) supporting the difference measurement of the test cases relative to the result set, and measuring the candidate metamorphic test cases relative to the result set C by adopting the abnormal score of the isolated forest algorithmRTCThe method calculates the complexThe complexity is O (n), the method has linear time complexity, high speed in processing high-dimensional data and low memory consumption, and is commonly used for network attack detection, financial transaction fraud detection and the like;
(4) calculating candidate test input and result set C without influence of input parameter dimensionRTCWhen the difference is different, a distance or density-based method is not used, so the method is not influenced by the dimension;
(5) the probability of finding the defects is improved, through two rounds of difference measurement, test inputs with obvious differences are automatically selected on the basis of a random value method, and according to a defect distribution model, the test inputs have higher probability of finding the defects;
(6) the method supports small data sets, and due to the cost, the number of test cases, especially metamorphic tests, is expected to be reduced as much as possible on the premise of keeping the error detection capability, so that a result set is most likely to be the small data sets, and researches show that the detection effect of the isolated forest algorithm on the small data sets is better.
Drawings
FIG. 1 is a schematic diagram of three types of software defect patterns in software engineering practice;
FIG. 2 is a flow chart of an embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples.
With reference to fig. 2, taking the sine function sin as an example, the implementation comprises the following steps,
(1) initialization: suppose that the field 0,2 pi is to be input]Is divided into [0,1 ]]、(1,π]、(π,5]、(5,2π]Assuming no executed test cases exist, randomly generating a batch of input C according to the input fieldRTC=Random(0,2π,10)={π/3,2,3,...,5π/3};
(2) Check if all partitions for all parameters have been covered: if all the partitions of all the parameters at least comprise one test case, stopping the test if the detection result is true, and otherwise, executing the next step;
(3) selecting uncovered partitions, and randomly generating a metamorphic test case set: in [0,1 ]]Interval random generation of 10 initial test inputs CSTCTransmutation relation MR periodically obtained from sin (0,1,10) {0.1,0.21:x2=x1+2π,sin(x2)=sin(x1) Generating a subsequent test input CFTC={Cstc+2 pi } - {0.1+2 pi, 0.2+2 pi, · 1+2 pi }, both of which constitute CMTC{ (0.1,0.1+2 pi), (0.2,0.2+2 pi),. ·, (1,1+2 pi) }, and so on for other partitions;
(4) calculating the distance of the initial input from the subsequent input: calculating CMTCDistance of STC to FTC, D, of each MTC insf(MTC1)=√(0.1-(0.1+2π))22 pi, and so on for other MTC;
(5) taking a group of MTC with the largest distance as a candidate test input set CCTCAssuming that the number of elements is taken to be 3, then from CMTCGet DsfMaximum 3 MTC Components CCTC={MTC1,MTC2,MTC3};
(6) Computing each MTC relative result set C using an isolated forest algorithmRTCIs given an abnormality score SAIs provided with SA(MTC1)=0.98,SA(MTC2)=0.50,SA(MTC1)=0.43;
(7) From CCTCRemoving MTC with score less than threshold, assuming abnormal score threshold of 0.85, removing C after MTCCTC={MTC1},CCTCNot null, input candidate test CCTCPut into result set CRTCAnd returning to the step 2, otherwise, returning to the step 3.
The embodiment can embody the difference between the initial input and a plurality of subsequent inputs in the metamorphic test case; evaluating the difference between the candidate test cases and the executed test case set by using an isolated forest anomaly detection algorithm; the calculation complexity is reduced to linear complexity, and the method has engineering practicability.
Various modifications and variations of the present invention may be made by those skilled in the art, and they are still within the scope of the present patent invention provided they are within the scope of the claims and their equivalents.
What is not described in detail in the specification is prior art that is well known to those skilled in the art.
Claims (4)
1. A self-adaptive random generation method for a test case of metamorphic testing is characterized by comprising the following steps:
the method comprises the following steps: initialization: firstly, analyzing an input field according to a design document of the tested program, identifying an equivalence class, dividing the input field into n disjoint areas according to the equivalence class, wherein an input X formed by n parameters is { X1, X2, …, xn }, and an input field of X1 is [0,100 }, and each parameter has different value ranges]Are divided into [0,20 ], [20,50 ], [50,100]Three areas, other input parameters and so on, initializing result set CRTC(Result Test Case, RTC), if there is an executed Test Case, copy to CRTCOtherwise, randomly generating a batch of input C according to the input fieldRTC;
Step two: check if all partitions for all parameters have been covered: stopping the generation process if all the partitions of all the input parameters of the program under test are covered by at least one test input, and outputting CRTCOtherwise, executing the next step;
step three: selecting uncovered partitions, and randomly generating a metamorphic test case set: randomly generating k MTC, and establishing an MTC set CMTC;
Step four: calculating the distance of the initial input from the subsequent input: calculating CMTCThe distance D between the STC of each MTC and the FTCsf;
Step five: taking a group of MTC with the largest distance as a candidate test input set CCTC(Candidate Test Case,CTC);
Step six: computing each MTC relative result set C using an isolated forest algorithmRTCIs given an abnormality score SA(Anomaly Score);
Step seven: from CCTCRemoving MTC with score less than threshold when if CCTCIf the test result is empty, returning to the step three, otherwise inputting the candidate test into the test CCTCPut into result set CRTCReturn stepAnd step two.
2. The method of claim 1, wherein the method comprises: in the third step, the method for establishing the candidate metamorphic test case set comprises the following steps: randomly selecting one partition from each input parameter to generate an initial Test input (Source Test Case, STC), obtaining a subsequent Test input (Follow-up Test Case, FTC) according to a Metamorphic relation, forming a Metamorphic Test Case (MTC) by the two, and so on.
4. The method for adaptively and randomly generating test cases for metamorphic testing according to claim 1 or 2, wherein: in the sixth step, an abnormality score S is calculatedAThe formula of (1) is:wherein x is MTC, using CRTCConstructing an orphan forest as a training set, h (x) is the height of x in the orphan tree, E (h (x)) is the average of h (x), C (n) is CRTCThe average height of the isolated tree when the test input equals n, for normalizing h (x), SAA closer to 1 indicates a larger degree of abnormality.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110994979.9A CN113778865B (en) | 2021-08-27 | 2021-08-27 | Test case self-adaptive random generation method for metamorphic test |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110994979.9A CN113778865B (en) | 2021-08-27 | 2021-08-27 | Test case self-adaptive random generation method for metamorphic test |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113778865A true CN113778865A (en) | 2021-12-10 |
CN113778865B CN113778865B (en) | 2023-07-18 |
Family
ID=78839832
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110994979.9A Active CN113778865B (en) | 2021-08-27 | 2021-08-27 | Test case self-adaptive random generation method for metamorphic test |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113778865B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117056203A (en) * | 2023-07-11 | 2023-11-14 | 南华大学 | Numerical expression type metamorphic relation selection method based on complexity |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104572462A (en) * | 2014-12-31 | 2015-04-29 | 中国人民解放军理工大学 | Method for generating metamorphic test case based on adaptive random strategy |
CN104598381A (en) * | 2015-01-26 | 2015-05-06 | 中国人民解放军理工大学 | Positioning method for failure test instance in metamorphic testing |
CN110823226A (en) * | 2019-10-30 | 2020-02-21 | 北京航空航天大学 | Unmanned aerial vehicle intelligent route planning test method based on metamorphic test technology |
CN111124896A (en) * | 2019-12-06 | 2020-05-08 | 北京京航计算通讯研究所 | Metamorphic test system for primary and secondary peak ratio calculation algorithm |
CN111830935A (en) * | 2020-07-23 | 2020-10-27 | 深圳慕智科技有限公司 | Metamorphic test method for automatic driving system |
-
2021
- 2021-08-27 CN CN202110994979.9A patent/CN113778865B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104572462A (en) * | 2014-12-31 | 2015-04-29 | 中国人民解放军理工大学 | Method for generating metamorphic test case based on adaptive random strategy |
CN104598381A (en) * | 2015-01-26 | 2015-05-06 | 中国人民解放军理工大学 | Positioning method for failure test instance in metamorphic testing |
CN110823226A (en) * | 2019-10-30 | 2020-02-21 | 北京航空航天大学 | Unmanned aerial vehicle intelligent route planning test method based on metamorphic test technology |
CN111124896A (en) * | 2019-12-06 | 2020-05-08 | 北京京航计算通讯研究所 | Metamorphic test system for primary and secondary peak ratio calculation algorithm |
CN111830935A (en) * | 2020-07-23 | 2020-10-27 | 深圳慕智科技有限公司 | Metamorphic test method for automatic driving system |
Non-Patent Citations (1)
Title |
---|
董国伟;聂长海;徐宝文;: "基于程序路径分析的有效蜕变测试", 计算机学报, no. 05 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117056203A (en) * | 2023-07-11 | 2023-11-14 | 南华大学 | Numerical expression type metamorphic relation selection method based on complexity |
CN117056203B (en) * | 2023-07-11 | 2024-04-09 | 南华大学 | Numerical expression type metamorphic relation selection method based on complexity |
Also Published As
Publication number | Publication date |
---|---|
CN113778865B (en) | 2023-07-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Gong et al. | Evolutionary generation of test data for many paths coverage based on grouping | |
CN111026664B (en) | Program detection method and detection system based on ANN and application | |
Li et al. | Mixed variables‐attributes test plans for single and double acceptance sampling under exponential distribution | |
Kumar et al. | An empirical analysis on web service anti-pattern detection using a machine learning framework | |
Grbac et al. | Stability of software defect prediction in relation to levels of data imbalance | |
Milroy et al. | Towards characterizing the variability of statistically consistent Community Earth System Model simulations | |
Zhang et al. | Autoregressive mediation models using composite scores and latent variables: Comparisons and recommendations. | |
Dulá et al. | DEA with streaming data | |
CN113778865B (en) | Test case self-adaptive random generation method for metamorphic test | |
CN115859805A (en) | Self-adaptive sequential test design method and device based on mixed point adding criterion | |
Hamarashid | Utilizing statistical tests for comparing machine learning algorithms | |
Xiao et al. | Adaptive testing based on moment estimation | |
Nishiura et al. | Improving faulty interaction localization using logistic regression | |
Grentzelos et al. | A comparative study of methods to handle outliers in multivariate data analysis | |
Rieck et al. | Structural analysis of multivariate point clouds using simplicial chains | |
Rönkkö et al. | Construct validity in partial least squares path modeling | |
CN111859799A (en) | Method and device for evaluating data accuracy based on complex electromechanical system coupling relation model | |
Martinez Villanueva et al. | clustcurv: an R package for determining groups in multiple curves | |
Huang et al. | Improving random test sets using a locally spreading approach | |
US11515995B2 (en) | Efficient computation of univariate statistical moments for side channel vulnerability evaluation | |
Patel et al. | A partial oracle for uniformity statistics | |
TW202001246A (en) | Method for detecting drug resistance of microorganism | |
Qu et al. | A method to improve Ripley's function to analyze spatial pattern by factor analysis | |
Gaol et al. | Software testing model by measuring the level of accuracy fault output using neural network algorithm | |
CN114154310B (en) | DMPA credibility evaluation method and device of combat simulation system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |