Semantic-oriented REST interface consistency test case generation method and related equipment

Through static mapping and dynamic mapping technology, REST interface test cases that conform to the semantics and testing intentions of the system under test are generated, solving the problem that test cases in the prior art do not conform to semantics, and improving the testing efficiency and accuracy.

CN120086127APending Publication Date: 2025-06-03BEIJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411967437.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-06-03

AI Technical Summary

Technical Problem

The prior art is difficult to generate REST interface test cases that meet the semantics and testing intentions of the system being tested, resulting in inaccurate test data.

Method used

By obtaining REST interface files, class model files, URI data and target test semantic files, perform static mapping and dynamic mapping, and generate test cases that conform to the semantics and test intentions of the system being tested.

Benefits of technology

It realizes the generation of test cases that meet the semantics and testing intentions of the system under test, improves the testing efficiency and accuracy, and avoids the need for testers to manually modify the test cases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120086127A_ABST
    Figure CN120086127A_ABST
Patent Text Reader

Abstract

The invention provides a semantic-oriented REST interface consistency test case generation method and related equipment. The method comprises the steps that a REST interface file, a class model file, URI data of a tested system and a target test semantic file describing test semantics of a REST interface are obtained; and performing static mapping and dynamic mapping based on the REST interface file, the class model file, the URI data and the target test semantic file to generate a target test case of the tested system. According to the method, the mapping rules generated by the interface test semantics and the test cases are formally defined by the target test semantic file, so that the generated test cases accord with the semantics and the test intention of the tested system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to a method for generating semantic-oriented REST interface consistency test cases and related devices. Background Art

[0002] REST (Representational State Transfer) is an architectural style of resources corresponding to Web protocols such as HTTP and URL. Due to the characteristics of simplicity, high scalability, high extensibility, low coupling, and high reusability of the REST architecture, the industry has conducted more and more research and applications on the REST architecture, and the REST architecture has become the mainstream technology of Web services.

[0003] Interface consistency testing is to test the compliance of the external interface of the system or component under test with the corresponding interface standard, mainly used to test the interfaces between the system and other external systems, as well as the interfaces between internal sub-modules, to ensure that the interfaces of the system under test can work properly. Among them, the most core part of interface testing is test cases.

[0004] Automatically generating test cases can generate syntactically correct test data according to the syntax rules defined by the REST interface. However, in the actual testing process, the test data often carries the semantics of the system under test and the testing intentions of the testers. The semantics of the system under test refers to the semantic information of each attribute in the class model of the system under test and the data relationship between attributes. When testers customize test data, they can well understand this semantics and send the most semantic-compliant test cases for the system under test. However, it is very difficult for tools that automatically generate test cases to automatically generate test cases that conform to the semantics of the system under test and the testing intentions of the testers. This is the main challenge in the field of automatic test case generation at present. Summary of the Invention

[0005] The present invention provides a method for generating semantic-oriented REST interface consistency test cases and related devices, which is used to solve the defect that the generated test cases do not conform to the semantics in the prior art, and achieve the effect of generating test cases that conform to the semantics of the system under test and the testing intentions.

[0006] The present invention provides a method for generating semantic-oriented REST interface consistency test cases, including: Obtaining a REST interface file, a class model file, URI data of the system under test, and a target test semantic file describing the test semantics of the REST interface; Based on the REST interface file, the class model file, the URI data, and the target test semantic file, performing static mapping and dynamic mapping to generate target test cases for the system under test.

[0007] A semantic-oriented REST interface consistency test case generation method provided by the present invention, where the target test cases include first test cases and second test cases; the target test semantic file is obtained by a tester modifying an initial test semantic file, and the initial test semantic file is generated based on the parsing result obtained by parsing a REST interface file; based on the REST interface file, class model file, URI data, and target test semantic file, static mapping and dynamic mapping are performed to generate target test cases for the system under test, including: Performing static mapping based on the REST interface file and the target test semantic file to obtain corresponding first test cases; Performing dynamic mapping according to the REST interface file, target test semantic file, URI data, and class model file to obtain corresponding second test cases.

[0008] A semantic-oriented REST interface consistency test case generation method provided by the present invention, performing static mapping based on the REST interface file and the target test semantic file to obtain corresponding first test cases, including: Obtaining static mapping rules, and based on the static mapping rules, performing static mapping on the REST interface file and the target test semantic file to obtain corresponding first test cases.

[0009] A semantic-oriented REST interface consistency test case generation method provided by the present invention, performing dynamic mapping according to the REST interface file, target test semantic file, URI data, and class model file to obtain corresponding second test cases, including: Obtaining a first dynamic mapping rule for the params field and a second dynamic mapping rule for the body field; Based on the first dynamic mapping rule, performing dynamic mapping on the target test semantic file, REST interface file, and URI data for the params field to obtain test cases for the params field; Based on the second dynamic mapping rule, performing dynamic mapping on the REST interface file, target test semantic file, URI data, and class model file for the body field to obtain test cases for the body field; Obtaining second test cases based on the test cases for the params field and the test cases for the body field.

