Assertion method, device, computer equipment, storage medium and program product

By injecting intercept bytecode into the initial bytecode of the interface, a target bytecode file is generated to intercept and process messages. This solves the problems of large workload and poor stability caused by source code modification in the existing technology, and realizes a more efficient and stable interface assertion.

CN114661599BActive Publication Date: 2026-06-26INDUSTRIAL AND COMMERCIAL BANK OF CHINA

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
INDUSTRIAL AND COMMERCIAL BANK OF CHINA
Filing Date
2022-03-22
Publication Date
2026-06-26

Smart Images

  • Figure CN114661599B_ABST
    Figure CN114661599B_ABST
Patent Text Reader

Abstract

The application relates to an assertion method and device, a computer device, a storage medium and a program product, and belongs to the technical field of artificial intelligence. The method comprises the following steps: intercepting and processing a message sent by a test script to a called interface to obtain first intercepted data; intercepting and processing the message received by the interface through a target bytecode file corresponding to the interface to obtain second intercepted data, wherein the target bytecode file is obtained by injecting an intercepted bytecode into initial bytecode obtained by compiling source code of the interface, and the intercepted bytecode is used for intercepting and processing the message; and performing interface assertion processing based on the first intercepted data and the second intercepted data. The method can reduce the workload of assertion and improve the stability of the called interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to an assertion method, apparatus, computer device, storage medium, and program product. Background Technology

[0002] To ensure the accuracy of program execution, assertions are needed to verify the program's operation. Assertions are a means of verifying the program during testing. To guarantee the accuracy and completeness of testing, in cross-application interface scheduling, in addition to asserting the execution of the application itself, it is also necessary to assert the data interaction between applications. Data interaction assertions include message assertions, which refer to asserting the messages sent by one application and the messages received by the called interface in another application. Existing technologies for asserting data interaction primarily involve modifying the source code of the called interface to obtain the messages received by the called interface. However, modifying the source code is labor-intensive and can lead to poor application stability. Summary of the Invention

[0003] Therefore, it is necessary to provide an assertion method, apparatus, computer device, storage medium, and program product to address the aforementioned technical problems.

[0004] Firstly, this application provides an assertion method, which includes: intercepting and processing messages sent by a test script to a called interface to obtain first intercepted data; intercepting and processing messages received by the interface through a target bytecode file corresponding to the interface to obtain second intercepted data, wherein the target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the source code of the interface, and the intercepted bytecode is used to intercept and process messages; and performing interface assertion processing based on the first intercepted data and the second intercepted data.

[0005] In one embodiment, the first intercepted data includes multiple first messages sent by the test script and call-related information corresponding to each first message, and the second intercepted data includes multiple second messages received by the interface and call-related information corresponding to each second message. Interface assertion processing is performed based on the first intercepted data and the second intercepted data, including: matching the first messages in the first intercepted data and the second messages in the second intercepted data based on the call-related information in the first intercepted data and the second intercepted data; and performing interface assertion processing based on the mutually matched first messages and second messages.

[0006] In one embodiment, based on the call-related information in the first intercepted data and the second intercepted data, a matching process is performed on the first message in the first intercepted data and the second message in the second intercepted data, including: determining the first message and the second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matched first messages and second messages.

[0007] In one embodiment, the relevant information includes the pass-through parameters carried by the message and the interface information of the call interface corresponding to the message; wherein, the pass-through parameters are pre-assigned to the message based on the test script.

[0008] In one embodiment, interface assertion processing is performed based on a first and a second message that match each other, including: determining the target field name; and detecting whether the field content corresponding to the target field name in the first and second messages that match each other is the same.

[0009] In one embodiment, interface assertion processing is performed based on a first and a second message that match each other, including: determining the expected value of a target field in the database based on at least one of the first and second messages that match each other; and detecting whether the actual value of the target field in the database is the same as the expected value.

[0010] In one embodiment, interface assertion processing based on first intercepted data and second intercepted data includes: after a preset assertion time is reached, performing interface assertion processing based on first intercepted data and second intercepted data.

