A real-time, efficient and automated contract testing method and system

By introducing an execution engine and a rule checker into the contract testing framework, graphical management and batch execution of contract use cases are realized, which solves the problems of low test coverage and low execution efficiency in the existing technology, and improves test coverage and accuracy. degree, and supports real-time perception of changes in microservice interfaces, providing clear test reports and result queries.

CN112699022BActive Publication Date: 2024-10-18SHANDONG LUNENG SOFTWARE TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202011543616.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-24
Publication Date
2024-10-18
Estimated Expiration
2040-12-24

AI Technical Summary

Technical Problem

The existing contract testing framework lacks full-process management functions and cannot support the integrity and accuracy verification of complex response information. It has low test coverage, low execution efficiency, and lacks real-time perception and graphical operation interfaces, making test results inconvenient to query. and analysis.

Method used

The contract test case number is received through the execution engine, parsed into a unittest executable use case, and the rule checker is called for verification, and an analysis report is generated to realize graphical management and batch execution of contract use cases, and integrate Jenkins to achieve automated construction and real-time perception. Supports flexible configuration of response header and response body verification rules.

Benefits of technology

It improves test coverage and accuracy, realizes batch efficient execution and automated operation of contract use cases, provides clear test reports and result queries, supports real-time perception of microservice interface changes, and reduces test writing difficulty and human burden.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112699022B_ABST
    Figure CN112699022B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for real-time, efficient and automated contract testing, the method comprising: an execution engine receives a test request containing a plurality of contract test case numbers, and reads a plurality of contract test cases corresponding to each contract test case number from a database according to the plurality of contract test case numbers in the test request; the execution engine sends the plurality of contract test cases corresponding to each read contract test case number to a use case parser, so that the use case parser converts each contract test case into a unittest executable test case; the execution engine receives the plurality of unittest executable test cases sent by the use case parser, and verifies each unittest executable test case by calling a rule verifier to obtain a verification result for each contract test case.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automated testing technology, and in particular to a method and system for real-time and efficient automated contract testing. Background Art

[0002] Consumer-driven contract testing (CDC testing) is a test of the data format between service consumers and providers. The current contract testing framework is based on creating a contract document on the consumer side. The service provider will provide data in the corresponding format based on the created contract document and return it to the consumer. The contract check determines whether the data provided by the service provider matches the contract generated by the consumer.

[0003] The current contract testing framework has the following problems:

[0004] 1. Lack of full-process management functions for contract use cases, use case execution, execution records, and test reports.

[0005] 2. The data format verification is single and cannot support the verification of the integrity, accuracy, return value format and return value type of complex response information, resulting in low test coverage and low test data accuracy. Verification rules of different formats need to be generated through coding, which lacks flexibility.

[0006] 3. The current contract testing framework does not have real-time perception capabilities. Only manual testing can reveal the impact of changes to the microservice interface on all other users.

[0007] 4. Contract use cases cannot be executed in batches, and the execution efficiency is low. Use cases only support manual triggering and cannot meet the needs of automated build execution.

[0008] 5. The contract testing framework lacks a graphical operation interface, requires coding skills from testers, and the test results are output to the console and cannot be saved persistently, making it impossible to query historical results. The result output is not clear enough and has poor readability, which is not conducive to quickly locating problems. Summary of the invention

[0009] In order to solve the problems that existing testing tools have limited assertion types and cannot support the verification functions of response information integrity, return value format and return value type, open source contract testing frameworks have low efficiency and poor universality, microservice interface changes are difficult to control, and the verification cost after changes is huge, the present invention provides a real-time, efficient and automated contract testing method and system.

[0010] A real-time, efficient and automated contract testing method provided by an embodiment of the present invention includes:

[0011] The execution engine receives a test request including multiple contract test case numbers, and reads multiple contract test cases corresponding to each contract test case number from a database according to the multiple contract test case numbers in the test request;

[0012] The execution engine sends the multiple contract test cases corresponding to each contract test case number read to the use case parser, so that the use case parser converts each contract test case into a unittest executable test case;