[0010] A semantic-oriented REST interface consistency test case generation method provided by the present invention, after performing static mapping and dynamic mapping based on the REST interface file, class model file, URI data, and target test semantic file to generate target test cases for the system under test, the method further includes: Generate an instance tree based on URI data; Update the instance tree based on the generated target test cases.

[0011] According to a semantic-oriented REST interface consistency test case generation method provided by the present invention, the target test semantic file includes definition information on intent test responses, intent test sequences, intent test parameter association relationships, and test data semantics.

[0012] According to a semantic-oriented REST interface consistency test case generation method provided by the present invention, before obtaining the REST interface file, the class model file, the URI data of the system under test, and the target test semantic file describing the test semantics of the REST interface, the method further includes: Perform lexical definition and grammar definition on the test semantics of the REST interface through the BNF paradigm, so as to obtain the target test semantic file based on the lexical definition and grammar definition.

[0013] The present invention also provides a semantic-oriented REST interface consistency test case generation device, including: An acquisition module configured to acquire the REST interface file, the class model file, the URI data of the system under test, and the target test semantic file describing the test semantics of the REST interface; A first generation module configured to perform static mapping and dynamic mapping based on the REST interface file, the class model file, the URI data, and the target test semantic file to generate target test cases for the system under test.

[0014] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements any of the above-mentioned semantic-oriented REST interface consistency test case generation methods.

[0015] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements any of the above-mentioned semantic-oriented REST interface consistency test case generation methods.

[0016] The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements any of the above-mentioned semantic-oriented REST interface consistency test case generation methods.

[0017] The method and related device for generating semantic-oriented REST interface consistency test cases provided by the present invention formally define the mapping of interface test semantics and test case generation through a target test semantics file that describes the test semantics of the REST interface, providing a paradigm for semantic-oriented test case generation. The present invention can perform dynamic mapping and static mapping based on the REST interface file, class model file, and URI data of the system under test, as well as the target test semantics file, to generate test cases that conform to the semantics and test intent of the system under test. Brief Description of the Drawings

[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following-described drawings are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0019] Figure 1 is one of the schematic flowcharts of the method for generating semantic-oriented REST interface consistency test cases provided by the present invention.

[0020] Figure 2 is one of the schematic diagrams of the REST interface definition of the student model in the embodiment provided by the present invention.

[0021] Figure 3 is the second schematic diagram of the REST interface definition of the student model in the embodiment provided by the present invention.

[0022] Figure 4 is the schematic diagram of the schemas definition of the student model in the embodiment provided by the present invention.

[0023] Figure 5 is the schematic diagram of the test cases of the class student model in the embodiment provided by the present invention.

[0024] Figure 6 is the schematic diagram of the instance tree constructed based on the URI data obtained through the inclusion service.

[0025] Figure 7 is one of the schematic diagrams of the generated test cases in the embodiment provided by the present invention.

[0026] Figure 8 is the second schematic diagram of the generated test cases in the embodiment provided by the present invention.

[0027] Figure 9 is the third schematic diagram of the generated test cases in the embodiment provided by the present invention.

[0028] Figure 10This is the fourth schematic diagram of the test case generated in the embodiment provided by the present invention.

[0029] Figure 11 This is the fifth schematic diagram of the test case generated in the embodiment provided by the present invention.

[0030] Figure 12 It is a structural schematic diagram of a semantics-oriented REST interface consistency test case generation device provided by the present invention.

[0031] Figure 13 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0033] In recent years, for the generation of test cases for REST interfaces, some studies have begun to focus on and solve the resource dependencies and parameter relationships in interface requests. A large number of valid input parameters of interface requests depend on the responses of other interfaces. How to model and solve these resource dependencies is the key to generating effective test cases for APIs. RESTler uses a lightweight static analysis method to automatically infer the producer-consumer relationship between requests from the swagger document. Starting from a single API, it extends the API call sequence by appending API requests in a heuristic way, which can test deeper cloud services. However, this bottom-up approach lacks an overall awareness of the test sequence and can easily produce path explosions during the search. To this end, forREST implements a tree-based REST API fuzzy testing method, which cleverly uses a tree structure to model the relationship between APIs, which not only reduces the complexity of API dependencies, but also captures the priority of resource dependencies, which is more effective than traditional graph-based testing methods. RestTestGen infers the resource dependencies between APIs through a simple field matching algorithm, builds an operation dependency graph (ODG), and generates valid API call sequences by traversing the ODG. However, this method is heavily dependent on ODG, which may not correctly reflect API behavior due to certain defects (for example, non-standard OpenAPI writing), thus affecting the test effect.

[0034] The main deficiencies in the current research field of resource dependency relationships and parameter relationships in interface requests are that the test sequences generated by algorithmic models cannot guarantee coverage of all interfaces, and the test sequences inferred by the models do not necessarily conform to the test intentions of the testing party itself.

