Contract testing method and related device thereof
By obtaining and comparing the configuration information of the server and the provider, and generating hash values to test the running stability of the code, it solves the problem that the code is difficult to ensure stability when running in different environments in the existing technology, and achieves the effect of improving code development efficiency and reducing maintenance costs.
Patent Information
- Application Number
- CN202411643349.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-11-18
AI Technical Summary
The prior art is difficult to accurately determine whether the code will be tampered with when running in different environments, and it is impossible to know the reason for the error in the code running, which makes it difficult for the code to ensure operational stability in complex software systems.
By obtaining the configuration information of the server and the provider, a hash value is generated, and the test results of the contract test are generated based on the matching results of the hash value, testing the running 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 success rate of code running, improves the development efficiency of the code and reduces maintenance costs.
Smart Images

Figure CN119645839A_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, business logic becomes more complex, and not only functional correctness but also the interaction and collaboration between different components must be considered. Contract testing is a testing technique that focuses on testing the interaction and contracts between different software components or services.
[0003] In related technologies, when the code is executed in different operating environments, it may not run properly due to some configuration information in the environment. PACT (Product Assistant-Compatibility Testing) can be used to test the code in contract testing, but the current testing method cannot accurately determine whether the code has been tampered with when running in the environment, and cannot know the reason for the code running error. Summary of the invention
[0004] In order to solve or partially solve the problems existing in the related 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 code development efficiency 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, and generating a first test file at the server according to a target code, the first test file including the first configuration information of the server; obtaining a contract file generated by the target code at a provider, the contract file including second configuration information of the provider; 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 method 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: in response to a first input operation, obtaining first configuration information of the server and the target code; 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 method 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; 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 method 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 is used to query the first test result and the second test result according to preset classification parameters; and displaying the data report.
[0011] A 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 a provider, wherein the contract file includes second configuration information on the provider; 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 method 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 manner of the second aspect, the acquisition module is further used 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.
[0014] In combination with the second aspect, in a possible implementation of the second aspect, the acquisition module is also used to obtain the first configuration information and the target code of the server in response to the 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 also 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 according to 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 as 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 as 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, and generating a first test file at the server according to a target code, wherein the first test file includes the first configuration information of the server; obtaining a contract file generated by the target code at a provider, wherein the contract file includes second configuration information of the provider; 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 code development efficiency 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 It is a flowchart of a contract testing method shown in an embodiment of the present application;
[0027] Figure 2 Another schematic diagram of the contract testing method shown in the embodiment of the present application
[0028] Figure 3 is a schematic diagram of the structure of a contract testing device shown in an embodiment of the present application;
[0029] Figure 4 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, 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 only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms of "a", "a", "an" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more 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 the same type of information 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, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0033] In related technologies, when code is executed in different operating environments, it may not run properly due to some configuration information in the environment. PACT can be used to test the code in contract testing, but the current testing method cannot accurately determine whether the code has been tampered with when running in the environment, and cannot know the reason for the code running error.
[0034] In the current software development and deployment process, customized code often needs to be executed in different operating environments, including development, testing, and production environments. There are often differences in Python versions, libraries, dependencies, etc. in these environments, which may cause the code to fail to run properly or generate errors. By using PACT to test the code, you can test the compatibility and stability of the code in different environments, and find out which configuration information in the code is incompatible with the environment, so that you can modify the configuration information in the environment to improve the compatibility of the code with the environment.
[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 solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0037] Embodiment 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, wherein 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 the server. PACT can obtain the first configuration information of the server. The server can be a machine or a different environment from the provider. The target code can be input into PACT, and a first test file can be generated on the server according to the target code. It can be understood that there is no limit on the capacity and quality of the target code. The first test file generated according to the target code can contain several files different from the test file, such as word documents. In general, PACT is a contract testing tool that supports consumer (server) driven contract testing (Consumer-Driven Contracts, CDC). This testing mode emphasizes defining the contract between services from the perspective of consumers, and using this to drive the development of producers (providers). 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 environment information of the server, such as version information, database information, and dependent library information of the compiler of the server. The first configuration information may be included in the generated first test file. PACT may pre-record version information, database information, and dependent library information of all compilers. 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 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, the second configuration information of the provider side will be recorded. The second configuration information may include the compiler version information, database information, dependency 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, first configuration information and 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 it is found after matching that the first hash value and the second hash value are different, it can be considered that the first test file and the contract file are different, and the first test file may be tampered with, damaged, etc. 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, thereby inferring that there are differences between the environment of the server and the environment of the provider. 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, and generating 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; obtaining a contract file generated by the target code on a provider, wherein the contract file includes second configuration information of the provider; 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 influence of different environments on the success rate of the code running, improve the code development efficiency and reduce the maintenance cost.
[0051] Embodiment 2
[0052] Figure 2It is another flow chart of the contract testing method shown in the embodiment of the present application.
[0053] See also Figure 2 , a contract testing method, comprising:
[0054] S210: In response to the first input operation, obtaining first configuration information and target code of the server.
[0055] Specifically, PACT can be deployed on the server side. After the user deploys PACT on the user side, the target code can be input into PACT through the electronic device, and PACT can be operated to obtain the first configuration information of the server side. For example, after PACT is deployed on the server side, a UI interface can be generated, and a plurality of buttons and input boxes can be displayed on the UI interface. The user can input the target code into the input box so that PACT obtains the target code. The user can also click the "detect" button, and PACT can automatically obtain the first configuration information of the server side, such as the compiler version of the server side.
[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 acquiring 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 a possible implementation, target configuration information in the target code is obtained according to an 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, and 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. In general, 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. AST is usually constructed in the source code parsing stage to store structured information of the source code, which can be used in subsequent compilation stages such as semantic analysis, code conversion, and code generation.
[0060] Furthermore, PACT can parse the abstract syntax tree of the target code and identify all modules and packages imported in the target code. All data modules and data packages imported in the target code can be imported on the provider side. PACT can also traverse the function call chain and class inheritance relationship in the abstract syntax tree of the target code to generate a call path graph of the target code. PACT ensures the correct use of the function call sequence and dependency relationships in the target code by analyzing the call path, so that the target code can avoid problems such as path errors or circular dependencies on the server side. PACT can also identify the main program hooks in the target code, such as the __main__ block or key control logic functions. By analyzing the abstract syntax book, it can be checked whether these hook functions can be correctly executed on the server side, and these key hooks can be checked for environmental consistency to ensure that 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 configuration information of the two. If the target configuration information is different from the first configuration information, PACT can obtain a configuration update package that is the same as 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 it from the provider through a cloud network, or Bluetooth transmission, etc., which is not limited here. Further, PACT can upload the obtained first configuration information of the server to the cloud for storage, and further, 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, and the first hash value of the first test file and the 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 is different from the second configuration information, the first hash value is different from the second hash value, and when the first configuration information is the same as the second configuration information, 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 according to the matching result of the first hash value and the third hash value.
[0069] Specifically, after the hash value of the first test file and the contract file are matched and the first test result is generated, PACT can obtain the generation time of the first test file and the current time of the server, and compare the generation time with the current time. If the difference between the current time and the generation time is greater than a preset threshold, which can be 1h, 2h, etc., and is not limited here, the second test file is regenerated at the server according to the target code, and the third hash value of the second test file is generated according to the preset hash algorithm, and the first hash value is matched with the third hash value to generate the second test result. By generating the second test file and comparing the first hash value with the third hash value, PACT can periodically detect whether the file generated by the target code has problems according to the set time, and then determine whether the configuration information of the server has changed, and regularly detect the compatibility of the dependencies in the target code. Furthermore, the server may regularly update the configuration information, such as software upgrades, environmental changes, compiler changes, etc. After detecting that the configuration information of the server has changed, PACT can immediately start the above detection process, generate a second test file for the target code, and detect the compatibility of the target code 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, and 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 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. PACT can summarize the test results and generate reports. For example, a report file can be generated based on Openpyxl and JSON technology. The report can be displayed on the display of the server. There are multiple classification parameters on the report, such as hash values, environmental parameters, etc., and the corresponding report can be viewed according to the classification.
[0072] The contract testing method of the present application includes, in response to a first input operation, obtaining first configuration information and target code of a server, 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 a provider, the contract file including the second configuration information of the provider, 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 influence of different environments on the success rate of code running, improve the development efficiency of the code and reduce the maintenance cost.
[0073] Corresponding to the aforementioned application function implementation method embodiment, the present application also provides a contract testing device, an electronic device and corresponding embodiments.
[0074] Figure 3 It is a schematic diagram of the structure of the contract testing device shown in the embodiment of the present application.
[0075] See also Figure 3 , a contract testing device 300, including a test file generating module 310, an acquiring module 320, a hash value generating module 330, and a matching module 340. Among them:
[0076] The test file generation module 310 is used to obtain the 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. The target code can be input into PACT, and a first test file can be generated on the server according to the target code. It can be understood that there is no limit on the capacity and quality of the target code. The first test file generated according to the target code can include several files different from the test file, such as word documents and other files.
[0078] In a possible implementation, the test file generation module 310 is also 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 according to the matching result of the first hash value and the third hash value.
[0079] The acquisition module 320 is used to acquire the contract file corresponding to the target code on the provider end, and the contract file includes the second configuration information of the provider end.
[0080] Specifically, the provider 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.
[0081] In a possible implementation, the acquisition module 320 is also used to acquire target configuration information in the target code according to 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 acquire first configuration information and a target code of the server in response to the first input operation; generate a first test file according to the target code and the first configuration information.
[0084] The hash value generation module 330 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.
[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, first configuration information and 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 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.
[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 it is found after matching that the first hash value and the second hash value are different, it can be considered that the first test file and the contract file are different, and the first test file may be tampered with, damaged, etc. 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, thereby inferring that there are differences between the environment of the server and the environment of the provider. 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 according to 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 according to 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 influence of different environments on the success rate of code running, improve the development efficiency of the code and reduce the maintenance cost.
[0090] Regarding the device 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 schematic diagram of the structure 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. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0094] The memory 410 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage. Among them, ROM can store static data or instructions required by the processor 420 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 410 may include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and 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 laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0095] The memory 410 stores executable codes, and when the executable codes are processed by the processor 420 , the processor 420 can execute part or all of the methods described above.
[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, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A contract testing method, characterized in that: Applied to PACT, including: Acquire first configuration information of the 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; Acquire a contract file generated by the target code at the provider end, wherein the contract file includes second configuration information of the provider end; 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 first test result of the contract test is generated according to a matching result between the first Hash value and the second Hash value.
2. The method according to claim 1, characterized in that Also includes: Acquire 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, 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, it includes: According to the target configuration information, obtaining a configuration update package; The first configuration information of the server is updated according to the configuration update package.
4. The method according to claim 1, characterized in that The step of generating a 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: After generating a first test file on the server 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; 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; A second test result is generated according to a matching result between the first Hash value and the third Hash value.
6. The method according to claim 5, characterized in that Also includes: Generate 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 a preset classification parameter; Display the data report.
7. A contract testing device, characterized in that: include: A test file generation module, used for acquiring first configuration information of a server, and generating 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, used for acquiring a contract file corresponding to the target code on the provider side, wherein the contract file includes second configuration 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 is used 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.
8. 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 6 is implemented.
9. 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 execute the method according to any one of claims 1 to 6.
10. 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 as claimed in any one of claims 1 to 6.
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
Interface testing method and device, electronic equipment and medium
CN114666258A