[0013] The execution engine receives multiple unittest executable test cases sent by the use case parser, and verifies each unittest executable test case by calling the rule verifier to obtain the verification result of each contract test case.

[0014] Preferably, the contract test case includes one or more test steps, and each test step includes a test step name, an interface request, a response header check, and a response body format check.

[0015] Preferably, before the execution engine receives a test request including a plurality of contract test case numbers, it further includes:

[0016] Setting the execution trigger mode of the execution engine;

[0017] The triggering mode includes a manual triggering mode and an automatic triggering mode.

[0018] Preferably, before the execution engine receives a test request including a plurality of contract test case numbers, it further includes:

[0019] Configuring verification rules for the rule verifier;

[0020] The verification rules include response header verification rules and response body verification rules.

[0021] Preferably, the execution engine verifies each unittest executable test case by calling a rule verifier, and obtains the verification result of each contract test case including:

[0022] The execution engine verifies each unittest executable test case by calling the verification rules in the rule verifier to obtain the verification result, verification details and error information of each contract test case;

[0023] The execution engine generates an analysis report for each contract test case based on the verification results, verification details and error information of each contract test case.

[0024] A real-time, efficient and automated contract testing system provided according to an embodiment of the present invention includes:

[0025] An execution engine is used to receive a test request containing multiple contract test case numbers, and read multiple contract test cases corresponding to each contract test case number from a database according to the multiple contract test case numbers in the test request; send the multiple contract test cases corresponding to each contract test case number read to a use case parser; receive multiple unittest executable test cases sent by the use case parser, and verify each unittest executable test case by calling a rule verifier to obtain a verification result for each contract test case;

[0026] The use case parser is used to convert each contract test case into a unittest executable test case.

[0027] Preferably, the contract test case includes one or more test steps, and each test step includes a test step name, an interface request, a response header check, and a response body format check.

[0028] Preferably, the execution engine is further used to set an execution triggering mode of the execution engine;

[0029] The triggering mode includes a manual triggering mode and an automatic triggering mode.

[0030] Preferably, the execution engine is also used to configure verification rules for the rule verifier;

[0031] The verification rules include response header verification rules and response body verification rules.

[0032] Preferably, the execution engine is specifically used to perform verification processing on each unittest executable test case by calling the verification rules in the rule verifier, obtain the verification results, verification details and error information of each contract test case, and generate an analysis report for each contract case test based on the verification results, verification details and error information of each contract test case.

[0033] According to the solution provided by the embodiment of the present invention, web-visualized full-stack management and control is realized. The contract use cases, use case execution, execution records, and test reports are managed in a unified graphical manner, which improves the ease of use of the tool, reduces the difficulty of contract test writing, and solves the problem of the lack of management functions in the existing contract test framework. By transforming Pactverify, flexible and rich interface data verification rules are implemented. The verification problems of complex response information integrity, return value format and return value type are solved, and a higher test coverage rate is achieved. The integration with Jenkins realizes the rapid perception of the impact of service provider changes on service consumers. When a Service is called by multiple users at the same time, it ensures that the impact of service modifications on all other users is quickly perceived, and problems that violate the interface contract are discovered in time. Batch execution of contract use cases is realized based on unittest, and the execution efficiency is higher. In addition to manually triggered operation, it also supports unattended automated operation mode, liberating manpower and improving work efficiency through automated test construction. Provide rich and clear test reports. Through the test overview and test details, it is convenient to obtain test results, which helps developers and testers to quickly locate problems. Supports statistical analysis of test results. By summarizing and analyzing historical test results, it helps to understand the changing trends of test results and further analyze the quality of service interfaces. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to understand the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0035] Figure 1 This is a flow chart of a method for real-time, efficient and automated contract testing provided by an embodiment of the present invention;

[0036] Figure 2 is a system schematic diagram of a real-time, efficient and automated contract testing system provided by an embodiment of the present invention;

[0037] Figure 3 It is a flow chart of creating, testing and querying an automated contract testing tool provided by an embodiment of the present invention;

[0038] Figure 4 It is a use case execution logic architecture diagram provided by an embodiment of the present invention;