[0035] Currently, the development and application of REST interface automation testing tools such as RestAssured and RestSharp have also emerged. These tools aim to simplify the testing process, improve testing efficiency, and have achieved certain application effects in actual projects. However, the data generation strategies of test cases in these tools do not consider the semantics of test cases and lack support for the automatic generation function of semantics-oriented test cases.

[0036] Therefore, this application provides a semantics-oriented REST interface consistency test case generation method and related devices. The following combines Figures 1-13 to describe the semantics-oriented REST interface consistency test case generation method and related devices of the present invention.

[0037] Figure 1 is a flowchart of a semantics-oriented REST interface consistency test case generation method shown according to an exemplary embodiment. As Figure 1 shown, in an exemplary embodiment, this semantics-oriented REST interface consistency test case generation method includes steps 110 to 120, which are introduced in detail as follows.

[0038] Step 110, obtain the REST interface file, class model file, URI data of the system under test, and the target test semantics file describing the test semantics of the REST interface.

[0039] In the embodiments of the present invention, the REST interface file provides the interface information of the system under test; the class model file provides the inclusion relationship, association relationship, etc. between the entity class corresponding to the interface and other classes; the URI (Uniform Resource Identifier) data of the system under test is obtained through the inclusion service, and the URI data can be used to construct the instance tree of the system under test; the target test semantics file of the interface test semantics is used to form test cases that conform to the semantics and test intentions of the system under test.

[0040] Step 120, based on the REST interface file, class model file, URI data, and target test semantics file, perform static mapping and dynamic mapping to generate the target test cases of the system under test.

[0041] In the embodiments of the present invention, a mapping rule from input to output is proposed to guide the mapping generation of test cases. The mapping rule is divided into static mapping and dynamic mapping. The static mapping is responsible for generating the static framework of test cases according to the REST interface file and the target test semantic file. The dynamic mapping is responsible for generating target test cases that conform to the semantic information of the system under test based on the REST interface file, the target test semantic file, the class relationship model file, and the URI data.

[0042] In the embodiments of the present invention, the target test semantic file that describes the test semantics of the REST interface formally defines the mapping rules for interface test semantics and test case generation, providing a paradigm for semantic-oriented test case generation. The present invention can perform dynamic mapping and static mapping based on the REST interface file, the class model file, and the URI data of the system under test, as well as the target test semantic file, to generate test cases that conform to the semantics and test intentions of the system under test. The test cases that conform to the semantics not only consider the test intention, the expected test sequence, and the expected test association relationship, but also consider the class model of the system under test. Finally, the automatically generated semantic-oriented test cases satisfy both test semantics and data semantics, without the need for testers to manually intervene and modify, and can be directly sent to the system under test for testing, achieving the expected test effect and improving the test efficiency and test accuracy.

[0043] In an exemplary embodiment of the present invention, the target test semantic file includes definition information for intent test responses, intent test sequences, intent test parameter association relationships, and test data semantics.

[0044] Specifically, the present invention proposes a formal definition of the test semantics for the REST interface to guide the automatic generation of test data that conforms to the semantics and test intentions of the system under test. The definition of test semantics includes the definitions of intent test responses, intent test sequences, intent test parameter association relationships, and test data semantics.

[0045] An intent test response refers to a specific method for a specific interface. Testers have an expected return response code. The generated test cases should conform to the parameter definition and response code semantics, and as closely as possible match the real data of the system under test.

[0046] An intent test sequence refers to the permutation and combination of the number of tests and the order for different operation methods of an interface. The intent test parameter association relationship refers to the association relationship between the parameters involved in different operation methods of an interface.

[0047] The association between the intent test sequence and the intent test parameters is inseparable. In a real test scenario, a reasonable test sequence needs to be arranged according to the test requirements, and it is possible to select the same or different instance resources for testing in a single sequence. This places specific requirements on the association of test parameters in a test sequence, and test data that conforms to the test intent needs to be generated.

[0048] The initial test data semantics mainly describe the semantics of the interface path parameters themselves and the semantics of the entity class attributes defined by the system under test in the REST interface, as well as the association relationships between the attributes. The association relationships between the attribute data in the class model are divided into two types, namely, the association relationships between different attributes of the same entity class and the association relationships between different attributes of different entity classes. When generating test data, the semantics of the attributes themselves and the data association relationships need to be considered.

[0049] In an exemplary embodiment of the present invention, before obtaining the REST interface file, the class model file, the URI data of the system under test, and the target test semantics file describing the test semantics of the REST interface, the method further includes the following steps, which are introduced in detail below.

[0050] The lexical definition and grammar definition of the test semantics of the REST interface are performed through the BNF paradigm, so as to obtain the target test semantics file based on the lexical definition and the grammar definition.

[0051] In the embodiment of the present invention, the BNF paradigm (Backus-Naur Form) is used to formally define the test semantics of the REST interface. The formal definition is mainly divided into lexical definition and grammar definition. The lexical definition part mainly defines the fixed composition method of the lexicon, including the composition forms of uppercase and lowercase letters, numbers, etc., and some fixed symbol representations, as shown in Table 1 below.