[0011] Secondly, this application also provides an assertion device, comprising: a first interception module for intercepting and processing messages sent by a test script to a called interface to obtain first interception data; a second interception module for intercepting and processing messages received by the interface through a target bytecode file corresponding to the interface to obtain second interception data, wherein the target bytecode file is obtained by injecting interception bytecode into the initial bytecode obtained by compiling the source code of the interface, and the interception bytecode is used to intercept and process messages; and an assertion module for performing interface assertion processing based on the first interception data and the second interception data.

[0012] In one embodiment, the first intercept data includes multiple first messages sent by the test script and call-related information corresponding to each first message, and the second intercept data includes multiple second messages received by the interface and call-related information corresponding to each second message. The assertion module is specifically used to: perform matching processing on the first messages in the first intercept data and the second messages in the second intercept data based on the call-related information in the first intercept data and the second intercept data; and perform interface assertion processing based on the mutually matched first messages and second messages.

[0013] In one embodiment, based on the call-related information in the first intercepted data and the second intercepted data, the assertion module is specifically used to: determine the first message and the second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matching first messages and second messages.

[0014] In one embodiment, the relevant information includes the pass-through parameters carried by the message and the interface information of the call interface corresponding to the message; wherein, the pass-through parameters are pre-assigned to the message based on the test script.

[0015] In one embodiment, the assertion module is specifically used to: determine the target field name; and detect whether the field content corresponding to the target field name in the first and second matching messages is the same.

[0016] In one embodiment, the assertion module is specifically configured to: determine the expected value of a target field in the database based on at least one of a first message and a second message that match each other; and detect whether the actual value of the target field in the database is the same as the expected value.

[0017] In one embodiment, the assertion module is specifically used to: after a preset assertion time is reached, perform an interface assertion process based on the first interception data and the second interception data.

[0018] Thirdly, this application also provides a computer device, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of the method described in any of the first aspects above.

[0019] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any of the first aspects above.

[0020] Fifthly, this application also provides a computer program product. This computer program product includes a computer program that, when executed by a processor, implements the steps of the method described in any of the first aspects above.

[0021] The beneficial effects of the technical solutions provided in this application include at least the following:

[0022] In this embodiment, the messages sent by the test script to the called interface are intercepted to obtain first intercepted data. Then, the messages received by the interface are intercepted using the target bytecode file corresponding to the interface to obtain second intercepted data. Finally, interface assertion processing is performed based on the first and second intercepted data. The target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the interface's source code. The intercepted bytecode is used to intercept messages. Therefore, in this embodiment, intercepted bytecode is injected into the initial bytecode corresponding to the interface to obtain the target bytecode file, and then the target bytecode file is used to intercept messages received by the interface. Compared to intercepting messages received by the interface by modifying the interface's source code, this embodiment reduces the workload of assertions and improves the stability of the called interface by injecting intercepted bytecode into the initial bytecode corresponding to the interface. Attached Figure Description

[0023] Figure 1 A schematic diagram of an implementation environment provided for an embodiment of this application;

[0024] Figure 2 A flowchart of an assertion method provided in an embodiment of this application;

[0025] Figure 3 This is a schematic diagram illustrating an example of injecting and intercepting bytecode, provided in an embodiment of this application.

[0026] Figure 4 A flowchart illustrating a technical process for interface assertion processing provided in this application embodiment;

[0027] Figure 5 A flowchart of an assertion method provided in an embodiment of this application;

[0028] Figure 6 A block diagram of an assertion device provided in an embodiment of this application;

[0029] Figure 7 This is an internal structural diagram of a computer device provided in an embodiment of this application. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0031] To ensure the accuracy of program execution, assertions are needed to verify the program's operation. Assertions are a means of verifying the program during testing. To guarantee the accuracy and completeness of testing, in cross-application interface scheduling, in addition to asserting the execution of the application itself, it is also necessary to assert the data interaction between applications. Data interaction assertions include message assertions, which refer to asserting the messages sent by one application and the messages received by the called interface in another application. Existing technologies for asserting data interaction primarily involve modifying the source code of the called interface to obtain the messages received by the called interface. However, modifying the source code is labor-intensive and can lead to poor application stability.