[0039] Figure 5 is a schematic diagram of a contract test report provided by an embodiment of the present invention;

[0040] Figure 6 is a functional structure diagram provided by an embodiment of the present invention;

[0041] Figure 7 It is a logic diagram for realizing the method of real-time, efficient and automated contract testing provided by an embodiment of the present invention;

[0042] Figure 8 is a schematic diagram of a use case set provided by an embodiment of the present invention;

[0043] Fig. 9 is a schematic diagram of a system for real-time, efficient, and automated contract testing provided by an embodiment of the present invention;

[0044] Fig.10 is a schematic diagram of an execution engine calling a rule checker provided by an embodiment of the present invention;

[0045] Fig.11 It is a schematic diagram of a test report provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described below are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0047] Figure 1 is a flow chart of a method for real-time, efficient and automated contract testing provided by an embodiment of the present invention. Figure 1 As shown, including:

[0048] Step S101: the execution engine receives a test request including multiple contract test case numbers, and reads multiple contract test cases corresponding to each contract test case number from a database according to the multiple contract test case numbers in the test request;

[0049] Step S102: the execution engine sends the multiple contract test cases corresponding to each contract test case number read to the use case parser, so that the use case parser converts each contract test case into a unittest executable test case;

[0050] Step S103: The execution engine receives multiple unittest executable test cases sent by the use case parser, and verifies each unittest executable test case by calling the rule verifier to obtain the verification result of each contract test case.

[0051] Preferably, the contract test case includes one or more test steps, and each test step includes a test step name, an interface request, a response header check, and a response body format check.

[0052] Preferably, before the execution engine receives a test request including a plurality of contract test case numbers, it further includes: setting an execution trigger mode of the execution engine; wherein the trigger mode includes a manual trigger mode and an automatic trigger mode.

[0053] Preferably, before the execution engine receives a test request including multiple contract test case numbers, it also includes: configuring verification rules for the rule verifier; wherein the verification rules include response header verification rules and response body verification rules.

[0054] Preferably, the execution engine verifies each unittest executable test case by calling the rule verifier, and obtains the verification result of each contract test case, including: the execution engine verifies each unittest executable test case by calling the verification rules in the rule verifier, and obtains the verification result, verification details and error information of each contract test case; the execution engine generates an analysis report for each contract case test based on the verification result, verification details and error information of each contract test case.

[0055] Figure 2 is a schematic diagram of a system for real-time, efficient and automated contract testing provided by an embodiment of the present invention. Figure 2 As shown, it includes: an execution engine 201, which is used to receive a test request containing multiple contract test case numbers, and read multiple contract test cases corresponding to each contract test case number from a database according to the multiple contract test case numbers in the test request; send the multiple contract test cases corresponding to each contract test case number read to a use case parser; receive multiple unittest executable test cases sent by the use case parser, and verify each unittest executable test case by calling a rule verifier to obtain a verification result for each contract test case; a use case parser 202, which is used to convert each contract test case into a unittest executable test case.

[0056] Preferably, the contract test case includes one or more test steps, and each test step includes a test step name, an interface request, a response header check, and a response body format check.

[0057] Preferably, the execution engine is also used to set the execution trigger mode of the execution engine; wherein the trigger mode includes a manual trigger mode and an automatic trigger mode.

[0058] Preferably, the execution engine is also used to configure verification rules for the rule verifier; wherein the verification rules include response header verification rules and response body verification rules.

[0059] Preferably, the execution engine is specifically used to perform verification processing on each unittest executable test case by calling the verification rules in the rule verifier, obtain the verification results, verification details and error information of each contract test case, and generate an analysis report for each contract case test based on the verification results, verification details and error information of each contract test case.

[0060] The technical solution of the present invention is described in detail below with reference to the accompanying drawings.

[0061] The present invention establishes a full-stack contract testing management method. It changes the traditional contract test case writing, execution and management methods, and uniformly customizes and analyzes the independently carried out contract cases, execution methods, and test reports, thereby reducing the complexity and workload of contract test coding, improving the efficiency of automated test execution, and realizing test automation and efficiency under microservices, solving the complexity of open source contract test framework function writing.