[0052] Table 1 Based on the lexical definition, the grammar definition of the test semantics is performed. The test semantics of all interfaces are composed of the test semantics of several specific interfaces, and the test semantics of a specific interface are composed of the test semantics under all Http request methods included in this interface. For the test semantics of a specific method under each specific interface, it includes the definitions of intent test response, intent test sequence, intent test parameter association relationship, and data semantics, as shown in Table 2 below.

[0053] Table 2 Data semantics are required in both the generation of interface parameters and test data for the interface body. The detailed definition of data semantics is described in Table 3. Data semantics include the data model of parameters or attribute fields themselves (such as value ranges, value rules, special values, etc.), the association relationships between different attributes of the same entity class, and the association relationships between different attributes of different entity classes.

[0054] Table 3 The following Table 4 shows the grammar definitions involved in the association relationship expressions in data semantics, including conventional operations such as addition, subtraction, multiplication, division, remainder, absolute value, trigonometric function operations, exponential and logarithmic operations, summation operations, etc., all of which are expanded based on basic elements such as letters, numbers, and variable names.

[0055] Table 4 In an exemplary embodiment of the present invention, the target test cases include a first test case and a second test case; the target test semantic file is obtained by a tester modifying the initial test semantic file, and the initial test semantic file is generated based on the parsing result obtained by parsing the REST interface file; based on the REST interface file, class model file, URI data, and target test semantic file, static mapping and dynamic mapping are performed to generate the target test cases of the system under test, including the following steps, which are introduced in detail below.

[0056] Perform static mapping based on the REST interface file and the target test semantic file to obtain the corresponding first test case.

[0057] Perform dynamic mapping according to the REST interface file, target test semantic file, URI data, and class model file to obtain the corresponding second test case.

[0058] In the embodiment of the present invention, the REST interface file is parsed to obtain the corresponding parsing result, and based on the parsing result, an initial test semantic file is generated. The tester makes custom modifications on the basis of the initial test semantic file and adds test intentions therein, thereby generating the target test semantic file. Parse the target test semantic file and store the corresponding parsing result.

[0059] Perform static mapping based on the REST interface file and the target test semantic file, and perform dynamic mapping based on the REST interface file, target test semantic file, URI data, and class model file to obtain the corresponding test cases.

[0060] In an exemplary embodiment of the present invention, static mapping is performed based on a REST interface file and a target test semantic file to obtain a corresponding first test case, including the following steps, which are introduced in detail below.

[0061] Obtain static mapping rules, and based on the static mapping rules, perform static mapping on the REST interface file and the target test semantic file to obtain a corresponding first test case.

[0062] In the embodiment of the present invention, in the static mapping rules, both the fields and the field values are determined, and it is necessary to obtain and encapsulate them into test cases according to the mapping rules. The static mapping rules can be represented by a simple sentence-based translation quadruple as: Next, each component symbol and rule in the quadruple will be explained one by one.

[0063] Specifically, represents a finite input set, . It contains all the content in two input files, namely the REST interface file and the target test semantic file. Among them, the target test semantic file is represented by , and the REST interface file is represented by .

[0064] represents a finite output set, which is a set of multiple test cases, represented as , define as one of the test cases, as the total number of specific test cases. The mapping rules for the encapsulation format of each test case are the same, where the specific values corresponding to the fields will be different.

[0065] represents a finite set of non-terminals, , which represents the intermediate results that will appear in the derivation rules. Define the set of each field in the test case as , the set of each field value as , and the key-value pair set of field: field value as .

[0066] The elements in the set of each field in the test case correspond to different fields of the test case, which are the test request path corresponding to this test case, the request Http method , the detailed description , the additional document , the request header , the request parameter and the request body , represented as: .

[0067] Similarly, the elements in the field value set correspond to different field values of the test case respectively, and are expressed as: . Among them, indicates that the value of the headers field in the test case is a fixed value and does not change with different inputs; and indicate that the values of the json field and the params field in the test case are both dynamically generated and are the content generated by the subsequent dynamic mapping rules, which will not be discussed in detail here.

[0068] Similarly, the elements in the key-value pair set correspond to the key-value pairs of different fields and field values of the test case respectively, and are expressed as: .

[0069] In addition, for each test in the target test semantic file, the path (URL) and method (method) of the test are defined, and the definition pair of the path and method of each test in the target test semantic file is denoted as .

[0070] represents the start symbol, , and is expressed as: . Multiple tests are defined in the target test semantic file, is the definition of the path and method of one of the tests, and n is the specific total number of tests. Each time appears in the semantic file, a mapping process starts.

[0071] represents a finite set of derivation rules, and its definition is shown in Table 5 below.

[0072] Table 5 In an exemplary embodiment of the present invention, dynamic mapping is performed according to the REST interface file, the target test semantic file, the URI data, and the class model file to obtain the corresponding second test case, including the following steps, which are introduced in detail below.

[0073] Obtain the first dynamic mapping rule for the params field and the second dynamic mapping rule for the body field.