[0032] In view of this, embodiments of this application provide an assertion method, apparatus, computer device, storage medium, and program product. Using this assertion method can reduce the workload of assertion and improve the stability of the called interface.

[0033] Please see Figure 1 This diagram illustrates the implementation environment involved in the assertion method provided in the embodiments of this application. Figure 1 As shown, the execution subject of the assertion method provided in this application embodiment can be a single computer device or a cluster of computer devices composed of multiple computer devices. Different computer devices can communicate with each other via wired or wireless means. Wireless communication can be achieved through WIFI, carrier networks, NFC (Near Field Communication), or other technologies.

[0034] Please see Figure 2 The diagram illustrates a flowchart of an assertion method provided in an embodiment of this application, which can be applied to... Figure 1 In the computer device shown. For example... Figure 2 As shown, the assertion method may include the following steps:

[0035] Step 201: The computer device intercepts and processes the messages sent by the test script to the called interface, and obtains the first intercepted data.

[0036] The first intercepted data may include multiple first messages sent by the test script and the call-related information corresponding to each first message; the call-related information may include the pass-through parameters carried by the message and the interface information of the call interface corresponding to the message.

[0037] Optionally, methods for intercepting messages sent by the test script to the called interface include using an automated testing framework, such as Watchman. Optionally, the automated testing framework can be configured on the aforementioned computer equipment or on other computer equipment independently. Before performing interface assertion processing, testers need to configure the interface information of the interface called by the test script in the test script. This interface information includes the application name, version number, interface name, and method name. Furthermore, testers will configure a pass-through parameter for each piece of test data. Optionally, the test data may include the first message; that is, the pass-through parameter is pre-assigned to the first message based on the test script. Optionally, the automated testing framework can obtain the interface information by scanning the project configuration file corresponding to the interface.

[0038] Optionally, after obtaining the first intercepted data, the first intercepted data can be stored in a database as the data basis for subsequent assertion processing.

[0039] Step 202: The computer device intercepts and processes the packets received by the interface through the target bytecode file corresponding to the interface to obtain the second intercepted data.

[0040] The target bytecode file is obtained by injecting intercept bytecode into the initial bytecode obtained by compiling the source code of the interface. The intercept bytecode is used to intercept and process the packets. The second intercept data may include multiple second packets received by the interface and the call-related information corresponding to each second packet. The call-related information may include the pass-through parameters carried by the packet and the interface information of the calling interface corresponding to the packet. The source code may be Java code.

[0041] In traditional technology, the execution logic of Java code is as follows: First, the written Java code is compiled into a bytecode file; then, the bytecode file is placed into a virtual machine for execution. In this embodiment, the interface corresponds to the source code. The initial bytecode obtained by compiling this source code can be injected with interceptor bytecode to intercept messages received by the interface. This interceptor bytecode contains logic for intercepting messages, and therefore can be used to intercept and process messages. Thus, the target bytecode file, including the interceptor bytecode, can intercept and process messages received by the interface. For a clear explanation of the process of injecting interceptor bytecode, please refer to [link to relevant documentation]. Figure 3 A diagram illustrating the injection and interception of bytecode.

[0042] In an optional embodiment of this application, by intercepting the packets received by the interface through the target bytecode file corresponding to the interface, multiple second packets received by the interface, the transparent parameters carried by the multiple second packets, and the interface information of the calling interface corresponding to the multiple second packets can be obtained. Optionally, the intercepted bytecode includes logic for obtaining the interface information of the calling interface corresponding to the packet; that is, the operation of obtaining interface information can be triggered through the target bytecode file corresponding to the interface. In another optional embodiment of this application, by intercepting the packets received by the interface through the target bytecode file corresponding to the interface, multiple second packets received by the interface and the transparent parameters carried by the multiple second packets can be obtained. An optional method for obtaining the interface information of the calling interface corresponding to the multiple second packets includes scanning the project configuration file corresponding to the interface through an automated testing framework to obtain the interface information. This application does not limit the method for obtaining the interface information of the calling interface corresponding to the multiple second packets, as long as the interface information of the calling interface corresponding to the multiple second packets can be obtained.

