Contract testing method and related device
By obtaining configuration information on the server and the provider side, generating hash values and matching, and using PACT tools to generate contract test files, the compatibility and stability of the code in different environments is solved, development efficiency is improved and maintenance costs are reduced.
Patent Information
- Application Number
- CN202411643349.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2044-11-18
AI Technical Summary
The existing contract testing methods cannot accurately determine whether the code will be tampered with when running in different environments, and cannot know the reason for the error in the code running, which makes it difficult to ensure the compatibility and stability of the code in different environments, affecting development efficiency and maintenance costs.
By obtaining the configuration information of the server and the provider, generating hash values and matching, using the PACT tool to generate contract test files, identifying configuration information differences and generating test results, providing configuration updates and report analysis, ensuring the stability of the code in different environments.
It improves the running stability of the code in different environments, reduces the impact of environmental differences on the code success rate, improves development efficiency and reduces maintenance costs.
Smart Images

Figure CN119645839B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a contract testing method and related devices. Background Art
[0002] In software testing, traditional testing methods focus on verifying the functional correctness of software components. However, as software systems become more complex and interconnected, and business logic becomes increasingly complex, it's crucial to consider not only functional correctness but also the interactions and collaborations between different components. Contract testing is a testing technique that focuses on testing the interactions and contracts between different software components or services.
[0003] In related technologies, when code is executed in different operating environments, it may not run properly due to certain configuration information in the environment. PACT (Prod Assistant-Compatibility Testing) can be used to test code during contract testing, but current testing methods cannot accurately determine whether the code has been tampered with when running in the environment, nor can they determine the cause of code errors. Summary of the Invention
[0004] In order to solve or partially solve the problems existing in the relevant technology, the present application provides a contract testing method and related devices, which can test the running stability of the code in different environments, reduce the impact of different environments on the success rate of code operation, improve the development efficiency of the code and reduce maintenance costs.
[0005] A first aspect of the present application provides a contract testing method, comprising obtaining first configuration information of a server side, and generating a first test file on the server side according to a target code, wherein the first test file includes the first configuration information of the server side; obtaining a contract file generated by the target code on the provider side, wherein the contract file includes the second configuration information of the provider side; generating a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information and the second configuration information; and generating a first test result of the contract test according to a matching result of the first hash value and the second hash value.
[0006] In combination with the first aspect, in a possible implementation method of the first aspect, it includes: obtaining target configuration information in the target code according to the abstract syntax tree of the target code; determining whether the target configuration information is consistent with the first configuration information; if the target configuration information is inconsistent with the first configuration information, generating a warning message.
[0007] In combination with the first aspect, in a possible implementation of the first aspect, if the target configuration information is inconsistent with the first configuration information, it includes: obtaining a configuration update package according to the target configuration information; and updating the first configuration information of the server according to the configuration update package.
[0008] In combination with the first aspect, in a possible implementation of the first aspect, generating a test file based on the target code includes: obtaining first configuration information of the server and the target code in response to a first input operation; and generating the first test file based on the target code and the first configuration information.
[0009] In combination with the first aspect, in a possible implementation of the first aspect, after generating a first test file on the server according to the target code, it also includes obtaining the generation time of the first test file and the current time of the server; if the difference between the current time and the generation time is greater than a preset threshold, generating a second test file according to the target code and generating a third hash value of the second test file; and generating a second test result based on the matching result of the first hash value and the third hash value.
[0010] In combination with the first aspect, in a possible implementation of the first aspect, it also includes: generating a data report based on the first test result and the second test result, the data report being used to query the first test result and the second test result based on preset classification parameters; and displaying the data report.
[0011] The second aspect of the present application provides a contract testing device, including a test file generation module, which is used to obtain first configuration information of a server and generate a first test file on the server according to a target code, wherein the first test file includes the first configuration information of the server; an acquisition module, which is used to obtain a contract file corresponding to the target code on the provider side, wherein the contract file includes the second configuration information of the provider side; a hash value generation module, which is used to generate a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information and the second configuration information; and a matching module, which is used to generate a first test result of the contract test according to the matching result of the first hash value and the second hash value.
[0012] In combination with the second aspect, in a possible implementation of the second aspect, the acquisition module is also used to obtain target configuration information in the target code based on the abstract syntax tree of the target code; determine whether the target configuration information is consistent with the first configuration information; if the target configuration information is inconsistent with the first configuration information, generate a warning message.
[0013] In combination with the second aspect, in a possible implementation of the second aspect, the acquisition module is further used to obtain a configuration update package according to the target configuration information; and update the first configuration information of the server according to the configuration update package.
[0014] In combination with the second aspect, in a possible implementation of the second aspect, the acquisition module is further used to obtain the first configuration information and the target code of the server in response to a first input operation; and generate the first test file according to the target code and the first configuration information.
[0015] In combination with the second aspect, in a possible implementation of the second aspect, the test file generation module is further used to obtain the generation time of the first test file and the current time of the server; if the difference between the current time and the generation time is greater than a preset threshold, a second test file is generated according to the target code, and a third hash value of the second test file is generated; and a second test result is generated based on the matching result of the first hash value and the third hash value.
[0016] In combination with the second aspect, in a possible implementation of the second aspect, the matching module is also used to generate a data report based on the first test result and the second test result, and the data report is used to query the first test result and the second test result according to preset classification parameters; and display the data report.
[0017] A third aspect of the present application provides an electronic device, including:
[0018] processor; and
[0019] The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method described above.
[0020] A fourth aspect of the present application provides a computer-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor is caused to execute the method described above.
[0021] A fifth aspect of the present application provides a computer program product, comprising a computer program / instruction, which implements the method described above when executed by a processor.
[0022] The technical solution provided by this application may have the following beneficial effects:
[0023] The contract testing method and related devices of the present application include obtaining first configuration information of a server side, and generating a first test file on the server side according to a target code, wherein the first test file includes the first configuration information of the server side; obtaining a contract file generated by the target code on the provider side, wherein the contract file includes the second configuration information of the provider side; generating a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information and the second configuration information; generating a first test result of the contract test according to a matching result of the first hash value and the second hash value, which can test the running stability of the code in different environments, reduce the impact of different environments on the success rate of code running, improve the development efficiency of the code and reduce maintenance costs.
[0024] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The above and other objects, features and advantages of the present application will become more apparent by describing in more detail exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.
[0026] Figure 1 1 is a flow chart of a contract testing method according to an embodiment of the present application;
[0027] Figure 2 This is another flow chart of the contract testing method shown in the embodiment of the present application.
[0028] Figure 3 is a schematic structural diagram of a contract testing device shown in an embodiment of the present application;
[0029] Figure 4 It is a structural diagram of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The following describes embodiments of the present application in more detail with reference to the accompanying drawings. Although the accompanying drawings illustrate embodiments of the present application, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. Rather, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0031] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms "a," "an," and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0032] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0033] In related technologies, when code is executed in different environments, it may not function properly due to certain configuration information in the environment. PACT can be used to test code in contract testing, but current testing methods cannot accurately determine whether the code has been tampered with when running in the environment, nor can they determine the cause of the code running errors.
[0034] In current software development and deployment, customized code often needs to be executed in different environments, including development, testing, and production. These environments often have different Python versions, libraries, and dependencies, which can cause code to malfunction or generate errors. Using PACT to test code compatibility and stability in different environments can also help identify incompatibilities between the code and the environment's configuration. This allows for configuration changes to improve compatibility.
[0035] In response to the above problems, the present application provides a contract testing method and related devices, which can test the running stability of the code in different environments, reduce the impact of different environments on the success rate of code operation, improve the development efficiency of the code and reduce maintenance costs.
[0036] The technical solutions of the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0037] Example 1
[0038] Figure 1 It is a flow chart of the contract testing method shown in the embodiment of the present application.
[0039] See also Figure 1 , a contract testing method, applied to PACT, including:
[0040] S110: Acquire first configuration information of the server, and generate a first test file on the server according to the target code, where the first test file includes the first configuration information of the server.
[0041] Specifically, PACT can be a testing tool. Users can install PACT on a server. PACT can obtain first configuration information from the server, which can be a machine or environment different from the provider. Target code can be entered into PACT, and a first test file is generated on the server based on the target code. It is understood that there are no restrictions on the size or quality of the target code. The first test file generated based on the target code can contain several files distinct from the test file, such as Word documents. Generally, PACT is a contract testing tool that supports consumer-driven contract testing (CDC). This testing model emphasizes defining inter-service contracts from the perspective of the consumer, which in turn drives the development of the producer (provider). PACT ensures that both parties have consistent expectations for interaction by allowing consumers and service producers to define clear interaction contracts.
[0042] Specifically, the first configuration information may include server-side environment information, such as server-side compiler version information, database information, and dependent library information. The first configuration information may be included in the generated first test file. PACT may pre-record all compiler version information, database information, and dependent library information. Furthermore, the first configuration information may be compared with the configuration information in PACT to ensure that the configuration information included in the first configuration information exists in PACT.
[0043] S120: Acquire a contract file generated by the target code at the provider end, where the contract file includes second configuration information of the provider end.
[0044] Specifically, the provider side can be the input side or generation side of the target code. For example, the user can compile the target code in the provider environment and generate a contract file for the target code at the provider. PACT can obtain the contract file generated by the target code at the provider. Each target code can have a corresponding contract file. When the target code changes, the corresponding contract file will also change. The contract file can be a JSON file.
[0045] Specifically, when the target code generates a contract file on the provider side, it will record the second configuration information of the provider side. The second configuration information may include the compiler version information, database information, dependent library information, etc. of the provider side. The contract file may include the corresponding compiler version information, etc.
[0046] S130: Generate a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information, and the second configuration information.
[0047] Specifically, a unique hash value of the first test file and a unique hash value of the contract file can be generated through a hash algorithm, the first configuration information and the second configuration information. The first hash value and the second hash value can be the same or different. The hash algorithm can be SHA-256 or SHA-512, etc.
[0048] S140: Generate a first test result of the contract test according to the matching result of the first hash value and the second hash value.
[0049] Specifically, after generating unique hash values for the first test file and the contract file, respectively, the first hash value and the second hash value can be matched to generate a first test result. If, after matching, the first hash value and the second hash value are found to be different, it can be considered that the first test file and the contract file are different, and the first test file may have been tampered with or damaged. PACT can mark the first test file at this time, and the mark is used to indicate that there is an operation risk for the first test file. Furthermore, when the first configuration information and the second configuration information are different, the first hash value and the second hash value may be different. From this, it can be inferred that there is a difference between the server environment and the provider environment. For example, the compiler version of the server is different from the compiler version of the provider, resulting in the target code being incompatible with the compiler version of the server.
[0050] The contract testing method of the present application includes obtaining first configuration information of a server side, and generating a first test file on the server side according to a target code, wherein the first test file includes the first configuration information of the server side; obtaining a contract file generated by the target code on the provider side, wherein the contract file includes second configuration information of the provider side; generating a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information, and the second configuration information; generating a first test result of the contract test according to a matching result of the first hash value and the second hash value, which can test the running stability of the code in different environments, reduce the impact of different environments on the success rate of the code running, improve the development efficiency of the code, and reduce maintenance costs.
[0051] Example 2
[0052] Figure 2This is another flowchart of the contract testing method shown in an embodiment of the present application.
[0053] See also Figure 2 , a contract testing method, comprising:
[0054] S210: In response to the first input operation, obtain first configuration information and target code of the server.
[0055] Specifically, PACT can be deployed on a server. After a user deploys PACT on a user, they can input the target code into PACT via an electronic device and operate PACT to obtain the server's first configuration information. For example, after PACT is deployed on the server, a UI interface can be generated, displaying multiple buttons and input boxes. The user can enter the target code into the input boxes, causing PACT to retrieve the target code. The user can also click a "Detect" button, causing PACT to automatically retrieve the server's first configuration information, such as the server's compiler version.
[0056] S220: Generate a first test file according to the target code and the first configuration information, where the first test file includes the first configuration information of the server.
[0057] Specifically, after obtaining the target code and the first configuration information, PACT can simulate the first configuration information of the server and generate a first test file according to the target code. At this time, the information of the first test file includes the first configuration information.
[0058] In one possible implementation, target configuration information in the target code is obtained according to the abstract syntax tree of the target code; whether the target configuration information is consistent with the first configuration information is determined; if the target configuration information is inconsistent with the first configuration information, a warning message is generated.
[0059] Specifically, the target code is compiled at the provider end, and the target code may contain the configuration information of the provider end. PACT can obtain the target configuration information in the target code by parsing the abstract syntax tree of the target code. The target configuration information may be the same as the second configuration information of the provider end. PACT can compare the target configuration information with the first configuration information at the server end. If the target configuration information is different from the first configuration information, a warning message may be generated, such as a warning message generated on the screen. Generally, an Abstract Syntax Tree (AST) is a tree-like representation of the abstract syntax structure of the source code. In compilation theory, it is used to represent the source code of a programming language. The AST is usually constructed during the source code parsing stage to store structured information of the source code. This information can be used in subsequent compilation stages such as semantic analysis, code conversion, and code generation.
[0060] Furthermore, PACT can parse the target code's abstract syntax tree (AST) to identify all modules and packages imported into the target code. All data modules and data packages imported into the target code may have been imported on the provider side. PACT can also traverse the function call chains and class inheritance relationships in the target code's AST to generate a call path graph for the target code. By analyzing the call path, PACT ensures the correct use of function call order and dependencies in the target code, preventing the target code from encountering path errors or circular dependencies on the server side. PACT can also identify main program hooks in the target code, such as the __main__ block or key control logic functions. By analyzing the AST, PACT can check whether these hook functions can be correctly executed on the server side, and perform environmental consistency checks on these key hooks to ensure they are correctly started on different servers.
[0061] Specifically, after obtaining the target configuration information of the target code and the first configuration information of the server, PACT can compare the two configuration information. If the target configuration information is different from the first configuration information, PACT can obtain a configuration update package to update the first configuration information. The updated first configuration information is the same as the target configuration information. For example, when the server cannot connect to the Internet, the corresponding configuration update package can be directly retrieved from PACT to update the server. When the server can connect to the Internet, PACT can obtain the configuration update package from the cloud server and update the first configuration information of the server.
[0062] S230: Acquire a contract file generated by the target code at the provider end, where the contract file includes second configuration information of the provider end.
[0063] Specifically, PACT can obtain the contract file generated by the target code from the provider. For example, PACT can obtain the contract file from the provider via a cloud network or Bluetooth transmission, etc. (this is not limited here). Furthermore, PACT can upload the obtained first configuration information of the server to the cloud for storage. Furthermore, PACT can use the HTTPS protocol to ensure data security.
[0064] S240: Generate a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information, and the second configuration information.
[0065] Specifically, the preset hash algorithm may be SHA-256 or SHA-512. A first hash value of the first test file and a second test value of the contract file are generated by the hash algorithm. The first hash value may match the first configuration information, and the second hash value may match the second configuration information. Furthermore, when the first configuration information and the second configuration information are different, the first hash value and the second hash value are different. When the first configuration information and the second configuration information are the same, the second hash value may be the same as the second hash value.
[0066] S250: Generate a first test result of the contract test according to the matching result of the first hash value and the second hash value.
[0067] Specifically, the first test result can record the matching result of the first hash value and the second hash value, and can also record the difference in configuration information between the server and the provider, code dependency analysis of the target code, call path detection, main program hook detection and other information.
[0068] In one possible implementation, the generation time of the first test file and the current time of the server are obtained; if the difference between the current time and the generation time is greater than a preset threshold, a second test file is generated according to the target code, and a third hash value of the second test file is generated; and a second test result is generated based on the matching result of the first hash value and the third hash value.
[0069] Specifically, after hash matching the first test file and the contract file and generating a first test result, PACT can obtain the generation time of the first test file and compare it with the current time on the server. If the difference between the generation time and the current time is greater than a preset threshold (which can be 1 hour, 2 hours, etc., but is not limited here), a second test file is regenerated based on the target code on the server. A third hash value of the second test file is generated using a preset hash algorithm. The first hash value is then matched with the third hash value to generate a second test result. By generating the second test file and comparing the first and third hash values, PACT can periodically check for issues with the files generated by the target code at a set time, thereby determining whether the server's configuration information has changed, and regularly checking the compatibility of dependencies in the target code. Furthermore, the server may periodically update its configuration information, such as due to software upgrades, environment changes, or compiler changes. Upon detecting a change in the server's configuration information, PACT can immediately initiate the aforementioned detection process, generating a second test file for the target code to test its compatibility with the updated server.
[0070] In a possible implementation, a data report is generated according to the first test result and the second test result, where the data report is used to query the first test result and the second test result according to preset classification parameters; and the data report is displayed.
[0071] Specifically, both the first test result and the second test result can record the differences in configuration information between the server and the provider, code dependency analysis of the target code, call path detection, main program hook detection and other information. PACT can summarize the test results and generate reports. For example, it can generate report files based on Openpyxl and JSON technology. The report can be displayed on the server's display. There are multiple classification parameters on the report, such as hash values, environment parameters, etc., and the corresponding report can be viewed according to the classification.
[0072] The contract testing method of the present application includes obtaining first configuration information and target code of the server in response to a first input operation, generating a first test file according to the target code and the first configuration information, the first test file including the first configuration information of the server, obtaining a contract file generated by the target code at the provider end, the contract file including the second configuration information of the provider end, generating a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information and the second configuration information, generating a first test result of the contract test according to the matching result of the first hash value and the second hash value, which can test the running stability of the code in different environments, reduce the impact of different environments on the success rate of code running, improve the development efficiency of the code and reduce maintenance costs.
[0073] Corresponding to the aforementioned application function implementation method embodiment, the present application also provides a contract testing device, electronic equipment and corresponding embodiments.
[0074] Figure 3 It is a structural diagram of a contract testing device shown in an embodiment of the present application.
[0075] See also Figure 3 A contract testing device 300 includes a test file generating module 310, an acquiring module 320, a hash value generating module 330, and a matching module 340.
[0076] The test file generation module 310 is configured to obtain first configuration information of the server and generate a first test file on the server according to the target code. The first test file includes the first configuration information of the server.
[0077] Specifically, PACT can be a testing tool. A user can install PACT on a server. PACT can obtain first configuration information of the server. The server can be a machine different from the provider or a different environment. Target code can be input into PACT, and a first test file can be generated on the server based on the target code. It is understood that there is no limit to the size or quality of the target code. The first test file generated based on the target code can include multiple files different from the test file, such as Word documents.
[0078] In one possible implementation, the test file generation module 310 is further configured to obtain the generation time of the first test file and the current time of the server; if the difference between the current time and the generation time is greater than a preset threshold, a second test file is generated according to the target code, and a third hash value of the second test file is generated; and a second test result is generated based on the matching result of the first hash value and the third hash value.
[0079] The acquisition module 320 is used to obtain the contract file corresponding to the target code on the provider end, where the contract file includes the second configuration information of the provider end.
[0080] Specifically, the provider side can be the input side or generation side of the target code. For example, the user can compile the target code in the provider side environment and generate a contract file for the target code at the provider side. PACT can obtain the contract file generated by the target code at the provider side. Each target code can have a corresponding contract file. When the target code changes, the corresponding contract file will also change.
[0081] In one possible implementation, the acquisition module 320 is also used to obtain target configuration information in the target code based on the abstract syntax tree of the target code; determine whether the target configuration information is consistent with the first configuration information; and generate a warning message if the target configuration information is inconsistent with the first configuration information.
[0082] In a possible implementation, the acquisition module 320 is further configured to acquire a configuration update package according to the target configuration information; and update the first configuration information of the server according to the configuration update package.
[0083] In a possible implementation, the acquisition module 320 is further configured to obtain the first configuration information and target code of the server in response to the first input operation; generate the first test file according to the target code and the first configuration information.
[0084] The hash value generation module 330 is configured to generate a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information, and the second configuration information.
[0085] Specifically, a unique hash value of the first test file and a unique hash value of the contract file can be generated through a hash algorithm, the first configuration information and the second configuration information. The first hash value and the second hash value can be the same or different. The hash algorithm can be SHA-256 or SHA-512, etc.
[0086] The matching module 340 is configured to generate a first test result of the contract test according to a matching result between the first hash value and the second hash value.
[0087] Specifically, after generating unique hash values for the first test file and the contract file, respectively, the first hash value and the second hash value can be matched to generate a first test result. If, after matching, the first hash value and the second hash value are found to be different, it can be considered that the first test file and the contract file are different, and the first test file may have been tampered with or damaged. PACT can mark the first test file at this time, and the mark is used to indicate that there is an operation risk for the first test file. Furthermore, when the first configuration information and the second configuration information are different, the first hash value and the second hash value may be different. From this, it can be inferred that there is a difference between the server environment and the provider environment. For example, the compiler version of the server is different from the compiler version of the provider, resulting in the target code being incompatible with the compiler version of the server.
[0088] In a possible implementation, the matching module 340 is further configured to generate a data report based on the first test result and the second test result, where the data report is used to query the first test result and the second test result based on preset classification parameters; and display the data report.
[0089] The contract testing device of the present application includes obtaining first configuration information of the server side, and generating a first test file on the server side according to the target code, the first test file including the first configuration information of the server side; obtaining a contract file generated by the target code on the provider side, the contract file including the second configuration information of the provider side; generating a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information and the second configuration information; generating a first test result of the contract test according to the matching result of the first hash value and the second hash value, which can test the running stability of the code in different environments, reduce the impact of different environments on the success rate of code operation, improve the development efficiency of the code and reduce maintenance costs.
[0090] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated again here.
[0091] Figure 4 It is a structural diagram of an electronic device shown in an embodiment of the present application.
[0092] See also Figure 4 , the electronic device 300 includes a memory 410 and a processor 420 .
[0093] The processor 420 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0094] Memory 410 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage. ROM may store static data or instructions required by processor 420 or other modules of the computer. Permanent storage may be a readable and writable storage device. A permanent storage device may be a non-volatile storage device that retains stored instructions and data even when the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (e.g., a magnetic or optical disk, flash memory) as the permanent storage device. In other embodiments, the permanent storage device may be a removable storage device (e.g., a floppy disk, optical drive). System memory may be a readable and writable storage device or a volatile readable and writable storage device, such as dynamic random access memory. System memory may store some or all instructions and data required by the processor during operation. In addition, memory 410 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (e.g., DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and magnetic disks and / or optical disks may also be used. In some embodiments, the memory 410 may include a readable and / or writable removable storage device, such as a compact disc (CD), a read-only digital versatile disc (e.g., DVD-ROM, dual-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. Computer-readable storage media do not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0095] The memory 410 stores executable codes. When the executable codes are processed by the processor 420 , the processor 420 may execute part or all of the above-mentioned methods.
[0096] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.
[0097] Alternatively, the present application can also be implemented as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) on which executable code (or computer program or computer instruction code) is stored. When the executable code (or computer program or computer instruction code) is executed by a processor of an electronic device (or server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.
[0098] The embodiments of the present application have been described above. The above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is selected to best explain the principles of the embodiments, their practical applications, or improvements to the technology in the market, or to enable other persons skilled in the art to understand the embodiments disclosed herein.
Claims
1. A contract testing method, characterized in that: Applied to PACT, including: Obtaining first configuration information of the server, and generating a first test file on the server according to the target code, wherein the first test file includes the first configuration information of the server, and the first configuration information includes version information, database information, and dependent library information of a compiler on the server; Obtaining a contract file generated by the target code on the provider side, the contract file including second configuration information of the provider side, the second configuration information including compiler version information, database information, and dependent library information of the provider side; Generate a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information, and the second configuration information; Generate a first test result of the contract test according to a matching result between the first hash value and the second hash value; After generating a first test file on the server side according to the target code, the method further includes: obtaining the generation time of the first test file and the current time of the server side; if the difference between the current time and the generation time is greater than a preset threshold, generating a second test file according to the target code and generating a third hash value of the second test file; and generating a second test result based on the matching result of the first hash value and the third hash value.
2. The method according to claim 1, characterized in that Also includes: Obtaining target configuration information in the target code according to an abstract syntax tree of the target code; Determining whether the target configuration information is consistent with the first configuration information; If the target configuration information is inconsistent with the first configuration information, a warning message is generated.
3. The method according to claim 2, characterized in that If the target configuration information is inconsistent with the first configuration information, the method includes: Obtaining a configuration update package according to the target configuration information; The first configuration information of the server is updated according to the configuration update package.
4. The method according to claim 1, wherein The generating of the test file according to the target code includes: In response to a first input operation, obtaining first configuration information of the server and the target code; The first test file is generated according to the target code and the first configuration information.
5. The method according to claim 1, characterized in that Also includes: generating a data report according to the first test result and the second test result, wherein the data report is used to query the first test result and the second test result according to preset classification parameters; Display the data report.
6. A contract testing device, characterized in that: include: a test file generation module, configured to obtain first configuration information of a server and generate a first test file on the server according to the target code, wherein the first test file includes the first configuration information of the server, and the first configuration information includes version information of a compiler, database information, and dependency library information of the server; An acquisition module, configured to acquire a contract file corresponding to the target code on the provider side, wherein the contract file includes second configuration information of the provider side, and the second configuration information includes compiler version information, database information, and dependent library information of the provider side; a hash value generation module, configured to generate a first hash value of the first test file and a second hash value of the contract file according to a preset hash algorithm, the first configuration information, and the second configuration information; a matching module, configured to generate a first test result of the contract test according to a matching result between the first hash value and the second hash value; After generating a first test file on the server side according to the target code, the method further includes: obtaining the generation time of the first test file and the current time of the server side; if the difference between the current time and the generation time is greater than a preset threshold, generating a second test file according to the target code and generating a third hash value of the second test file; and generating a second test result based on the matching result of the first hash value and the third hash value.
7. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.
8. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to perform the method according to any one of claims 1 to 5.
9. A computer-readable storage medium, characterized in that An executable code is stored thereon, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Verification method and device for mirror image file, electronic equipment and storage medium
CN113342745A
Data comparison method and device based on Hash algorithm, equipment and storage medium
CN114020813A