[0074] Based on the first dynamic mapping rule, perform dynamic mapping of the params field on the target test semantic file, the REST interface file, and the URI data to obtain the test case for the params field.

[0075] Based on the second dynamic mapping rule, perform dynamic mapping on the REST interface file, target test semantic file, URI data, and class model file for the body field to obtain test cases for the body field.

[0076] Obtain the second test case based on the test case for the params field and the test case for the body field.

[0077] In the embodiments of the present invention, parameters can be passed to the system under test in different ways. The two most common ways are using params (query parameters) and body (request body). Params are passed as part of the URL, located in the query string of the URL, that is, the part after the? in the URL. The body is included in the request body of the HTTP request. It is usually empty for GET requests, but for requests such as POST, PUT, PATCH, etc., it can contain a large amount of data.

[0078] Dynamic mapping rule Includes the first dynamic mapping for the params field and the second dynamic mapping rule for the body field , then the dynamic mapping rule is expressed as: .

[0079] During the dynamic mapping process, it is necessary to combine multiple inputs and process them. In the embodiments of the present invention, a stack is used to store context information and the order requirements are met during the mapping process. Therefore, the present invention selects the pushdown automaton model to define the dynamic mapping rule.

[0080] Specifically, the first dynamic mapping rule for the params field is expressed as: , and the meanings of the symbols in the first mapping rule are explained one by one below.

[0081] is a finite set of states, and the state set is defined as follows: ; Among them, represents the initial state, is the state of obtaining the parsing result of the target test semantic file, is the state of obtaining the parsing result of the REST interface file, is the state of obtaining the parsing result of the URI, is the state of generating test data, is the termination state.

[0082] is the input set, the input set is expressed as: ; input set contains three inputs, namely the target test semantic file, the REST interface file, and the URI data of the system under test obtained through the inclusion service. Among them, the target test semantic file is represented by the REST interface file is represented by and the URI data of the system under test is represented by respectively.

[0083] is the stack alphabet of the pushdown automaton model, which contains the content obtained from each input during the mapping process and serves as an intermediate parameter for the entire mapping process, directly acting on the generation of test data for the params field. contains the test semantics obtained from the target test semantic file, which includes the expected response , the association relationship between tests , the custom attributes of the params field included in the data semantics ; the definition type of the params field obtained from the REST interface file ; and the instance tree of the system under test constructed through the URI data obtained from the inclusion service . In addition also contains the initial content of the stack, which stores the previously generated test instances and is defined as . Then the definition of the set is as follows: In particular, during the test instance generation phase, different generation strategies will be adopted according to the different contents in and and . Therefore, we divide the test instance generation state into different states corresponding to different generation strategies. That is: .

[0084] The content corresponding to the test instance generation state is shown in Table 6 below.

[0085] Table 6 is the transition rule between states. In the embodiment of the present invention, the definition of is extended. The transition function receives 3 parameters, where is the current state , is the input that can be received in the current state, or , is the set of stack symbols required for the current state to transition to the next state, . The relevant introduction of the conversion rule is shown in Table 7 below.

[0086] Table 7 Upon reaching the final state, the stored in the stack is the field value obtained by dynamically mapping the params field

[0087] Specifically, for the second dynamic mapping rule of the body field is expressed as: , the meanings of the symbols in the second mapping rule are explained one by one below.

[0088] is a finite set of states, and the state set is defined as follows: ; Among them, represents the initial state, is the state of obtaining the parsing result of the target test semantic file, is the state of obtaining the parsing result of the URI, is the state of obtaining the parsing result of the class model, is the state of obtaining the parsing result of the REST interface file, is the state of generating test data for the body part, is the termination state.

[0089] is the input set, and the input set is expressed as: .

[0090] The input set contains four inputs, namely the class model file, REST interface file, target test semantic file, and URI data of the system under test. Among them, the class model file is represented by , the REST interface file is represented by , the semantic file is represented by , and the URI of the system under test is represented by .

[0091] is the stack alphabet of the pushdown automaton model, which contains the content obtained from each input during the mapping process. As an intermediate parameter for the entire mapping process, it directly acts on the generation of test data for the body field. Contains the test semantics obtained from the target test semantic file, which includes a set of field semantic attributes , the association relationships between different fields within the same class , the association relationships between different fields in different classes ; the association relationships between this interface class and other classes obtained from the class relationship model file ; the schema contained in this interface class obtained from the REST interface file, that is, the names and types of each field, which are uniformly denoted as ; and the instance tree of the system under test constructed by using the URI data obtained from the included service . In addition, also contains the initial content of the stack, which stores the previously generated test data, defined as .

[0092] If there are multiple inclusion relationships for the entity class corresponding to this interface in the class model, it is necessary to generate the included class instances in sequence and finally generate the class instance of itself. Assume is a natural number that points to the first class instance to be generated during initialization, represents the total number of class instances to be generated. Then the set is represented as: .