[0043] Optionally, after obtaining the second intercepted data, the second intercepted data can be formatted to obtain second intercepted data that meets the format requirements, and the second intercepted data that meets the format requirements can be stored in the database as the data basis for subsequent assertion processing.

[0044] Step 203: The computer device performs interface assertion processing based on the first intercepted data and the second intercepted data.

[0045] Optionally, the interface assertion processing may include message assertion and database assertion, wherein message assertion is to assert the first message in the first intercepted data and the second message in the second intercepted data; and database assertion is to assert the database operation result corresponding to the interface.

[0046] In this embodiment, the messages sent by the test script to the called interface are intercepted to obtain first intercepted data. Then, the messages received by the interface are intercepted using the target bytecode file corresponding to the interface to obtain second intercepted data. Finally, interface assertion processing is performed based on the first and second intercepted data. The target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the interface's source code. The intercepted bytecode is used to intercept messages. Therefore, in this embodiment, intercepted bytecode is injected into the initial bytecode corresponding to the interface to obtain the target bytecode file, and then the target bytecode file is used to intercept messages received by the interface. Compared to intercepting messages received by the interface by modifying the interface's source code, this embodiment reduces the workload of assertions and improves the stability of the called interface by injecting intercepted bytecode into the initial bytecode corresponding to the interface.

[0047] Please see Figure 4 This illustrates a technical process for interface assertion processing provided in an embodiment of this application, such as... Figure 4 As shown, the technical process of this interface assertion processing may include the following steps:

[0048] Step 401: The computer device performs matching processing on the first message in the first intercepted data and the second message in the second intercepted data based on the call-related information in the first intercepted data and the second intercepted data.

[0049] Optionally, matching the first and second messages based on call-related information includes: identifying first and second messages with the same call-related information in the first and second intercepted data as mutually matched first and second messages. That is, first and second messages with the same pass-through parameters and interface information in the first and second intercepted data are mutually matched first and second messages. The relationship between the matched first and second messages is as follows: the test script sends the first message to the called interface, the called interface receives the second message, and the second message corresponds to the first message.

[0050] In an optional embodiment of this application, the first intercepted data and the second intercepted data are stored in a database. Since the database contains a large amount of data, directly retrieving the message to be asserted from the database for each assertion would put significant pressure on the database and be inefficient. To avoid this problem, optionally, based on the same interface information and pass-through parameters, the first message and the second message corresponding to the same interface information and pass-through parameters can be retrieved from the database, and the first message, the second message, the interface information, and the pass-through parameters can be stored as a group in the assertion database. This avoids the problem of low assertion efficiency caused by database performance limitations and improves assertion efficiency.

[0051] Step 402: The computer device performs interface assertion processing based on the mutually matching first and second messages.

[0052] Optionally, before performing interface assertion processing based on the matching first and second messages, it is necessary to determine whether the preset assertion method is message assertion or database assertion. If the preset assertion method is message assertion, the message assertion steps are executed. Optional steps include: first, determining the target field name; second, checking whether the field content corresponding to the target field name in the matching first and second messages is the same. The target field can be a field to be asserted pre-set by the tester. If the field content corresponding to the target field name in the matching first and second messages is the same, the message assertion is successful and the program runs accurately; if the field content corresponding to the target field name in the matching first and second messages is different, the message assertion fails and there is a problem with the program. Optionally, in the case of message assertion failure, the computer device can display the result of the assertion failure so that the tester can resolve the problem promptly.

[0053] The called interface performs database operations. However, in traditional technologies, it's impossible to assert the results of these database operations, making it impossible to confirm whether the database operation results are normal. In this embodiment, testers can pre-configure the names of the database fields to be asserted and their corresponding expected values. When the called interface performs database operations, comparing the actual values ​​with the expected values ​​for the same database field names confirms whether the database operation results are normal. If the actual value matches the expected value, the database assertion is successful and the database operation result is normal; if the actual value differs from the expected value, the database assertion fails and the database operation result is abnormal. Optionally, in the case of a database assertion failure, the computer device can display the result of the failure, allowing testers to resolve the issue promptly.