[0062] The present invention establishes a flexible and rich microservice interface response data verification method. It solves the verification problems of the integrity, accuracy, return value format, and return value type of complex interface data of microservices and micro-applications, greatly enhances the coverage of interface data testing, and improves the verification efficiency of interface data accuracy.

[0063] The present invention establishes a real-time perception method for contract testing. When a service is called by multiple users at the same time, it ensures that the impact of service modification on all other users is quickly perceived, and problems that violate the interface contract are discovered in time.

[0064] The present invention establishes a contract test automation operation mode, supports batch execution of contract use cases, and has higher execution efficiency. In addition to manual triggering operation, it also supports unattended automatic operation mode, liberating manpower and improving work efficiency through automated construction and testing.

[0065] The present invention establishes a method for querying test reports. Through the test overview and test details, the test results can be easily obtained, which helps developers and testers to quickly locate problems. The problem of poor readability of test reports and no historical report storage in the existing contract testing framework is solved. Test result statistical analysis is supported. By summarizing and analyzing historical test results, it is helpful to understand the changing trend of test results and then analyze the quality of microservice interfaces.

[0066] The present invention establishes a real-time, efficient and automated contract testing method. The technical solution mainly includes establishing a method for visualizing the entire process in web form by unifying and graphically managing contract use cases, use case executions, execution records and test reports; to achieve higher test coverage, a flexible and rich data verification rule implementation method is established through integration with Pactverify; a real-time and rapid perception method of the impact of service provider changes on service consumers is established through integration with Jenkins; to achieve batch execution of use cases and improve work efficiency, a contract test automation operation mode is established; and a method for querying test reports is established to solve the problem that test results cannot be saved for a long time and historical results cannot be queried. The creation, testing and query processes of the real-time, efficient and automated contract testing method are as follows: Figure 3 As shown, 1) create a use case set and contract use case according to the interface description; 2) configure verification rules; 3) set the use case execution trigger method; 4) parse the execution use case; 5) generate execution records and result details; 6) generate a contract test report; 7) historical data summary and analysis.

[0067] In response to the various technical requirements and problems mentioned above, the following technical solutions have been adopted to break through and solve them:

[0068] Create use case sets and contract use cases according to the interface description, and establish a full-stack control method for contract testing. Testers log in to the system, enter the contract test function module, and create use case sets according to the interface module. Select the use case set to add the contract use case, and fill in the contract use case content according to the service interface defined in the design phase. The contract use case is managed in a tree structure according to the actual system business and stored in the database in binary format. The contract use case content is in json format, including the request information, response information and verification rule information of the contract.

[0069] The content of the contract use case is as follows:

[0070]

[0071] The specific parameters are as follows:

[0072] Name is the name of the use case step;

[0073] Request is the request information, including the request address, request method, request header, etc. Validate is the response header verification information;

[0074] Contact is the response body verification information.

[0075] A contract use case can contain multiple interface contracts, which can be used flexibly according to specific scenarios. For example, if a microservice interface corresponds to multiple microservice consumers, multiple contract test steps can be set in the same use case, as shown below:

[0076]

[0077]

[0078] By configuring the response header and response body verification rules, a flexible and rich microservice interface response data verification method is established. Verify the response header and response body by configuring the verification rules. The response header verification rules are defined in the "validate" list. The verification rules are the comparison between the actual response header result and the expected result, including equal, less than, less than or equal to, greater than or equal to, greater than, and not equal. The response body verification rule is the comparison between the actual response body result and the expected result. It is implemented based on pactverify and defined in "contract". The verification rules include value matching, type matching, array type matching, regular matching, enumeration matching, and complex rule matching. The above rich verification rules realize the verification of the integrity of the response information, the return value format, and the return value type.