[0093] Specifically, for the fields included in the body, their syntax is defined in the REST interface file, and their semantics are defined in the target test semantic file. Therefore, the generation strategy for the test cases of the body part is to generate them first according to the syntax definition and then overwrite them according to the semantic definition. Therefore, is further divided into two states, namely the syntax generation state and the semantic generation state, defined as: .

[0094] is the transition rule between states. Here, the definition of is still extended. The transition function receives 3 parameters, where is the current state, , is the input that the current state can receive, or , is the set of stack symbols required for the current state to transition to the next state, The relevant introduction of the conversion rules is shown in the following Table 8.

[0095] Table 8 Arrival After reaching the final state, the stored in the stack is the field value obtained by dynamic mapping for the body field.

[0096] In an exemplary embodiment of the present invention, after generating the target test cases of the system under test through static mapping and dynamic mapping based on the REST interface file, class model file, URI data, and target test semantic file, the method further includes the following steps, which are introduced in detail as follows.

[0097] Generate an instance tree based on the URI data.

[0098] Update the instance tree based on the generated target test cases.

[0099] In the embodiment of the present invention, the instance tree is a structure for organizing and managing test cases, usually presented in a tree form to show different levels of test cases and their relationships, which can help testers manage and execute test cases more clearly, thereby improving test efficiency and coverage.

[0100] Construct an instance tree through the URI data. During the dynamic mapping process, the construction and real-time update of the instance tree of the system under test play an important role in generating test cases that conform to the test semantics. Through the instance tree, the real data of the system under test can be obtained. First, the identifier of the instance data can be directly sent to the system under test as a test case. At this time, the test case is the real data in the system under test and is the most conforming to the semantics of the system under test. Second, the real identifier data in the instance tree can provide a constraint reference for the generation of test cases. For example, for the interface test of creating a new resource, the test data that can return a successful response needs to meet the constraint conditions not in the instance tree. The instance tree makes the generated test data more conform to the real semantics of the system under test.

[0101] In an exemplary embodiment of the present invention, the method for generating semantic-oriented REST interface consistency test cases includes: respectively parsing the class model file and the REST interface file, and storing the corresponding parsing results; constructing an instance tree of the managed system through URI data; generating a target test semantic file based on the parsing result of the REST interface file, and parsing the target test semantic file to obtain the corresponding parsing result and store it; traversing the target test semantic file to determine the number of interfaces for which test cases need to be generated, and determining the number of methods for which test cases need to be generated under a specific interface; based on the instance tree of the system under test, the parsing result of the class model file, the number of interfaces, the number of methods, and the parsing result of the target test semantic file, generating corresponding test cases for each Http request under each interface defined in the target test semantic file; encapsulating the test cases, and detecting whether the test cases for all methods under a specific interface have been generated. If not, jump to the step of generating corresponding test cases for each Http request under each interface defined in the target test semantic file based on the instance tree of the system under test, the parsing result of the class model file, the number of interfaces, the number of methods, and the parsing result of the target test semantic file. If it is generated, detect whether the test cases for all interfaces have been generated. If not, jump to the step of determining the number of methods for which test cases need to be generated under a specific interface until the test cases for all interfaces are generated.

[0102] In the embodiment of the present invention, the process of generating test cases follows the static mapping rules and dynamic mapping rules defined above.

[0103] In an exemplary embodiment of the present invention, the class model relationship of the class-student model is used as an example, where one class instance of a class contains three class instances of students. As Figures 2 to 4 shown, Figures 2 to 4 is the definition of the REST interface and schemas for the class and students classes. As Figure 5 is an example of the representation of the test cases of the class-student model defined according to the test semantic formal definition rules. Figure 6 is an instance tree constructed based on the URI data obtained through the included service.

[0104] After the semantic-oriented input is prepared, the generation of test cases starts following the mapping rules. The following Table 9 shows the static mapping derivation process for the / resource / student interface.

[0105] Table 9 After the generation of the static mapping rules is completed, the generation of the dynamic mapping rules begins. During the dynamic mapping process, corresponding test cases can be generated for specific methods of specific interfaces. During the generation process, two instance trees are maintained. Instance tree 1 is the original instance tree of the system under test to provide the original real data of the system under test; Instance tree 2 is the instance tree updated as the test cases are generated to record the latest instance state of the system under test.

[0106] Specifically, for the POST method, the root DN is generated according to instance tree 1, and instance tree 2 is updated. The number of classes involved in the inclusion relationship is determined according to the class model file. The quantitative relationship between each included class and its parent class is determined according to the number of classes. Whether there is an inclusion relationship in the sub-DN is determined according to the quantitative relationship. If there is, jump to the step of determining the number of classes involved in the inclusion relationship according to the class model file. If not, generate the sub-DN and update instance tree 2. For each DN, the attribute data at the syntax level and the attribute data at the semantic level are generated respectively. It is detected whether the attribute data of each DN in the quantitative relationship has been generated. If not, jump to the step of generating the attribute data at the syntax level and the attribute data at the semantic level for each DN respectively. If it has been generated, it is detected whether the attribute data of each DN in the number of classes has been generated. If not, jump to the step of determining the quantitative relationship between each included class and its parent class according to the number of classes. If it has been generated, the corresponding test case is generated and the test case is encapsulated.