[0054] Optionally, the expected value corresponding to the database field name can be a fixed value, or it can be dynamically obtained from the content of the target field in at least one of the first and second matching messages. This application does not limit the comparison of embodiments. When the expected value is dynamically obtained, unnecessary modification of the expected value caused by message changes can be avoided, ensuring the flexibility and convenience of the assertion.

[0055] In an optional embodiment of this application, if the preset assertion method is database assertion, the steps of performing database assertion are as follows: First, determine the expected value of the target field in the database based on at least one of the mutually matching first and second messages; second, check whether the actual value of the target field in the database is the same as the expected value. If the actual value is the same as the expected value, it indicates that the database assertion is successful and the database operation result is normal; if the actual value is different from the expected value, it indicates that the database assertion fails and the database operation result is abnormal.

[0056] In one embodiment of this application, the step of performing interface assertion processing based on the first and second intercepted data can be executed after a preset assertion time has elapsed. In traditional technologies, some test scenarios involve delayed execution, and the entire test process can last for a considerable time. For example, in timed batch testing, the entire test process often continues until the early hours of the morning, and it is impossible to know exactly when the interface assertion processing will be executed. Manually waiting for the test process to complete before executing the assertions is very time-consuming. In this embodiment, however, an assertion time is preset, ensuring that the entire test process has finished before the assertion time. Optionally, after the preset assertion time has elapsed, the step of performing interface assertion processing based on the first and second intercepted data can be executed. After the interface assertion processing step is completed, the computer device can display the assertion results for testers to view. Thus, in this embodiment, by using a preset assertion time, assertion operations can be automatically executed according to a preset assertion method, reducing the pressure on testers and improving assertion efficiency.

[0057] Please see Figure 5 The diagram illustrates a flowchart of an assertion method provided in an embodiment of this application, which can be applied to... Figure 1 In the computer device shown. For example... Figure 5 As shown, the assertion method may include the following steps:

[0058] Step 501: The computer device intercepts and processes the messages sent by the test script to the called interface, and obtains the first intercepted data.

[0059] The first intercepted data includes multiple first messages sent by the test script and call-related information corresponding to each first message; the call-related information may include the pass-through parameters carried by the message and the interface information of the call interface corresponding to the message.

[0060] Step 502: The computer device intercepts and processes the packets received by the interface through the target bytecode file corresponding to the interface to obtain the second intercepted data.

[0061] The target bytecode file is obtained by injecting intercept bytecode into the initial bytecode obtained by compiling the source code of the interface. The intercept bytecode is used to intercept and process the packets. The second intercept data may include multiple second packets received by the interface and the call-related information corresponding to each second packet. The call-related information may include the pass-through parameters carried by the packet and the interface information of the calling interface corresponding to the packet. The source code may be Java code.

[0062] In traditional technology, the execution logic of Java code is as follows: First, the written Java code is compiled into a bytecode file; then, the bytecode file is placed into a virtual machine for execution. In this embodiment, the interface corresponds to the source code. The initial bytecode obtained by compiling the source code can be injected with interception bytecode to intercept messages received by the interface. This interception bytecode contains logic for intercepting messages, and therefore can be used to intercept and process messages. Thus, the target bytecode file including the interception bytecode can intercept and process messages received by the interface.

[0063] Step 503: The computer device determines the first message and the second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matched first messages and second messages.

[0064] Optionally, if the tester believes that the message cannot meet the assertion requirements, the message can be stored in a custom way. For example, if the pass-through parameters carried by the message are modified, causing the message to fail to meet the assertion requirements, the message can be stored in a custom way.

[0065] Step 504: The computer device determines the target field name.

[0066] Step 505: The computer device checks whether the content of the field corresponding to the target field name in the first and second matching messages is the same.