[0079] Establish a real-time perception method for contract testing, and establish a way to automate contract testing by setting the execution trigger method of the use case. Execute contract use cases in two ways: manual triggering and automatic triggering. Select the use case set or multiple use cases, and click "Execute" to trigger manually; add a contract test execution node through the Jenkins pipeline plug-in extension function, obtain the contract use case set created in the project through database query in the contract test execution node, and check the contract use case to be executed. Configure a scheduled trigger task or automatically trigger when the source code library changes. The contract test will be executed as the Jenkins pipeline runs, realizing automated continuous integration testing. Through frequent construction, packaging, and testing of the pipeline, problems that violate the interface contract are discovered in a timely manner to ensure that the impact of service modifications on all other users is quickly perceived.

[0080] Parse and execute contract use cases. Based on the unittest unit testing framework, read the selected contract use cases from the database, parse the request, parameters and verification rules of each step in the contract use case, generate unittest executable test cases, call PactVerify to verify the contract rules, and finally realize the automatic batch execution of contract tests. The use case execution logic architecture is as follows: Figure 4 shown.

[0081] Generate execution records and result details. After the use case is executed, the execution details (request information, response information), verification results generated by Pactverify (assertion information, error information), execution time, and executor are stored in the database. Assertion information includes assertion results and assertion statistics for each test step; error information includes use case execution errors and assertion errors.

[0082] Generate a contract test report. Figure 5 As shown in the figure, the system generates a contract test report based on the test details data generated in the background. The test report displays the test overview information, test step details, verification results and details, and error information. The test overview and test details can easily obtain the test results, helping developers and testers to quickly locate problems.

[0083] Based on the historical test details of the database, the project contract test summary information is generated to display the overall results and test result change trends of all microservice interface contracts under the project. This helps managers to conduct quality assessment and improve the R&D process.

[0084] Combine the following Figure 6-Figure 11 The present invention is described:

[0085] like Figure 7 As shown, the present invention mainly includes test cases, case parser, execution engine, Jenkins, rule checker, execution details and results, etc.

[0086] The use case management includes use case set and contract use case. The use case set is used to organize and manage contract use cases and classify test cases according to functional modules, business scenarios or processes. The use case set contains multiple independent contract use cases. Figure 6 As shown in the figure, each contract use case contains one or more test steps, separated by commas. The test steps include the test step name, interface request, response header verification, and response body format verification. Figure 8 .

[0087] Test case execution includes manual triggering and automatic execution. Users can manually trigger the execution engine to execute tests by selecting test cases through the browser interface, or they can trigger the execution engine to execute tests automatically by triggering a scheduled task through Jenkins. The execution engine receives the incoming test case number set, reads the test case content from the database according to the test case number, parses the test case content through the test case parser, and converts it into a unittest test case for the execution engine to call and execute. See Fig. 9 .

[0088] The execution engine calls the rule verifier (PactVerify module) to verify the verification rules defined in the use case. The verification rules return verification results, verification details, and error information. Fig.10 .

[0089] After the use case is executed, the execution engine stores the use case execution details, execution results, verification results, verification details, error information, executor, and execution time in the database. The system generates a contract test report based on the above data information returned by the execution engine. For report content, see Fig.11 .

[0090] By summarizing and counting the historical test results in the database, the overall test results of the project and the changing trends of the historical test results are generated, which helps managers to conduct quality assessments and improve the R&D process.

[0091] Although the present invention is described in detail above, the present invention is not limited thereto, and those skilled in the art can make various modifications based on the principles of the present invention. Therefore, all modifications made based on the principles of the present invention should be understood to fall within the protection scope of the present invention.

Claims