[0107] For the GET, PUT, and DELETE methods, it is determined whether the intention test parameter association relationship is specified. If it is specified, the param field is generated according to the intention test parameter association relationship. If it is not specified, the param field is generated according to instance tree 2. Instance tree 2 is updated according to the generated param field. It is detected whether the specific method is the PUT method. If it is the PUT method, a new body field is generated according to the test semantic file, and a test case is generated based on the body field. If it is not the PUT method, the test case is encapsulated according to the param field PUT method.

[0108] In the embodiment of the present application, in the foregoing class student model, for the POST method of the / resource / student interface, the generated test cases are as Figure 7 shown. The test expectation defined in the test semantic file is 201, so the student_id in the generated test case cannot conflict with the existing DN in the current instance tree. In addition, the generated test cases meet the data semantics of each attribute itself and the association relationship between attributes defined in the test semantics (the value of the grade attribute is the sum of the values of the chineseGrade, mathGrade, and englishGrade attributes).

[0109] In the foregoing class student model, for the GET, PUT, and DELETE methods of the / resource / student / {student_id} interface, the generated test cases are shown in Figure 8 to FIG. 10. The expected test response for the GET method is 201. Therefore, the student_id in the generated test case needs to be in the instance tree, that is, an instance that currently exists in the system under test is generated. The expected test response for the PUT method is 201, and it is specified that the parameters need to be the same as those just generated by the previous POST method. Therefore, the student_id in the generated test case is the student_id created by the previous POST method. The expected test response for the DELETE method is 404. Therefore, the student_id in the generated test case cannot be in the instance tree, that is, an instance parameter that currently does not exist in the system under test is generated.

[0110] For the POST method of the / resource / class interface, the generated test cases are as Figure 11 shown. The expected test response for the POST method is 201. Therefore, the DN in the generated test case cannot conflict with the existing DN in the current instance tree. In addition, the generated test cases satisfy the data semantics of each attribute itself defined in the test semantics, the association relationship between attributes within the class (the value of the grade attribute of the student class is the sum of the values of the chineseGrade, mathGrade, and englishGrade attributes), and the association relationship between attributes between classes (the value of the avgGrade attribute of the class class is the average value of the grade attributes of the 3 student class instances it contains).

[0111] Next, a semantic-oriented REST interface consistency test case generation device provided by the present invention will be described. The semantic-oriented REST interface consistency test case generation device described below can be correspondingly referred to the semantic-oriented REST interface consistency test case generation method described above. It should be noted that the device provided in the following embodiments and the method provided in the above embodiments belong to the same concept. The specific ways in which each module and unit perform operations have been described in detail in the method embodiments and will not be repeated here.

[0112] In an exemplary embodiment of the present invention, please refer to Figure 12 , Figure 12 which is a semantic-oriented REST interface consistency test case generation device shown according to an exemplary embodiment, including the following modules.

[0113] An acquisition module 1210, configured to acquire a REST interface file, a class model file, URI data of a system under test, and a target test semantic file describing the test semantics of the REST interface; A first generation module 1220, configured to perform static mapping and dynamic mapping based on the REST interface file, the class model file, the URI data, and the target test semantic file to generate target test cases for the system under test.

[0114] In an exemplary embodiment of the present invention, the target test cases include a first test case and a second test case; the target test semantic file is obtained by a tester modifying an initial test semantic file, and the initial test semantic file is generated based on the parsing result obtained by parsing the REST interface file; the first generation module 1220 includes: A static mapping sub-module, configured to perform static mapping based on the REST interface file and the target test semantic file to obtain a corresponding first test case; A dynamic mapping sub-module, configured to perform dynamic mapping based on the REST interface file, the target test semantic file, the URI data, and the class model file to obtain a corresponding second test case.

[0115] In an exemplary embodiment of the present invention, the static mapping sub-module includes: A static mapping unit, configured to obtain a static mapping rule and perform static mapping on the REST interface file and the target test semantic file based on the static mapping rule to obtain a corresponding first test case.

[0116] In an exemplary embodiment of the present invention, the dynamic mapping sub-module includes: An acquisition unit, configured to obtain a first dynamic mapping rule for the params field and a second dynamic mapping rule for the body field; A first dynamic mapping unit, configured to perform dynamic mapping on the target test semantic file, the REST interface file, and the URI data for the params field based on the first dynamic mapping rule to obtain a test case for the params field; A second dynamic mapping unit, configured to perform dynamic mapping on the REST interface file, the target test semantic file, the URI data, and the class model file for the body field based on the second dynamic mapping rule to obtain a test case for the body field; A test case unit, configured to obtain a second test case based on the test case for the params field and the test case for the body field.

[0117] In an exemplary embodiment of the present invention, the semantic-oriented REST interface consistency test case generation device further includes: A second generation module, configured to generate an instance tree based on URI data; An update module, configured to update the instance tree based on the generated target test cases.