[0067] The target field can be a field pre-defined by the tester to be asserted. If the content of the target field name in the first and second matching messages is the same, the message assertion is successful and the program runs accurately; if the content of the target field name in the first and second matching messages is different, the message assertion fails and there is a problem with the program. Optionally, in the case of message assertion failure, the computer device can display the result of the failure so that the tester can resolve the problem promptly.

[0068] In this embodiment, the messages sent by the test script to the called interface are intercepted to obtain first intercepted data. Then, the messages received by the interface are intercepted using the target bytecode file corresponding to the interface to obtain second intercepted data. Next, the first and second matching messages are determined based on the identical call-related information in the first and second intercepted data. Finally, the content of the fields corresponding to the target field names in the matching first and second messages is checked to complete the assertion. The target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the interface's source code. The intercepted bytecode is used to intercept messages. Therefore, in this embodiment, intercepted bytecode is injected into the initial bytecode corresponding to the interface to obtain the target bytecode file, which is then used to intercept messages received by the interface. Compared to the prior art of intercepting messages received by the interface by modifying the interface's source code, this embodiment reduces the workload of assertions and improves the stability of the called interface by injecting intercepted bytecode into the initial bytecode corresponding to the interface.

[0069] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0070] Please see Figure 6 This diagram illustrates a block diagram of an assertion device 600 provided in an embodiment of this application, which can be configured in the aforementioned computer device. Figure 6As shown, the assertion device 600 includes a first interception module 601, a second interception module 602, and an assertion module 603.

[0071] The first interception module 601 is used to intercept and process the messages sent by the test script to the called interface to obtain first interception data; the second interception module 602 is used to intercept and process the messages received by the interface through the target bytecode file corresponding to the interface to obtain second interception data, wherein the target bytecode file is obtained by injecting the interception bytecode into the initial bytecode obtained by compiling the source code of the interface, and the interception bytecode is used to intercept and process the messages; the assertion module 603 is used to perform interface assertion processing based on the first interception data and the second interception data.

[0072] In one embodiment, the first interception data includes multiple first messages sent by the test script and call-related information corresponding to each first message, and the second interception data includes multiple second messages received by the interface and call-related information corresponding to each second message. The assertion module 603 is specifically used for: matching the first messages in the first interception data and the second messages in the second interception data based on the call-related information in the first interception data and the second interception data; and performing interface assertion processing based on the mutually matched first messages and second messages.

[0073] In one embodiment, based on the call-related information in the first intercepted data and the second intercepted data, the assertion module 603 is specifically used to: determine the first message and the second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matching first messages and second messages.

[0074] In one embodiment, the relevant information includes the pass-through parameters carried by the message and the interface information of the call interface corresponding to the message; wherein, the pass-through parameters are pre-assigned to the message based on the test script.

[0075] In one embodiment, the assertion module 603 is specifically used to: determine the target field name; and detect whether the field content corresponding to the target field name in the first and second matching messages is the same.

[0076] In one embodiment, the assertion module 603 is specifically configured to: determine the expected value of a target field in the database based on at least one of a first message and a second message that match each other; and detect whether the actual value of the target field in the database is the same as the expected value.

[0077] In one embodiment, the assertion module 603 is specifically used to: after a preset assertion time is reached, perform an interface assertion process based on the first interception data and the second interception data.

[0078] The assertion device provided in this application embodiment can implement the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.

[0079] Each module in the aforementioned assertion device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can invoke and execute the operations corresponding to each module.

[0080] In one embodiment, a computer device is provided, the internal structure of which can be shown as follows: Figure 7 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements an assertion method. The display screen can be an LCD screen or an e-ink display screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.

[0081] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0082] In one embodiment of this application, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: intercepting and processing messages sent by a test script to a called interface to obtain first intercepted data; intercepting and processing messages received by the interface through a target bytecode file corresponding to the interface to obtain second intercepted data, wherein the target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the source code of the interface, and the intercepted bytecode is used to intercept and process messages; and performing interface assertion processing based on the first intercepted data and the second intercepted data.