1. A real-time, efficient and automated contract testing method, characterized in that: include: The execution engine receives a test request including multiple contract test case numbers, and reads multiple contract test cases corresponding to each contract test case number from a database according to the multiple contract test case numbers in the test request; the contract test case content includes the contract case step name, request information, response information and verification rule information; wherein the request information includes the request address, request method and request header; the response information includes response header verification information and response body verification information; the verification rule information includes the response header and the response body; The execution engine sends the multiple contract test cases corresponding to each contract test case number read to the use case parser, so that the use case parser converts each contract test case into a unittest executable test case by parsing the request, parameter and verification rule of each step in each contract test case; The execution engine receives multiple unittest executable test cases sent by the use case parser, and verifies each unittest executable test case by calling the verification rules in the rule verifier, obtains the execution details of each contract test case, the verification results generated by pactverify, the execution time and the executor, and generates a test report for each contract use case test based on the execution details of each contract test case, the verification results generated by pactverify, the execution time and the executor; wherein the execution details include request information and response information; the verification results include assertion information and error information; the assertion information includes the assertion result and assertion statistics of each test step; the error information includes use case execution errors and assertion errors; The execution engine displays the test report of each contract case test, so that the tester can quickly locate the problem through the test overview and test details in the test report of each contract case test; Among them, the verification processing of each unittest executable test case by calling the verification rules in the rule verifier includes: the response header verification rule is defined in the response header verification information validate list, and the verification rule is a comparison between the actual response header result and the expected result, including equality, less than, less than or equal to, greater than or equal to, greater than, and unequal; the response body verification rule is a comparison between the actual response body result and the expected result, which is implemented based on pactverify and defined in the response body verification information contract. The verification rules include value matching, type matching, array type matching, regular matching, enumeration matching, and complex rule matching.

2. The method according to claim 1, characterized in that The contract test case includes one or more test steps, and each test step includes a test step name, an interface request, a response header check, and a response body format check.

3. The method according to claim 1, characterized in that Before the execution engine receives a test request including multiple contract test case numbers, the method further includes: Setting the execution trigger mode of the execution engine; The triggering mode includes a manual triggering mode and an automatic triggering mode.

4. The method according to claim 1, characterized in that: Before the execution engine receives a test request including multiple contract test case numbers, the method further includes: A validation rule is configured for the rule validator.

5. A real-time, efficient and automated contract testing system, characterized in that: include: An execution engine, configured to receive a test request including a plurality of contract test case numbers, and read a plurality of contract test cases corresponding to each contract test case number from a database according to the plurality of contract test case numbers in the test request; Send multiple contract test cases corresponding to each contract test case number read to the use case parser; receive multiple unittest executable test cases sent by the use case parser, and verify each unittest executable test case by calling the verification rules in the rule verifier to obtain the execution details of each contract test case, the verification results generated by pactverify, the execution time and the executor, and generate a test report for each contract use case test based on the execution details of each contract test case, the verification results generated by pactverify, the execution time and the executor; wherein, the execution details include request information and response information; the verification results include assertion information and error information; the assertion information includes the assertion result and assertion statistics of each test step; the error information includes use case execution errors and assertion errors; the contract test case content includes the contract use case step name, request information, response information and verification rule information; wherein, the request information includes the request address, request method and request header; the response information includes the response header verification information and the response body verification information; the verification rule information includes the response header and the response body; A test case parser is used to convert each contract test case into a unittest executable test case by parsing the request, parameters and verification rules of each step in each contract test case; The execution engine is further used to display the test report of each contract case test, so that the tester can quickly locate the problem through the test overview and test details in the test report of each contract case test; Among them, the verification processing of each unittest executable test case by calling the verification rules in the rule verifier includes: the response header verification rule is defined in the response header verification information validate list, and the verification rule is a comparison between the actual response header result and the expected result, including equality, less than, less than or equal to, greater than or equal to, greater than, and unequal; the response body verification rule is a comparison between the actual response body result and the expected result, which is implemented based on pactverify and defined in the response body verification information contract. The verification rules include value matching, type matching, array type matching, regular matching, enumeration matching, and complex rule matching.

6. The system according to claim 5, characterized in that The contract test case includes one or more test steps, and each test step includes a test step name, an interface request, a response header check, and a response body format check.

7. The system according to claim 5, characterized in that The execution engine is also used to set the execution trigger mode of the execution engine; The triggering mode includes a manual triggering mode and an automatic triggering mode.

8. The system according to claim 5, characterized in that The execution engine is also used to configure verification rules for the rule verifier.

Citation Information

Patent Citations

  • Automatic test method and automatic test system on basis of WEB interfaces

    CN106095673A

  • Test method and tool integration based on micro-service architecture

    CN110990262A

  • Distributed architecture-oriented micro-service contract management method and device, computer equipment and readable storage medium

    CN111176660A

  • Automated service testing

    US20090006897A1