[0118] In an exemplary embodiment of the present invention, the target test semantic file includes definition information on intent test responses, intent test sequences, intent test parameter association relationships, and test data semantics.

[0119] In an exemplary embodiment of the present invention, the semantic-oriented REST interface consistency test case generation device further includes: A definition module, configured to perform lexical definition and grammar definition on the test semantics of the REST interface through the BNF paradigm, so as to obtain the target test semantic file based on the lexical definition and the grammar definition.

[0120] Figure 13 Illustrates a schematic diagram of the entity structure of an electronic device, as Figure 13 shown. The electronic device may include: a processor 1310, a communication interface 1320, a memory 1330, and a communication bus 1340. Among them, the processor 1310, the communication interface 1320, and the memory 1330 communicate with each other through the communication bus 1340. The processor 1310 may call the logical instructions in the memory 1330 to execute the semantic-oriented REST interface consistency test case generation method.

[0121] In addition, when the logical instructions in the above-mentioned memory 1330 are implemented in the form of software functional units and sold or used as an independent product, they may be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, may be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs, and other various media that can store program codes.

[0122] On the other hand, the present invention also provides a computer program product. The computer program product includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the semantic-oriented REST interface conformance test case generation method provided by each of the above methods.

[0123] In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is implemented to execute the semantic-oriented REST interface conformance test case generation method provided by each of the above methods.

[0124] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative labor.

[0125] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solutions, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiments.

[0126] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in each of the foregoing embodiments, or perform equivalent replacements for some of the technical features. And these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of each embodiment of the present invention.

Claims

1. A semantics-oriented REST interface consistency test case generation method, characterized in that: include: Obtaining a REST interface file, a class model file, URI data of the system under test, and a target test semantics file describing the test semantics of the REST interface; Based on the REST interface file, the class model file, the URI data and the target test semantic file, static mapping and dynamic mapping are performed to generate a target test case for the system under test.

2. The method for generating semantic-oriented REST interface consistency test cases according to claim 1, characterized in that: The target test case includes a first test case and a second test case; the target test semantic file is obtained by a tester modifying the initial test semantic file, and the initial test semantic file is generated based on the parsing result obtained by parsing the REST interface file; the static mapping and dynamic mapping based on the REST interface file, the class model file, the URI data and the target test semantic file to generate the target test case of the system under test includes: Perform static mapping based on the REST interface file and the target test semantic file to obtain a corresponding first test case; Dynamic mapping is performed according to the REST interface file, the target test semantic file, the URI data and the class model file to obtain a corresponding second test case.

3. The method for generating semantic-oriented REST interface consistency test cases according to claim 2, characterized in that: The static mapping based on the REST interface file and the target test semantic file to obtain a corresponding first test case includes: Obtain static mapping rules, and based on the static mapping rules, statically map the REST interface file and the target test semantic file to obtain the corresponding first test case.

4. The method for generating semantic-oriented REST interface consistency test cases according to claim 2, characterized in that: The dynamically mapping according to the REST interface file, the target test semantic file, the URI data and the class model file to obtain a corresponding second test case includes: Get the first dynamic mapping rule for the params field and the second dynamic mapping rule for the body field; Based on the first dynamic mapping rule, dynamically map the params field of the target test semantic file, the REST interface file, and the URI data to obtain a test case for the params field; Based on the second dynamic mapping rule, dynamically map the body field of the REST interface file, the target test semantic file, the URI data, and the class model file to obtain a test case for the body field; The second test case is obtained based on the test case for the params field and the test case for the body field.

5. The method for generating semantic-oriented REST interface consistency test cases according to claim 1, characterized in that: After performing static mapping and dynamic mapping based on the REST interface file, the class model file, the URI data and the target test semantic file to generate a target test case for the system under test, the method further includes: Generate an instance tree based on the URI data; The instance tree is updated based on the generated target test case.

6. The method for generating semantic-oriented REST interface consistency test cases according to any one of claims 1 to 5, characterized in that: The target test semantics file includes definition information of intended test response, intended test sequence, intended test parameter association relationship and test data semantics.

7. The method for generating semantic-oriented REST interface consistency test cases according to claim 6, characterized in that: Before obtaining the REST interface file, the class model file, the URI data of the system under test, and the target test semantics file describing the test semantics of the REST interface, the method further includes: The test semantics of the REST interface are lexically defined and grammatically defined by using the BNF paradigm, so that the target test semantics file is obtained based on the lexical definition and the grammatical definition.

8. A semantics-oriented REST interface consistency test case generation device, characterized in that: include: An acquisition module configured to acquire a REST interface file, a class model file, and URI data of a system under test, and a target test semantics file describing the test semantics of the REST interface; The first generation module is configured to perform static mapping and dynamic mapping based on the REST interface file, the class model file, the URI data and the target test semantic file to generate a target test case for the system under test.

9. 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 program, the method for generating semantic-oriented REST interface consistency test cases according to any one of claims 1 to 7 is implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for generating semantic-oriented REST interface consistency test cases according to any one of claims 1 to 7 is implemented.