[0083] In one embodiment of this application, the first interception data includes multiple first messages sent by the test script and call-related information corresponding to each first message, and the second interception data includes multiple second messages received by the interface and call-related information corresponding to each second message. When the processor executes the computer program, it further implements the following steps: matching the first messages in the first interception data and the second messages in the second interception data based on the call-related information in the first interception data and the second interception data; and performing interface assertion processing based on the mutually matched first messages and second messages.

[0084] In one embodiment of this application, when the processor executes a computer program, it further implements the following steps: determining a first message and a second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matching first messages and second messages.

[0085] In one embodiment of this application, the relevant information includes the transparent parameters carried by the message and the interface information of the calling interface corresponding to the message; wherein, the transparent parameters are pre-assigned to the message based on the test script.

[0086] In one embodiment of this application, when the processor executes the computer program, it further performs the following steps: determining the target field name; detecting whether the field content corresponding to the target field name in the first and second matching messages is the same.

[0087] In one embodiment of this application, the processor, when executing a computer program, further implements the following steps: determining the expected value of a target field in the database based on at least one of a first message and a second message that match each other; and detecting whether the actual value of the target field in the database is the same as the expected value.

[0088] In one embodiment of this application, when the processor executes the computer program, it further implements the following steps: after a preset assertion time is reached, it performs interface assertion processing based on the first interception data and the second interception data.

[0089] The computer device provided in this application embodiment has a similar implementation principle and technical effect to the above method embodiment, and will not be described again here.

[0090] In one embodiment of this application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps: intercepting and processing messages sent by a test script to a called interface to obtain first intercepted data; intercepting and processing messages received by the interface through a target bytecode file corresponding to the interface to obtain second intercepted data, wherein the target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the source code of the interface, and the intercepted bytecode is used to intercept and process messages; and performing interface assertion processing based on the first intercepted data and the second intercepted data.

[0091] In one embodiment of this application, the first interception data includes multiple first messages sent by the test script and call-related information corresponding to each first message; the second interception data includes multiple second messages received by the interface and call-related information corresponding to each second message; when the computer program is executed by the processor, it further implements the following steps: matching the first messages in the first interception data and the second messages in the second interception data based on the call-related information in the first interception data and the second interception data; and performing interface assertion processing based on the mutually matched first messages and second messages.

[0092] In one embodiment of this application, when the computer program is executed by the processor, it further implements the following steps: determining a first message and a second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matching first messages and second messages.

[0093] In one embodiment of this application, the relevant information includes the transparent parameters carried by the message and the interface information of the calling interface corresponding to the message; wherein, the transparent parameters are pre-assigned to the message based on the test script.

[0094] In one embodiment of this application, when the computer program is executed by the processor, it further performs the following steps: determining the target field name; detecting whether the field content corresponding to the target field name in the first and second matching messages is the same.

[0095] In one embodiment of this application, when the computer program is executed by the processor, it further performs the following steps: determining the expected value of a target field in the database based on at least one of a first message and a second message that match each other; and detecting whether the actual value of the target field in the database is the same as the expected value.

[0096] In one embodiment of this application, when the computer program is executed by the processor, it further implements the following steps: after a preset assertion time is reached, it performs interface assertion processing based on the first interception data and the second interception data.

[0097] The computer-readable storage medium provided in this embodiment is similar in principle and technical effect to the method embodiment described above, and will not be repeated here.

[0098] In one embodiment of this application, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps: intercepting and processing messages sent by a test script to a called interface to obtain first intercepted data; intercepting and processing messages received by the interface through a target bytecode file corresponding to the interface to obtain second intercepted data, wherein the target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the source code of the interface, and the intercepted bytecode is used to intercept and process messages; and performing interface assertion processing based on the first intercepted data and the second intercepted data.

[0099] In one embodiment of this application, the first interception data includes multiple first messages sent by the test script and call-related information corresponding to each first message; the second interception data includes multiple second messages received by the interface and call-related information corresponding to each second message; when the computer program is executed by the processor, it further implements the following steps: matching the first messages in the first interception data and the second messages in the second interception data based on the call-related information in the first interception data and the second interception data; and performing interface assertion processing based on the mutually matched first messages and second messages.

