Method, device and storage medium for automatic generation of transmutation relationships based on templated combinatorial space
By constructing a templated metamorphic relation basic combination space and a combination generation strategy, candidate metamorphic relations are automatically evaluated, solving the problems of limited range of metamorphic relation generation and insufficient automation in the existing technology, and realizing efficient and automated generation and testing of metamorphic relations.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING UNIV
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-19
AI Technical Summary
Existing methods for generating metamorphic relations impose strong constraints on the form or generation process, resulting in a limited range of types and scope of metamorphic relations that can be generated, restricting applicable problem scenarios. Furthermore, they lack sufficient automation and require manual verification or correction, affecting efficiency and practicality.
A basic combinatorial space of templated metamorphic relations is constructed. By combining forward and reverse generation strategies, candidate metamorphic relations are generated through the input transformation space and the output relation space. The relations are then automatically evaluated and screened, and the generation strategy ratio is adjusted to generate effective metamorphic relations that meet the quality requirements.
This approach achieves a reduction in human intervention while expanding the scope of metamorphic relation generation, increasing automation, and generating reliable metamorphic relations for target program testing.
Smart Images

Figure CN122240470A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software testing technology, and specifically to a method, device, and storage medium for automatically generating metamorphic relationships based on a templated composition space. Background Technology
[0002] Metamorphic testing is a commonly used software testing technique that verifies program behavior by utilizing the relationships that a program should satisfy between multiple related inputs and their corresponding outputs. In metamorphic testing, metamorphic relations (MR) are the core elements for generating test cases and verifying test results. A metamorphic relation refers to a relationship that should be maintained between inputs and outputs under specific conditions. This relationship is typically used to verify whether the output of software or a model is consistent under different inputs, especially when the expected output is difficult to determine. The core of metamorphic relations lies in determining whether software defects exist through multiple pairs of input-output relationships. The quantity and quality of metamorphic relations directly affect the effectiveness of metamorphic testing.
[0003] To reduce the cost of manually constructing metamorphic relations and improve testing automation, various methods have been proposed to assist in generating metamorphic relations, exploring a degree of automation in the construction process. However, in practical applications, existing methods typically impose strong constraints on the form or generation process of metamorphic relations, resulting in a limited range of generated relation types and restricting applicable problem scenarios. Furthermore, existing metamorphic relation generation methods still suffer from insufficient automation; some methods still rely on human experience or pre-defined rules to guide the generation process, and the consistency and reliability of the generated results are difficult to guarantee. Manual verification or correction of the results is often required, thus impacting the efficiency and practicality of metamorphic relation generation.
[0004] Therefore, how to expand the spatial range of metamorphic relationships that can be generated while reducing the degree of human intervention, and how to achieve more universal and automated generation of metamorphic relationships while ensuring the quality of generation, remains a technical problem that urgently needs to be solved in the field of metamorphic testing. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention provides a method, device, and storage medium for automatically generating metamorphic relationships based on a templated combination space.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] An automatic generation method for metamorphic relations based on a templated combinatorial space includes: Construct a basic combinatorial space for templated metamorphic relationships; The problem description of the target problem is preprocessed to generate a formal problem definition; Within the basic combinatorial space of metamorphic relations, candidate metamorphic relations are generated based on the formal problem definition, combining forward and reverse generation strategies. The candidate metamorphic relations are automatically evaluated and screened to obtain valid metamorphic relations, and the usage ratio of forward and reverse generation strategies is adjusted based on the evaluation results. An executable test program is generated based on an effective metamorphic relationship to test the target program.
[0008] To optimize the above technical solution, the specific measures also include: Furthermore, the basic combination space of the transformation relationship is composed of an input transformation space and an output relationship space. The input transformation space is used to describe the feasible ways to transform the input parameters, and the output relationship space is used to describe the mathematical or logical relationships that the output results should satisfy when the input parameters change. Each element of the input transformation space consists of an operation method template describing the input transformation and a parameter passing method corresponding to the operation method template. Each element of the output relation space consists of an assertion method template describing the output relation and a parameter passing method corresponding to the assertion method template. The operation method template is used to constrain which operation method the input transformation belongs to, and the assertion method template is used to constrain which assertion method the output relation belongs to. The parameter passing method is used to constrain the source and rules of the parameter values in the operation method template and the assertion method template.
[0009] Furthermore, the construction of the basic combinatorial space of templated metamorphic relations specifically refers to: Collect existing transformation relationships of similar problems in the domain of the target problem to obtain a set of existing transformation relationships; Using each metamorphic relation in the existing set of metamorphic relations, the current input transformation space and output relation space are maintained. Specifically, for each metamorphic relation, the input transformation and output relation are separated, the operation method template to which the input transformation belongs is extracted, and the parameter passing mode corresponding to the operation method template is parsed. When the extracted operation method template does not yet exist in the input transformation space, the operation method template is added to the input transformation space, and the parameter passing mode set corresponding to the operation method template is initialized. When the extracted operation method template already exists in the input transformation space, the parsed new parameter passing mode is merged into the parameter passing mode set corresponding to the existing operation method template. The assertion method template to which the output relation belongs is extracted, and the parameter passing mode corresponding to the assertion method template is parsed. When the extracted assertion method template does not yet exist in the output relation space, the assertion method template is added to the output relation space, and the parameter passing mode set corresponding to the assertion method template is initialized. When the extracted assertion method template already exists in the output relation space, the parsed new parameter passing mode is merged into the parameter passing mode set corresponding to the existing assertion method template.
[0010] Furthermore, the preprocessing of the problem description of the target problem specifically involves: Obtain a natural language problem description of the target problem, perform semantic parsing on the natural language problem description, identify the input parameters, output parameters, and constraints between the input and output parameters involved in the natural language problem description, and convert the parsing results into a structure-constrained formal problem definition. The formal problem definition includes at least a set of input parameters, a set of output parameters, and a symbolic mathematical model for representing the constraints between the input and output parameters.
[0011] Furthermore, the generation of candidate metamorphic relations based on the formal problem definition, combined with forward and reverse generation strategies, specifically involves: The forward generation strategy is as follows: In the input transformation space, an operation method template for the input transformation is selected. Combined with the formal problem definition of the target problem, a parameter passing method matching the input parameters of the target problem is determined from the set of parameter passing methods corresponding to the operation method template. The operation method template is then instantiated using the parameter passing method to obtain an input transformation instance. Based on the input transformation instance, the input parameters of the target problem are transformed. Combined with the formal problem definition, an output relation instance that maintains consistency with the input transformation instance is generated or matched in the output relation space, thereby forming a candidate metamorphic relation composed of the input transformation instance and the output relation instance. The reverse generation strategy is as follows: In the output relation space, an assertion method template for the output relation is selected. Combined with the formal problem definition of the target problem, a parameter passing method matching the output parameter definition of the target problem is determined from the set of parameter passing methods corresponding to the assertion method template. The assertion method template is then instantiated using the parameter passing method to obtain candidate output relation instances. Based on these output relation instances, input transformation instances that satisfy the constraints of the output relation instances are generated or matched in the input transformation space. The consistency between the input transformation instances and the formal problem definition is checked, thereby forming a candidate metamorphic relation composed of input transformation instances and output relation instances. The generated candidate metamorphic relation includes at least one input transformation instance, one output relation instance, and a description of the correspondence between the two.
[0012] Furthermore, the generation and evaluation of candidate metamorphic relationships are performed in a multi-round iterative manner. The candidate metamorphic relationship generation task is divided into multiple subtasks. Each subtask is used to generate and evaluate a candidate metamorphic relationship. The multiple subtasks are organized into several generation windows. Each generation window contains a preset number of subtasks. The subtasks within the generation window are executed using a forward generation strategy and a reverse generation strategy respectively according to a preset ratio. In the initial round of the iteration, the allocation ratio of the forward generation strategy and the reverse generation strategy in the initial generation window is set to a preset initial ratio.
[0013] Furthermore, the evaluation indicators used to assess candidate metamorphic relationships include correctness, repeatability, triviality, and reasonableness. The correctness is used to evaluate whether the candidate metamorphic relation itself is valid, and whether the derivation process between the input transformation and the output relation in the process of generating the metamorphic relation is logically consistent; Repeatability is used to evaluate whether a candidate metamorphic relation is semantically repeated with other candidate metamorphic relations; The triviality is used to evaluate whether the candidate metamorphic relation can serve as an effective test for the target program; Reasonableness is used to evaluate whether there is a reasonable correspondence between the input transformation and the output relationship in the candidate metamorphic relation. Specifically, for candidate metamorphic relations generated by the forward generation strategy, it is evaluated whether there is a corresponding valid output relationship given the input transformation; for candidate metamorphic relations generated by the reverse generation strategy, it is evaluated whether there is a corresponding valid input transformation given the output relationship.
[0014] Furthermore, the results of the automatic evaluation are aggregated according to the generation strategy of the candidate metamorphic relationship, forming strategy-level evaluation results for the forward generation strategy and the reverse generation strategy respectively. After completing a round of candidate metamorphic relationship generation and evaluation, the usage ratio of the forward generation strategy and the reverse generation strategy in the subsequent metamorphic relationship generation process is adjusted based on the strategy-level evaluation results, and the adjusted generation strategy is used for the next round of candidate metamorphic relationship generation.
[0015] The present invention also proposes an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements the automatic generation method of metamorphic relations based on templated combinatorial space as described above.
[0016] The present invention also proposes a computer-readable storage medium storing a computer program that enables a computer to execute the automatic generation method of metamorphic relations based on a templated combinatorial space as described above.
[0017] The beneficial effects of this invention are: This invention provides a unified structural constraint on the generation process of metamorphic relations by constructing a basic combination space of metamorphic relations, including an input transformation space and an output relation space. Based on this, and combined with the formal problem description of the target problem, metamorphic relation generation is performed within this basic combination space, enabling the matching and derivation of input transformations and output relations under explicit semantic constraints. During the generation process, each generated candidate metamorphic relation is evaluated, and the evaluation results guide subsequent generation processes, thereby gradually obtaining effective metamorphic relations that meet quality requirements. Based on these effective metamorphic relations, corresponding test programs are generated, allowing the generated metamorphic relations to be directly used for testing the target program. Through the coordination of these steps, the automatic generation of metamorphic relations and their test programs for formally describable problems is achieved. This reduces the degree of human intervention, expands the scope of generateable metamorphic relations, and achieves more general and automated metamorphic relation generation while ensuring generation quality. Attached Figure Description
[0018] Figure 1 This is a schematic diagram of an automatic generation method for metamorphic relations based on a templated combination space provided in an embodiment of the present invention.
[0019] Figure 2 This is a schematic diagram illustrating the construction process of the basic combination space for metamorphic relationships.
[0020] Figure 3 This is a schematic diagram illustrating the iterative adjustment process of the forward and reverse generation strategies during the metamorphic relationship generation phase. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0022] Example 1 This invention proposes an automatic generation method for metamorphic relations based on a templated combinatorial space. The method flow is as follows: Figure 1 As shown, it includes: Given a natural language problem description of the target problem, a basic combinatorial space of templated metamorphic relations is gradually constructed. This space consists of an input transformation space and an output relation space. The input transformation space describes feasible ways to transform input parameters, while the output relation space describes the mathematical or logical constraints that should be satisfied between output results when input parameters change. Each element of the input transformation space consists of an operation method template describing the input transformation and a corresponding parameter passing method. Each element of the output relation space consists of an assertion method template describing the output relation and a corresponding parameter passing method. The operation method template constrains which operation method the input transformation belongs to, and the assertion method template constrains which assertion method the output relation belongs to. The parameter passing method constrains the source and rules of parameter values in the operation method template and the assertion method template.
[0023] The process of constructing the basic combinatorial space of templated metamorphic relations is as follows: Figure 2 As shown, specifically: Collect existing transformation relationships of similar problems in the domain of the target problem to obtain a set of existing transformation relationships; Using each metamorphic relation in the existing set of metamorphic relations, maintain the current input transformation space and output relation space. Specifically: for each metamorphic relation, separate the input transformation and output relation, extract the operation method template to which the input transformation belongs, parse the parameter passing mode corresponding to the operation method template, and if the extracted operation method template does not yet exist in the input transformation space, add the operation method template to the input transformation space and initialize the parameter passing mode set corresponding to the operation method template; if the extracted operation method template already exists in the input transformation space, merge the parsed new parameter passing mode into the parameter passing mode set corresponding to the existing operation method template. Extract the assertion method template to which the output relation belongs, parse the parameter passing mode corresponding to the assertion method template, and if the extracted assertion method template does not yet exist in the output relation space, add the assertion method template to the output relation space and initialize the parameter passing mode set corresponding to the assertion method template; if the extracted assertion method template already exists in the output relation space, merge the parsed new parameter passing mode into the parameter passing mode set corresponding to the existing assertion method template.
[0024] The above approach allows input transformations with the same operational structure to be maintained using a unified method template. Differences in the source or rules of parameter values across different metamorphic relations are reflected by expanding the set of parameter passing methods. For the same method template, multiple different parameter passing methods can be used to support its reuse in different metamorphic relation generation tasks.
[0025] The problem description of the target problem is preprocessed to generate a formal problem definition; specifically: The natural language problem description of the target problem is obtained, and semantic parsing of the natural language problem description is performed through a language model to identify the input parameters, output parameters and the constraint relationship between the input parameters and output parameters involved in the natural language problem description. The parsing result is then converted into a structure-constrained formal problem definition, which includes at least a set of input parameters, a set of output parameters and a symbolic mathematical model for representing the constraint relationship between the input parameters and output parameters.
[0026] Within the basic combination space of metamorphic relations, candidate metamorphic relations are generated based on the formal problem definition, combined with forward and reverse generation strategies. The forward generation strategy specifically involves: selecting an operation method template for input transformation in the input transformation space; determining a parameter passing method matching the input parameters of the target problem from the set of parameter passing methods corresponding to the operation method template; instantiating the operation method template using the parameter passing method to obtain an input transformation instance; transforming the input parameters of the target problem based on the input transformation instance; and generating or matching an output relation instance in the output relation space that maintains consistency with the input transformation instance, thereby forming a candidate metamorphic relation composed of the input transformation instance and the output relation instance; the reverse generation strategy... The generation strategy is as follows: In the output relation space, an assertion method template for the output relation is selected. Combined with the formal problem definition of the target problem, a parameter passing method matching the output parameter definition of the target problem is determined from the set of parameter passing methods corresponding to the assertion method template. The assertion method template is instantiated using the parameter passing method to obtain candidate output relation instances. Based on the output relation instances, input transformation instances that satisfy the constraints of the output relation instances are generated or matched in the input transformation space. The consistency between the input transformation instances and the formal problem definition is checked, thereby forming a candidate metamorphic relation composed of input transformation instances and output relation instances. The generated candidate metamorphic relation includes at least one input transformation instance, one output relation instance, and a description of the correspondence between them.
[0027] Candidate metamorphic relationships are automatically evaluated and screened to obtain valid metamorphic relationships. The ratio of forward and reverse generation strategies is adjusted based on the evaluation results. The iterative adjustment process of the two strategies during the metamorphic relationship generation stage is as follows: Figure 3 As shown.
[0028] The generation and evaluation of candidate metamorphic relations are performed in a multi-round iterative manner. The candidate metamorphic relation generation task is divided into multiple subtasks. Each subtask is used to generate and evaluate a candidate metamorphic relation. The multiple subtasks are organized into several generation windows. Each generation window contains a preset number of subtasks. The subtasks in the generation window are executed using a forward generation strategy and a reverse generation strategy respectively according to a preset ratio. In the initial round of the iteration, the allocation ratio of the forward generation strategy and the reverse generation strategy in the initial generation window is set to a preset initial ratio.
[0029] The evaluation metrics used to assess candidate metamorphic relationships include correctness, repeatability, triviality, and reasonableness. The correctness is used to evaluate whether the candidate metamorphic relation itself is valid, and whether the derivation process between the input transformation and the output relation in the process of generating the metamorphic relation is logically consistent; Repeatability is used to evaluate whether a candidate metamorphic relation is semantically repeated with other candidate metamorphic relations; The triviality is used to evaluate whether the candidate metamorphic relation can serve as an effective test for the target program; Reasonableness is used to evaluate whether there is a reasonable correspondence between the input transformation and the output relationship in the candidate metamorphic relation. Specifically, for candidate metamorphic relations generated by the forward generation strategy, it is evaluated whether there is a corresponding valid output relationship given the input transformation; for candidate metamorphic relations generated by the reverse generation strategy, it is evaluated whether there is a corresponding valid input transformation given the output relationship.
[0030] For each evaluation indicator, a corresponding evaluation result is generated, and candidate metamorphic relationships are graded based on the evaluation results. When a candidate metamorphic relationship fails to meet the preset requirements on one or more key evaluation indicators, it is determined to be of low quality and discarded. When a candidate metamorphic relationship fails to meet the requirements on some evaluation indicators but performs well on other evaluation indicators, it is determined to contain usable information and enters the automatic correction process for candidate metamorphic relationships. When a candidate metamorphic relationship meets the preset requirements on all evaluation indicators, it is determined to be a valid metamorphic relationship and retained.
[0031] The results of the automatic evaluation are aggregated according to the generation strategies of the candidate metamorphic relationships, forming strategy-level evaluation results for both forward and reverse generation strategies. These strategy-level evaluation results are obtained by weighting the various indicators generated by the strategy within the window, and are used to measure the overall performance of the strategy within the current window. After completing one round of candidate metamorphic relationship generation and evaluation, the usage ratio of the forward and reverse generation strategies in subsequent metamorphic relationship generation processes is adjusted based on the strategy-level evaluation results, ensuring that the generation strategy with better overall performance receives a higher usage ratio in subsequent generation processes. The adjusted generation strategy is then used in the next round of candidate metamorphic relationship generation. Through the iterative execution of these multiple generation windows, a closed-loop feedback loop is formed, encompassing candidate metamorphic relationship generation, evaluation indicator-driven screening and correction, and generation strategy ratio adjustment, thereby gradually obtaining a set of effective metamorphic relationships that meet quality requirements.
[0032] An executable test program is generated based on an effective metamorphic relationship to test the target program. In one embodiment, the test program includes test method code for calling the target program and verifying the metamorphic relationship, and test input data corresponding to the test method code. The test input data includes original test input and associated test input derived from the original test input based on the input transformation defined in the effective metamorphic relationship. The test program can be in the form of unit tests, interface tests, or script tests, and the applicable test framework, programming language, and execution environment are not limited.
[0033] Example 2 This invention proposes an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the automatic generation method of metamorphic relations based on templated combinatorial space as described in Embodiment 1.
[0034] Example 3 This invention proposes a computer-readable storage medium storing a computer program that enables a computer to execute the automatic generation method of metamorphic relations based on a templated combinatorial space as described in Embodiment 1.
[0035] In the embodiments disclosed in this application, a computer storage medium may be a tangible medium that may contain or store programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of computer storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, and portable compact disc read-only memory (CD). ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0036] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0037] The above are merely preferred embodiments of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principles of the present invention should be considered within the scope of protection of the present invention.
Claims
1. A method for automatically generating metamorphic relations based on a templated combinatorial space, characterized in that, include: Construct a basic combinatorial space for templated metamorphic relationships; The problem description of the target problem is preprocessed to generate a formal problem definition; Within the basic combinatorial space of metamorphic relations, candidate metamorphic relations are generated based on the formal problem definition, combining forward and reverse generation strategies. Candidate metamorphic relationships are automatically evaluated and screened to obtain effective metamorphic relationships, and the usage ratio of forward generation strategy and reverse generation strategy is adjusted based on the evaluation results; An executable test program is generated based on an effective metamorphic relationship to test the target program.
2. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 1, characterized in that, The basic combination space of the metamorphic relationship consists of an input transformation space and an output relationship space. The input transformation space is used to describe the feasible ways to transform the input parameters, and the output relationship space is used to describe the mathematical or logical relationships that should be satisfied between the output results when the input parameters change. Each element of the input transformation space consists of an operation method template describing the input transformation and a parameter passing method corresponding to the operation method template. Each element of the output relation space consists of an assertion method template describing the output relation and a parameter passing method corresponding to the assertion method template. The operation method template is used to constrain which operation method the input transformation belongs to, and the assertion method template is used to constrain which assertion method the output relation belongs to. The parameter passing method is used to constrain the source and rules of parameter values in the operation method template and assertion method template.
3. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 1, characterized in that, The basic combinatorial space for constructing templated metamorphic relations is specifically as follows: Collect existing transformation relationships of similar problems in the domain of the target problem to obtain a set of existing transformation relationships; Using each metamorphic relation in the existing set of metamorphic relations, the current input transformation space and output relation space are maintained. Specifically, for each metamorphic relation, the input transformation and output relation are separated, the operation method template to which the input transformation belongs is extracted, and the parameter passing mode corresponding to the operation method template is parsed. When the extracted operation method template does not yet exist in the input transformation space, the operation method template is added to the input transformation space, and the set of parameter passing modes corresponding to the operation method template is initialized. When the extracted operation method template already exists in the input transformation space, the parsed new parameter passing mode is merged into the set of parameter passing modes corresponding to the existing operation method template. Extract the assertion method template to which the output relation belongs, parse the parameter passing method corresponding to the assertion method template, and add the assertion method template to the output relation space if the extracted assertion method template does not yet exist, and initialize the set of parameter passing methods corresponding to the assertion method template; if the extracted assertion method template already exists in the output relation space, then merge the parsed new parameter passing method into the set of parameter passing methods corresponding to the existing assertion method template.
4. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 1, characterized in that, The preprocessing of the problem description of the target problem specifically involves: Obtain a natural language problem description of the target problem, perform semantic parsing on the natural language problem description, identify the input parameters, output parameters, and constraints between the input and output parameters involved in the natural language problem description, and convert the parsing results into a structure-constrained formal problem definition. The formal problem definition includes at least a set of input parameters, a set of output parameters, and a symbolic mathematical model for representing the constraints between the input and output parameters.
5. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 1, characterized in that, The process of generating candidate metamorphic relations based on the formal problem definition, combined with forward and reverse generation strategies, specifically involves: The forward generation strategy is as follows: In the input transformation space, an operation method template for the input transformation is selected. Combined with the formal problem definition of the target problem, a parameter passing method matching the input parameters of the target problem is determined from the set of parameter passing methods corresponding to the operation method template. The operation method template is then instantiated using the parameter passing method to obtain an input transformation instance. Based on the input transformation instance, the input parameters of the target problem are transformed. Combined with the formal problem definition, an output relation instance that maintains consistency with the input transformation instance is generated or matched in the output relation space, thereby forming a candidate metamorphic relation composed of the input transformation instance and the output relation instance. The reverse generation strategy is as follows: select the assertion method template of the output relation in the output relation space, and in combination with the formal problem definition of the target problem, determine the parameter passing method that matches the output parameter definition of the target problem from the parameter passing method set corresponding to the assertion method template, and instantiate the assertion method template using the parameter passing method to obtain candidate output relation instances; Based on the output relation instance, an input transformation instance that can satisfy the constraint of the output relation instance is generated or matched in the input transformation space, and the consistency between the input transformation instance and the formal problem definition is checked, thereby forming a candidate metamorphic relation composed of the input transformation instance and the output relation instance. The generated candidate metamorphic relation includes at least one input transformation instance, one output relation instance, and a description of the correspondence between the two.
6. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 1, characterized in that, The generation and evaluation of candidate metamorphic relations are performed in a multi-round iterative manner. The candidate metamorphic relation generation task is divided into multiple subtasks. Each subtask is used to generate and evaluate a candidate metamorphic relation. The multiple subtasks are organized into several generation windows. Each generation window contains a preset number of subtasks. The subtasks in the generation window are executed using a forward generation strategy and a reverse generation strategy respectively according to a preset ratio. In the initial round of the iteration, the allocation ratio of the forward generation strategy and the reverse generation strategy in the initial generation window is set to a preset initial ratio.
7. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 1, characterized in that, The evaluation metrics used to assess candidate metamorphic relationships include correctness, repeatability, triviality, and reasonableness. The correctness is used to evaluate whether the candidate metamorphic relation itself is valid, and whether the derivation process between the input transformation and the output relation in the process of generating the metamorphic relation is logically consistent; Repeatability is used to evaluate whether a candidate metamorphic relation is semantically repeated with other candidate metamorphic relations; The triviality is used to evaluate whether the candidate metamorphic relation can serve as an effective test for the target program; Reasonableness is used to evaluate whether there is a reasonable correspondence between the input transformation and the output relationship in the candidate metamorphic relation. Specifically, for candidate metamorphic relations generated by the forward generation strategy, it is evaluated whether there is a corresponding valid output relationship given the input transformation; for candidate metamorphic relations generated by the reverse generation strategy, it is evaluated whether there is a corresponding valid input transformation given the output relationship.
8. The method for automatically generating metamorphic relations based on a templated combinatorial space as described in claim 6, characterized in that, The results of the automatic evaluation are aggregated according to the generation strategy of the candidate metamorphic relationship, forming strategy-level evaluation results for the positive generation strategy and the negative generation strategy respectively. After completing one round of candidate metamorphic relationship generation and evaluation, the proportion of positive generation strategy and negative generation strategy used in the subsequent metamorphic relationship generation process is adjusted based on the strategy-level evaluation results, and the adjusted generation strategy is used for the next round of candidate metamorphic relationship generation.
9. An electronic device, characterized in that, include: The memory, the processor, and the computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements the automatic generation method for metamorphic relations based on a templated combinatorial space as described in any one of claims 1-8.
10. A computer-readable storage medium storing a computer program, characterized in that, The computer program causes the computer to execute the automatic generation method of metamorphic relations based on a templated combinatorial space as described in any one of claims 1-8.