[0100] In one embodiment of this application, when the computer program is executed by the processor, it further implements the following steps: determining a first message and a second message with the same call-related information in the first intercepted data and the second intercepted data as mutually matching first messages and second messages.

[0101] In one embodiment of this application, the relevant information includes the transparent parameters carried by the message and the interface information of the calling interface corresponding to the message; wherein, the transparent parameters are pre-assigned to the message based on the test script.

[0102] In one embodiment of this application, when the computer program is executed by the processor, it further performs the following steps: determining the target field name; detecting whether the field content corresponding to the target field name in the first and second matching messages is the same.

[0103] In one embodiment of this application, when the computer program is executed by the processor, it further performs the following steps: determining the expected value of a target field in the database based on at least one of a first message and a second message that match each other; and detecting whether the actual value of the target field in the database is the same as the expected value.

[0104] In one embodiment of this application, when the computer program is executed by the processor, it further implements the following steps: after a preset assertion time is reached, it performs interface assertion processing based on the first interception data and the second interception data.

[0105] The computer program product provided in this embodiment has a similar implementation principle and technical effect to the above method embodiments, and will not be described again here.

[0106] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0107] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0108] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. An assertion method, characterized in that, The method includes: The message sent by the test script to the called interface is intercepted and processed to obtain the first intercepted data; The intercepted packets received by the interface are processed by the target bytecode file corresponding to the interface to obtain second intercepted data. The target bytecode file is obtained by injecting intercepted bytecode into the initial bytecode obtained by compiling the source code of the interface. The intercepted bytecode is used to intercept packets. The first intercepted data includes multiple first packets sent by the test script and call-related information corresponding to each first packet. The second intercepted data includes multiple second packets received by the interface and call-related information corresponding to each second packet. The call-related information includes the pass-through parameters carried by the packet and the interface information of the calling interface corresponding to the packet. The pass-through parameters are pre-allocated to the packet based on the test script. Based on the call-related information in the first intercepted data and the second intercepted data, the first message in the first intercepted data and the second message in the second intercepted data are matched. Interface assertion processing is performed based on the first and second messages that match each other.

2. The method according to claim 1, characterized in that, The matching process based on the call-related information in the first intercepted data and the second intercepted data, involving the matching of the first message in the first intercepted data and the second message in the second intercepted data, includes: The first message and the second message that have the same call-related information in the first intercepted data and the second intercepted data are identified as the first message and the second message that match each other.

3. The method according to claim 1, characterized in that, The interface assertion process based on the mutually matching first and second messages includes: Determine the target field name; Check whether the content of the fields corresponding to the target field names in the first and second matching messages is the same.

4. The method according to claim 1, characterized in that, The interface assertion process based on the mutually matching first and second messages includes: The expected value of the target field in the database is determined based on at least one of the first and second matching messages; Check whether the actual value of the target field in the database is the same as the expected value.

5. The method according to claim 1, characterized in that, The interface assertion processing based on the first intercepted data and the second intercepted data includes: After the preset assertion time is reached, the step of performing interface assertion processing based on the first interception data and the second interception data is executed.

6. An assertion device, characterized in that, The device includes: The first interception module is used to intercept and process the messages sent by the test script to the called interface, and obtain the first interception data; The second interception module is used to intercept and process the packets received by the interface through the target bytecode file corresponding to the interface, and obtain second interception data. The target bytecode file is obtained by injecting interception bytecode into the initial bytecode obtained by compiling the source code of the interface. The interception bytecode is used to intercept and process the packets. The first interception data includes multiple first packets sent by the test script and call-related information corresponding to each first packet. The second interception data includes multiple second packets received by the interface and call-related information corresponding to each second packet. The call-related information includes the pass-through parameters carried by the packet and the interface information of the calling interface corresponding to the packet. The pass-through parameters are pre-allocated to the packet based on the test script. The assertion module is used to perform matching processing on the first message in the first interception data and the second message in the second interception data based on the call-related information in the first interception data and the second interception data; and to perform interface assertion processing based on the mutually matched first message and second message.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.

9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.