Automatic interface testing method and system based on data preprocessing

By adopting an interface automation test method based on data preprocessing in automated testing, and using timestamp difference values ​​to control log updates and queries, the problem of test cases relying on historical data in the prior art is solved, and the accuracy and adaptability of interface tests are improved.

CN119807029APending Publication Date: 2025-04-11CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411747449.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

During the continuous iteration of existing automated testing solutions, test cases rely on fixed historical data and cannot reflect the correctness of new data, resulting in insufficient detection accuracy and difficult to meet the quality assurance requirements in product iteration scenarios.

Method used

An interface automation test method based on data preprocessing is adopted to determine whether to report a new log by judging the difference in timestamps, ensure the real-timeness of the test data, and conduct interface logic testing based on the latest timestamp query of the target log information in the database.

Benefits of technology

It improves the accuracy of interface testing, ensuring that after product iteration and interface modification, the latest log data can be used for testing, meeting the quality assurance needs of continuous iteration scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807029A_ABST
    Figure CN119807029A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of automatic testing, and discloses an automatic interface testing method and system based on data preprocessing, the method is applied to an automatic testing framework, and the method comprises the steps that a time threshold value is set according to the data processing frequency of a module to be tested, and if the difference value between the current timestamp and the last log reporting timestamp exceeds the threshold value, the module to be tested is tested; if so, reading the original log of the module, updating the timestamp and reporting to the database. And querying logs in a target time interval (a current forward preset threshold value) range, and if an original log is contained, performing an interface logic test based on the original log to obtain a result. Through real-time and dynamic log report and query, the test log is ensured to be always synchronized with the latest code logic, so that the problem of inaccurate interface test result caused by product iteration and data preprocessing logic change is solved, and the interface test accuracy in the product iteration process is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of automated testing, and in particular to an interface automated testing method and system based on data preprocessing. Background Art

[0002] In practice, databases often store preprocessed data. Raw data is usually collected in the form of logs and stored in search engines such as Elasticsearch, and then queried, cleaned, and converted through scheduled tasks, and finally the processed data is stored in a relational database.

[0003] However, if the product continues to iterate, the existing automated testing solutions have the following technical problems: test cases rely on fixed historical data, the data is generated according to the old processing logic, and cannot reflect the correctness of new data. Since the query results of a fixed time range may be outdated, they cannot cover new business scenarios and data processing requirements. When the data processing logic changes, the test data needs to be re-prepared, which has high maintenance costs.

[0004] Therefore, the existing technology has the problem of insufficient accuracy in detecting the interface to be tested, making it difficult to ensure the correctness of the data processing logic and failing to meet the quality assurance requirements in the scenario of continuous product iteration. Summary of the invention

[0005] In view of this, the present invention provides an interface automation testing method and system based on data preprocessing to solve how to effectively improve the accuracy of the detection results of the interface to be tested during the continuous iteration process of the product.

[0006] In a first aspect, the present invention provides an interface automation testing method based on data preprocessing, which is applied to an automation testing framework, and the method comprises:

[0007] Determine whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested;

[0008] If it is greater than the first preset time period threshold, the original log information generated when the target module to be tested is running is read, and at the same time, the value of the log time variable in the original log information is modified to the value of the timestamp corresponding to the current moment, and the modified log information is reported to the database, and then the value of the timestamp corresponding to the current moment is recorded, so as to be used for the difference calculation between the value of the timestamp corresponding to the next log reporting moment and the next log reporting moment;

[0009] Based on the interface to be tested corresponding to the target module to be tested, query the database for target log information within a target time interval, wherein the target time interval represents a time interval corresponding to a first preset time period threshold shifted forward from the current moment;

[0010] If the target log information includes the original log information reported to the database, a logic test of the interface to be tested is performed based on the target log information to obtain a test result of the interface to be tested.

[0011] In an embodiment of the present invention, it is determined whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, and whether a new log needs to be reported is determined by the time difference, so as to avoid too frequent data updates and improve test efficiency. If it is greater than the first preset time period threshold, the value of the log time variable in the original log information is modified to the value of the timestamp corresponding to the current moment, and the modified log information is reported to the database, and then the value of the timestamp corresponding to the current moment is recorded, and the log time is updated to the current time, so as to ensure the real-time nature of the test data. The log data at the next log collection and reporting is the latest, and the target log information within the target time interval range in the database is queried based on the interface to be tested. The target time interval is a preset time period forward, so as to ensure that the queried data is the latest data related to the current test moment, and avoid using old data for testing, thereby improving the accuracy of the test; if the queried target log information contains the original log information reported previously, it means that the data processing flow is correct and is generated based on the latest timestamp, thereby effectively ensuring the accuracy of the latest interface test results after the product iteration update and the corresponding interface modification.

[0012] In an optional implementation, determining whether a time difference between a value of a timestamp corresponding to the current moment and a value of a timestamp corresponding to the last log report is greater than a first preset time period threshold specifically includes:

[0013] Obtain a value corresponding to a first time variable and a value corresponding to a second time variable, wherein the first time variable is used to store the value of the timestamp recorded when the last log was reported, and the second time variable is used to store the value of the timestamp corresponding to the current moment;

[0014] It is determined whether a time difference obtained by subtracting a value corresponding to the first time variable from a value corresponding to the second time variable is greater than the first preset time period threshold.

[0015] In the embodiment of the present invention, the first time variable is used to store the timestamp value recorded when the last log was reported. The second time variable is used to store the timestamp value corresponding to the current moment. Through these two time variables, the system can accurately track the time of the last log report and the current time, thereby providing a data basis for subsequent time difference calculation.

[0016] In an optional implementation, before querying the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, the method further includes:

[0017] Enter a waiting state until the duration of the waiting state reaches a second preset time period threshold; wherein the second preset time period threshold is negatively correlated with the data processing complexity value of the target module to be tested, or the second preset time period threshold is positively correlated with the data response speed value of the target module to be tested.

[0018] In the embodiment of the present invention, before querying the target log information, a waiting state is first entered until the waiting time reaches the second preset time period threshold, so as to ensure that the database has enough time to complete data processing and response, and avoid the situation where data is not generated or processed in time due to data processing complexity or slow response speed, which affects the accuracy of interface testing during product iteration.

[0019] In an optional implementation, after querying the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, the method further includes:

[0020] If the target log information does not contain the original log information reported to the database, then after the second preset time period threshold, continue to query the target log information within the target time interval in the database based on the interface to be tested corresponding to the target module to be tested until the target log information contains the original log information reported to the database.

[0021] In an embodiment of the present invention, when the target log information does not contain the reported original log information, it is queried again after an interval. That is to say, if the updated original log information is not found in the target log information in the initial query, it means that the log data may not have been completely processed, and the queried log is not the latest and accurate log. At this time, the test will not be terminated immediately, but after an interval of a second preset time period threshold, the target log information in the database will continue to be queried, thereby avoiding frequent queries to the database, controlling the frequency of testing, and ensuring that the latest log data can still be used for testing after product iterations and interface modifications, thereby improving the accuracy of the test results.

[0022] In an optional implementation, the interface to be tested includes a data processing code logic fragment;

[0023] The performing a logic test of the interface to be tested based on the target log information to obtain a test result of the interface to be tested specifically includes:

[0024] According to inputting the target log information into the data processing code logic fragment, an actual data processing result is obtained as an output;

[0025] Determine whether the actual data processing result is the same as the preset expected processing result. If they are the same, the data processing code logic fragment test of the interface to be tested passes; if they are different, the data processing code logic fragment test of the interface to be tested fails.

[0026] In the embodiment of the present invention, the interface to be tested not only simply returns data by querying the database, but also includes a code logic fragment for data processing, that is, the test is not only the database query result, but also includes the test of the data processing logic. By inputting the target log information into the data processing code logic fragment, the running result of the current code logic can be directly tested. In other words, the test process corresponds to the latest code logic and does not rely on historical data for testing, thereby ensuring that the latest log data can still be used for testing after product iteration and interface modification, thereby improving the accuracy of interface testing.

[0027] In an optional implementation, the interface to be tested includes a data acquisition code logic fragment;

[0028] The performing a logic test of the interface to be tested based on the target log information to obtain a test result of the interface to be tested specifically includes:

[0029] Determine whether the target log information is the same as the preset expected log information. If they are the same, the data acquisition code logic fragment test of the interface to be tested passes; if they are not the same, the data acquisition code logic fragment test of the interface to be tested fails.

[0030] In an embodiment of the present invention, the interface to be tested also includes a code logic fragment for data processing, that is, by comparing the target log information with the preset expected log information, the correctness of the data collection logic can be quickly verified. The test process also corresponds to the latest code logic and does not rely on historical data for testing, thereby ensuring that the latest log data can still be used for testing after product iterations and interface modifications, thereby improving the accuracy of interface testing.

[0031] In a second aspect, the present invention provides an interface automation testing system based on data preprocessing, the system comprising:

[0032] A time difference judgment module is used to judge whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested;

[0033] The log processing and reporting module is used to read the original log information generated when the target module to be tested is running, and at the same time, modify the value of the log time variable in the original log information to the value of the timestamp corresponding to the current moment, report the modified log information to the database, and then record the value of the timestamp corresponding to the current moment, so as to calculate the difference between the value of the timestamp corresponding to the next log reporting moment and the next log reporting moment;

[0034] A log query module, used to query the target log information within a target time interval in the database based on the interface to be tested corresponding to the target module to be tested, wherein the target time interval represents the time interval corresponding to the first preset time period threshold shifted forward from the current moment;

[0035] The interface testing module is used to perform a logic test of the interface to be tested based on the target log information if the target log information contains the original log information reported to the database, and obtain a test result of the interface to be tested.

[0036] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the interface automation testing method based on data preprocessing of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0037] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the interface automation testing method based on data preprocessing of the above-mentioned first aspect or any corresponding embodiment thereof.

[0038] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the interface automation testing method based on data preprocessing according to the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0040] Figure 1 is a first flow chart of an interface automation testing method based on data preprocessing according to an embodiment of the present invention;

[0041] Figure 2 is a second flow chart of the interface automation testing method based on data preprocessing according to an embodiment of the present invention;

[0042] Figure 3 is a third flow chart of the interface automation testing method based on data preprocessing according to an embodiment of the present invention;

[0043] Figure 4 is a fourth flow chart of the interface automation testing method based on data preprocessing according to an embodiment of the present invention;

[0044] Figure 5 is a fifth flow chart of the interface automation testing method based on data preprocessing according to an embodiment of the present invention;

[0045] Figure 6 is a structural block diagram of an interface automation test system based on data preprocessing according to an embodiment of the present invention;

[0046] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

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

[0048] In Web application systems, the front-end and back-end separation architecture has become the mainstream development model. The front-end initiates a request to the back-end through the HTTP protocol POST, GET and other methods, carrying query parameters; after receiving these parameters, the back-end constructs the corresponding database query statement, retrieves the qualified data from the database and returns it to the front-end.

[0049] In actual application scenarios, Web interface testing uses an automated testing framework. Existing Web interface automated testing mainly uses a fixed parameter request method, that is, pre-setting query parameters, initiating a request to the interface, and then comparing the returned result with the expected value to verify the correctness of the interface.

[0050] If the product is continuously iterated, the logic of data preprocessing may change. For example, the data cleaning rules may be adjusted, the calculation method may be updated, or new processing steps may be added, which will directly affect the results of the preprocessed data stored in the database. Simply testing the query results within a fixed time range cannot effectively verify whether the data processing logic in the current code is correct.

[0051] That is to say, during the continuous iteration of the product, the test cases rely on fixed historical log data. The data is generated according to the old processing logic, not in real time, and cannot reflect the correctness of the new log data, resulting in inaccurate results of testing the Web interface.

[0052] The embodiment of the present invention provides an interface automation testing method based on data preprocessing, and the main application scenarios are: web interface automation involving raw data processing and display, such as the underlying engine of the web application firewall reports access logs and attack logs, the back end processes the raw data regularly, extracts the key fields of the attack logs and stores them in the database, and the web interface directly queries the database when obtaining data; the underlying engine of the DDoS high defense reports access logs, attack logs, and attack source IP logs, the back end processes the original logs regularly to generate attack events, and counts the relevant attack source IP, attack type, and bps\pps in the attack event and stores them in the database, and the web interface directly queries the database when obtaining data. The embodiment of the present invention provides an interface automation testing method based on data preprocessing, which ensures that the test log is always synchronized with the latest code logic through real-time and dynamic log reporting and querying, thereby solving the problem of inaccurate interface test results caused by product iteration and data preprocessing logic changes, and effectively improving the accuracy of interface testing during product iteration.

[0053] According to an embodiment of the present invention, an embodiment of an interface automation testing method based on data preprocessing is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0054] In this embodiment, an interface automation testing method based on data preprocessing is provided, which is applied to an automation testing framework. Taking the interface automation framework Pytest as an example, there is a parameter scope in the fixture of Pytest, and its scopes are: function, class, module, and session. The embodiment of the present invention reports real-time logs in the scope of the session level, and then queries the data in the current time period in the relevant interface to more accurately verify the logical correctness of the current code, verify the accuracy of the code related to data preprocessing, and improve the code coverage of the web interface automation test. Figure 1 is a flow chart of an interface automation testing method based on data preprocessing according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0055] Step S101, determining whether the time difference between the timestamp value corresponding to the current moment and the timestamp value corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested.

[0056] It should be noted that the first preset time period threshold refers to a time interval value pre-set according to the data processing characteristics of the target module to be tested, and is negatively correlated with the data processing frequency of the target module to be tested, that is, the higher the processing frequency, the smaller the threshold. The target module to be tested refers to the functional module to be tested, such as the attack log processing module of the Web application firewall or the attack event statistics module of the DDoS high defense.

[0057] Specifically, a timestamp calculation technology is used, or a timer is used to periodically trigger a time difference check.

[0058] Exemplarily, the current timestamp is obtained, the timestamp of the last log report is read, and then the difference between the two timestamps is calculated. If the data processing frequency of the target module to be tested is once per hour, the first preset time period threshold can be set to 3600 seconds / 60 minutes / 1 hour, and when the data processing frequency increases, the threshold is correspondingly reduced. For example, if the last log report time is 14:00, the current time is 14:30, and the preset threshold is 1 hour, then the time difference of 30 minutes is less than the threshold, and no new log report is required. The log report frequency is controlled by the time difference to avoid too frequent data updates affecting the test efficiency, while also ensuring the timeliness of the test log information data.

[0059] Step S102, if it is greater than the first preset time period threshold, read the original log information generated when the target module to be tested is running, and at the same time, modify the value of the log time variable in the original log information to the value of the timestamp corresponding to the current moment, report the modified log information to the database, and then record the value of the timestamp corresponding to the current moment for use in the next log report, and perform a difference calculation with the value of the timestamp corresponding to the next log report moment.

[0060] It should be noted that the original log information refers to the original operation record generated by the target module under test during operation, including various status information of the module during operation, data processing results, etc. The log time variable refers to the field in the log record that indicates the time when the log is generated.

[0061] Specifically, the log is read by file IO operation, or the log parser provided by the database is used to parse the log. That is, the original log information is obtained from the target module to be tested, the log content is parsed, the log time variable is updated to the current system timestamp, and then the updated log information is written to the database through the database connection, and finally the current timestamp is saved to the storage, wherein the log format is JSON format.

[0062] For example, using the interface automation testing framework Pytest as an implementation method, a method with the @pytest.fixture(scope="session") decorator can be defined to implement real-time reporting of raw data to the Elasticsearch database. This method will be called once before the test session starts. First, it checks whether the system permanent variable POST_TIME exists. If it does not exist, the system permanent variable is initialized to POST_TIME=0. The variable is used to store the time of the last log report to avoid repeated log reporting during retry or debugging of the automation case failure, resulting in abnormal query results.

[0063] Among them, the original log format may be: {"timestamp":"1632047100000", "user_id":"12345"}, and the updated log format may be: {"timestamp":"1632047400000", "user_id":"12345"}. It can be understood that the "timestamp" field is updated to the timestamp corresponding to the current time.

[0064] Step S103, querying the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, wherein the target time interval represents a time interval corresponding to a first preset time period threshold shifted forward from the current moment.

[0065] It should be noted that the interface to be tested refers to the Web application interface that needs to be tested, the target time interval range refers to a time range determined by the first preset time period threshold based on the current time, and the target log information refers to the log records queried from the database within the time interval. There are two common types of Web application interfaces, one is the http protocol interface, and the other is the web service interface such as soup, rmi, and rpc protocols. Common http protocol interface request methods include: post (add), delete (delete), put (change), and get (query).

[0066] Specifically, if the database is MySQL, the log information within the target time range is obtained from the database through the SQL statement query syntax, that is, data is filtered by specifying the timestamp range, or the current time can be converted into a timestamp in a unified format and queried using the standard library of the programming language.

[0067] Exemplarily, the current time is 14:30, and the last log report time is 13:00. If the first preset time period threshold is 1 hour, the target time interval range should be all log information between 13:30 and 14:30. When calling the interface to be tested, pass in the time range to query all log records generated during this period. Query the latest data in the database based on the time interval to obtain the log information that matches the current test time, to ensure that the queried log information can truly reflect the latest processing status of the module to be tested, and avoid affecting the accuracy of the test results due to expired data.

[0068] Step S104: If the target log information includes the original log information reported to the database, a logic test of the interface to be tested is performed based on the target log information to obtain a test result of the interface to be tested.

[0069] It should be noted that logic testing refers to checking the content and logic of the target log information based on pre-designed automated test cases to verify whether the log data matches the logic of the interface to be tested and whether it is correct.

[0070] Specifically, the automated testing framework Pytest is used to implement logic testing. Assertions can be set in the test code to verify whether the target log information contains the expected original log information and obtain the test results of the interface to be tested. Alternatively, if the original log information and the target log information have complex structures, the data parsing library can be used to perform structured parsing of the log data to perform logic verification and obtain the test results of the interface to be tested.

[0071] It is understandable that by comparing the contents of the target log information and the original log information, it is verified whether the logic and data processing of the interface to be tested are in line with expectations. When the product iteration and data processing logic change, the interface to be tested can correctly query the latest data for testing. Compared with the common web interface automation testing solutions, which all query fixed data within a fixed time range and cannot well verify whether the data preprocessing logic modification during the product iteration process is correct, the embodiment of the present invention adds a step of real-time reporting of the original data, which can more accurately verify the correctness of the logic of the code related to the interface to be tested.

[0072] In an embodiment of the present invention, it is determined whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, and whether a new log needs to be reported is determined by the time difference, so as to avoid too frequent data updates and improve test efficiency. If it is greater than the first preset time period threshold, the value of the log time variable in the original log information is modified to the value of the timestamp corresponding to the current moment, and the modified log information is reported to the database, and then the value of the timestamp corresponding to the current moment is recorded, and the log time is updated to the current time, so as to ensure the real-time nature of the test data. The log data at the next log collection and reporting is the latest, and the target log information within the target time interval range in the database is queried based on the interface to be tested. The target time interval is a preset time period forward, so as to ensure that the queried data is the latest data related to the current test moment, and avoid using old data for testing, thereby improving the accuracy of the test; if the queried target log information contains the original log information reported previously, it means that the data processing flow is correct and is generated based on the latest timestamp, thereby effectively ensuring the accuracy of the latest interface test results after the product iteration update and the corresponding interface modification.

[0073] In this embodiment, an interface automation testing method based on data preprocessing is provided, which can be used for the above-mentioned computer. Figure 2 is a flow chart of an interface automation testing method based on data preprocessing according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0074] Step S201, determine whether the time difference between the timestamp value corresponding to the current moment and the timestamp value corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested.

[0075] Specifically, step S201 includes:

[0076] Step S2011, obtaining a value corresponding to a first time variable and a value corresponding to a second time variable, wherein the first time variable is used to store the value of the timestamp recorded when the last log was reported, and the second time variable is used to store the value of the timestamp corresponding to the current moment.

[0077] Step S2012, determining whether a time difference obtained by subtracting a value corresponding to the first time variable from a value corresponding to the second time variable is greater than a first preset time period threshold.

[0078] For example, see Figure 3 When making a judgment, it is necessary to obtain the environment variables, including: analyzing whether there is POST TIME (first time variable) in the system permanent variables, if so, ending the process of obtaining the environment variables, if not, setting the system permanent variable POST TIME = 0 (first time variable), and then ending the process of obtaining the environment variables, and performing the step of judging whether the time difference obtained by subtracting the value corresponding to the second time variable from the value corresponding to the first time variable is greater than the first preset time period threshold (for example, 1h).

[0079] In the embodiment of the present invention, the first time variable is used to store the timestamp value recorded when the last log was reported. The second time variable is used to store the timestamp value corresponding to the current moment. Through these two time variables, the system can accurately track the time of the last log report and the current time, thereby providing a data basis for subsequent time difference calculation.

[0080] Step S202, if it is greater than the first preset time period threshold, read the original log information generated when the target module to be tested is running, and at the same time, modify the value of the log time variable in the original log information to the value of the timestamp corresponding to the current moment, report the modified log information to the database, and then record the value of the timestamp corresponding to the current moment for use in the next log reporting, and perform difference calculation with the value of the timestamp corresponding to the next log reporting moment.

[0081] Exemplarily, after the modified log information is reported to the database, the value of the timestamp corresponding to the current time is recorded, that is, the timestamp corresponding to the current time of 14:30 is stored in the first time variable POST TIME, for example, POSTTIME=1632047100000.

[0082] Step S203, query the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, wherein the target time interval represents the time interval corresponding to the first preset time period threshold shifted forward from the current moment. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.

[0083] Step S204: If the target log information includes the original log information reported to the database, a logic test of the interface to be tested is performed based on the target log information to obtain a test result of the interface to be tested.

[0084] In a specific embodiment, the interface to be tested includes a data processing code logic fragment; the above step S204 includes:

[0085] Step a1, according to inputting the target log information into the data processing code logic fragment, the actual data processing result is outputted.

[0086] It should be noted that the data processing code logic fragment in the interface to be tested refers to the core code part for data processing. The core code part will execute a series of calculations or processing processes based on the input data to generate corresponding output results. In this embodiment, the data processing code logic fragment can be the filtering processing of log information, log analysis processing, etc.

[0087] Step a2, determining whether the actual data processing result is the same as the preset expected processing result;

[0088] Step a3: If they are the same, the test of the data processing code logic fragment of the interface to be tested passes; if they are different, the test of the data processing code logic fragment of the interface to be tested fails.

[0089] It should be noted that the actual data processing results and expected results are usually compared through comparison operators in programming languages, and it is necessary to ensure that the formats of the actual results and expected results are consistent. For example, if the expected result is in JSON format, the actual result must also be in JSON format, and all fields (such as the timestamp of the log information, the event type of the log information, etc.) should match one by one.

[0090] For example, if the actual data processing result is the same as the expected result, it means that the code logic fragment of the interface to be tested works normally, can correctly process the input data, generate the correct output result, and the test passes. If the actual data processing result does not match the expected result, it means that there is a problem with the logic of the interface to be tested, and the input data cannot be processed as expected, and the test fails. By judging whether the interface passes the test through real-time log data, it is ensured that the function of the interface is feasible in actual use, and its test results are more accurate.

[0091] In the embodiment of the present invention, the interface to be tested not only simply returns data by querying the database, but also includes a code logic fragment for data processing, that is, the test is not only the database query result, but also includes the test of the data processing logic. By inputting the target log information into the data processing code logic fragment, the running result of the current code logic can be directly tested. In other words, the test process corresponds to the latest code logic and does not rely on historical data for testing, thereby ensuring that the latest log data can still be used for testing after product iteration and interface modification, thereby improving the accuracy of interface testing.

[0092] In another specific embodiment, the interface to be tested includes a data acquisition code logic fragment; the above step S204 includes:

[0093] Step b1, determining whether the target log information is the same as the preset expected log information;

[0094] Step b2: If they are the same, the test of the logic fragment of the data acquisition code of the interface to be tested passes; if they are not the same, the test of the logic fragment of the data acquisition code of the interface to be tested fails.

[0095] It should be noted that the preset expected log information is defined according to the previous log specification, which refers to the log format that should be generated when the interface to be tested collects log information data. The expected log information can specifically set certain specific events (such as errors, warning information, etc.) to appear in a specific timestamp and field combination. The judgment and comparison operation can be achieved by direct field value comparison or by preset matching rules.

[0096] For example, if the target log information is the same as the preset expected log information, it means that the data collection function has no problem and can correctly collect the expected log information, and the test passes. If the two are different, it means that there is a problem with the data collection and the test fails.

[0097] In an embodiment of the present invention, the interface to be tested also includes a code logic fragment for data processing, that is, by comparing the target log information with the preset expected log information, the correctness of the data collection logic can be quickly verified. The test process also corresponds to the latest code logic and does not rely on historical data for testing, thereby ensuring that the latest log data can still be used for testing after product iterations and interface modifications, thereby improving the accuracy of interface testing.

[0098] In the embodiment of the present invention, the first time variable is used to store the timestamp value recorded when the last log was reported. The second time variable is used to store the timestamp value corresponding to the current moment. Through these two time variables, the system can accurately track the time of the last log report and the current time, thereby providing a data basis for subsequent time difference calculation.

[0099] This embodiment provides an interface automation testing method based on data preprocessing, which can be used for the above-mentioned computer. Figure 4 is a flow chart of an interface automation testing method based on data preprocessing according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:

[0100] Step S401, determine whether the time difference between the timestamp value corresponding to the current moment and the timestamp value corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested. For details, see Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0101] Step S402: If it is greater than the first preset time period threshold, read the original log information generated when the target module to be tested is running, and at the same time, modify the value of the log time variable in the original log information to the value of the timestamp corresponding to the current moment, report the modified log information to the database, and then record the value of the timestamp corresponding to the current moment, so as to calculate the difference between the value of the timestamp corresponding to the next log reporting moment and the next log reporting moment. For details, please refer to Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0102] Step S403, enter a waiting state until the duration of the waiting state reaches a second preset time period threshold; wherein the second preset time period threshold is negatively correlated with the data processing complexity value of the target module to be tested, or the second preset time period threshold is positively correlated with the data response speed value of the target module to be tested.

[0103] It is understandable that before querying the target log information, the waiting state is entered first until the waiting time reaches the second preset time period threshold, ensuring that the database has enough time to complete data processing and response, avoiding the data not being generated or processed in time due to data processing complexity or slow response speed, affecting the accuracy of interface testing during product iteration.

[0104] The second preset time period threshold is negatively correlated with the data processing complexity value of the target module to be tested, or the second preset time period threshold is positively correlated with the data response speed value of the target module to be tested.

[0105] Example 1: If the data processing complexity of the target module to be tested is high, the second preset time period threshold should be relatively large to allow sufficient time for data processing to complete (the complexity value reaches 100, and the second preset time period threshold / s reaches 3600). Conversely (the complexity value reaches 80, and the second preset time period threshold / s reaches 3000), the higher the complexity, the larger the threshold.

[0106] Example 2: If the data response speed of the target module to be tested is slow, the second preset time period threshold should be relatively large to give the database enough time to respond and return data (the response speed value, in units of times / s, reaches 100, and the second preset time period threshold / s reaches 3600), otherwise (the response speed value, in units of times / s, reaches 50, and the second preset time period threshold / s reaches 7200). The slower the response speed, the larger the threshold.

[0107] In the embodiment of the present invention, before querying the target log information, a waiting state is first entered until the waiting time reaches the second preset time period threshold, so as to ensure that the database has enough time to complete data processing and response, and avoid the situation where data is not generated or processed in time due to data processing complexity or slow response speed, which affects the accuracy of interface testing during product iteration.

[0108] Step S404: query the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, wherein the target time interval represents the time interval corresponding to the first preset time period threshold shifted forward from the current moment. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.

[0109] Step S405, if the target log information does not contain the original log information reported to the database, then after an interval of the second preset time period threshold, continue to query the target log information within the target time interval in the database based on the interface to be tested corresponding to the target module to be tested, until the target log information contains the original log information reported to the database.

[0110] Specifically, after querying the target log information, if the reported original log information is not found in the target log information, a loop query process is entered. In the loop, the target log information in the database is queried once every second preset time period threshold until the target log information containing the reported original log information is found, which can avoid frequent database queries and control the frequency of testing.

[0111] It is understandable that the reason for re-querying after the second preset time period threshold is that the target log information may not contain the latest original log information when the query is first made. This is caused by the high data processing complexity of the target module to be tested or the slow response speed of the database. If the test is terminated immediately, the latest and accurate log information cannot be obtained, which affects the accuracy of the test results.

[0112] By querying again at certain intervals, you can ensure that the database has enough time to complete data processing and response, so that you can query the target log information containing the latest original log information. After the product is iterated and the interface is modified, you can still use the latest log data for testing, which improves the accuracy of the test results.

[0113] Step S406: If the target log information contains the original log information reported to the database, a logic test of the interface to be tested is performed based on the target log information to obtain the test result of the interface to be tested. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.

[0114] For example, refer to Figure 5 , first obtain the variable POST TIME in the system, which records the timestamp of the last log report. Determine whether the time difference between the current time and the system variable POST TIME is greater than the preset 1 hour: If the time difference between the current time and POST TIME is greater than 1 hour, assign the current time to the system variable POST TIME as the new report time. Read the original log file generated when the target module to be tested is running. Update the log timestamp in the read original log file to the timestamp of the current time. Then report the modified log information to the Elasticsearch database for subsequent data query and verification. After the report is completed, the system enters a waiting state for 1 minute to ensure that the Elasticsearch database has sufficient time for data processing and response. After the waiting time reaches 1 minute, use the Web interface related to the target module to be tested to query the log information within the last 1 hour from Elasticsearch to confirm whether it contains the original log information just reported. If the query result contains the reported original log information, the process ends and confirms that the report is successful. If the query result does not contain the reported original log information, enter the loop query process. In the loop query, the log information within the last hour is queried from the Elasticsearch database every 1 minute until the query result contains the original log information reported. If the time difference between the current time and the POST TIME is less than or equal to 1 hour, the process ends directly.

[0115] In addition, in addition to being used in the automation of Web interface use cases related to data preprocessing, the embodiments of the present invention can also set variables in certain specific fields in the original log, and report the log at a regular interval by reading the variable values. The reported log can display data on various pages and query functions when testing web functions or presenting to customers.

[0116] In an embodiment of the present invention, when the target log information does not contain the reported original log information, it is queried again after an interval. That is to say, if the updated original log information is not found in the target log information in the initial query, it means that the log data may not have been completely processed, and the queried log is not the latest and accurate log. At this time, the test will not be terminated immediately, but after an interval of a second preset time period threshold, the target log information in the database will continue to be queried, thereby avoiding frequent queries to the database, controlling the frequency of testing, and ensuring that the latest log data can still be used for testing after product iterations and interface modifications, thereby improving the accuracy of the test results.

[0117] In the present embodiment, an interface automation test system based on data preprocessing is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the system described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.

[0118] This embodiment provides an interface automation test system based on data preprocessing, such as Figure 6 As shown, including:

[0119] The time difference judgment module 601 is used to judge whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested;

[0120] The log processing and reporting module 602 is used to read the original log information generated when the target module to be tested is running, and at the same time, modify the value of the log time variable in the original log information to the value of the timestamp corresponding to the current moment, report the modified log information to the database, and then record the value of the timestamp corresponding to the current moment, so as to calculate the difference between the value of the timestamp corresponding to the next log reporting moment and the next log reporting moment;

[0121] The log query module 603 is used to query the target log information within the target time interval in the database based on the interface to be tested corresponding to the target module to be tested, wherein the target time interval range represents the time interval range corresponding to the first preset time period threshold shifted forward from the current moment;

[0122] The interface testing module 604 is used to perform a logic test on the interface to be tested based on the target log information if the target log information contains the original log information reported to the database, and obtain a test result of the interface to be tested.

[0123] In some optional implementations, the time difference determination module 601 includes:

[0124] A timestamp acquisition unit, used to acquire a value corresponding to a first time variable and a value corresponding to a second time variable, wherein the first time variable is used to store the value of the timestamp recorded when the last log was reported, and the second time variable is used to store the value of the timestamp corresponding to the current moment;

[0125] The time difference judgment unit is used to judge whether the time difference value obtained by subtracting the value corresponding to the first time variable from the value corresponding to the second time variable is greater than a first preset time period threshold.

[0126] In some optional embodiments, the above system further includes:

[0127] Enter a waiting state until the duration of the waiting state reaches a second preset time period threshold; wherein the second preset time period threshold is negatively correlated with the data processing complexity value of the target module to be tested, or the second preset time period threshold is positively correlated with the data response speed value of the target module to be tested.

[0128] In some optional embodiments, the above system further includes:

[0129] If the target log information does not contain the original log information reported to the database, then after a second preset time period threshold, continue to query the target log information within the target time interval in the database based on the interface to be tested corresponding to the target module to be tested until the target log information contains the original log information reported to the database.

[0130] In some optional implementations, the interface to be tested includes a data processing code logic fragment; the interface testing module 604 includes:

[0131] A data processing result verification unit, used to obtain the output actual data processing result according to inputting the target log information into the data processing code logic fragment;

[0132] The data collection result verification unit is used to determine whether the actual data processing result is the same as the preset expected processing result. If they are the same, the data processing code logic fragment test of the interface to be tested passes; if they are different, the data processing code logic fragment test of the interface to be tested fails.

[0133] In some optional implementations, the interface to be tested includes a data acquisition code logic fragment; the interface test module 604 includes:

[0134] The data processing logic test unit is used to determine whether the target log information is the same as the preset expected log information. If they are the same, the data acquisition code logic fragment test of the interface to be tested passes; if they are not the same, the data acquisition code logic fragment test of the interface to be tested fails.

[0135] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0136] The interface automation test system based on data preprocessing in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0137] The embodiment of the present invention also provides a computer device having the above Figure 6 The interface automation testing system based on data preprocessing is shown.

[0138] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.

[0139] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0140] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.

[0141] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0142] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0143] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0144] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0145] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0146] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the defined scope.

Claims

1. An interface automation testing method based on data preprocessing, characterized in that: Applied to an automated testing framework, the method comprises: Determine whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested; If it is greater than the first preset time period threshold, the original log information generated when the target module to be tested is running is read, and at the same time, the value of the log time variable in the original log information is modified to the value of the timestamp corresponding to the current moment, and the modified log information is reported to the database, and then the value of the timestamp corresponding to the current moment is recorded, so as to be used for the difference calculation between the value of the timestamp corresponding to the next log reporting moment and the next log reporting moment; Based on the interface to be tested corresponding to the target module to be tested, query the database for target log information within a target time interval, wherein the target time interval represents a time interval corresponding to a first preset time period threshold shifted forward from the current moment; If the target log information includes the original log information reported to the database, a logic test of the interface to be tested is performed based on the target log information to obtain a test result of the interface to be tested.

2. The method according to claim 1, characterized in that The determining whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than the first preset time period threshold specifically includes: Obtain a value corresponding to a first time variable and a value corresponding to a second time variable, wherein the first time variable is used to store the value of the timestamp recorded when the last log was reported, and the second time variable is used to store the value of the timestamp corresponding to the current moment; It is determined whether a time difference obtained by subtracting a value corresponding to the first time variable from a value corresponding to the second time variable is greater than the first preset time period threshold.

3. The method according to claim 1, characterized in that Before querying the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, the method further includes: Enter a waiting state until the duration of the waiting state reaches a second preset time period threshold; wherein the second preset time period threshold is negatively correlated with the data processing complexity value of the target module to be tested, or the second preset time period threshold is positively correlated with the data response speed value of the target module to be tested.

4. The method according to claim 3, characterized in that After querying the database for target log information within a target time interval based on the interface to be tested corresponding to the target module to be tested, the method further includes: If the target log information does not contain the original log information reported to the database, then after the second preset time period threshold, continue to query the target log information within the target time interval in the database based on the interface to be tested corresponding to the target module to be tested until the target log information contains the original log information reported to the database.

5. The method according to any one of claims 1 to 4, characterized in that: The interface to be tested includes a data processing code logic fragment; The performing a logic test of the interface to be tested based on the target log information to obtain a test result of the interface to be tested specifically includes: According to inputting the target log information into the data processing code logic fragment, an actual data processing result is obtained as an output; Determine whether the actual data processing result is the same as the preset expected processing result. If they are the same, the data processing code logic fragment test of the interface to be tested passes; if they are different, the data processing code logic fragment test of the interface to be tested fails.

6. The method according to any one of claims 1 to 4, characterized in that: The interface to be tested includes a data acquisition code logic fragment; The performing a logic test of the interface to be tested based on the target log information to obtain a test result of the interface to be tested specifically includes: Determine whether the target log information is the same as the preset expected log information. If they are the same, the data acquisition code logic fragment test of the interface to be tested passes; if they are not the same, the data acquisition code logic fragment test of the interface to be tested fails.

7. An interface automation test system based on data preprocessing, characterized in that: The system comprises: A time difference judgment module is used to judge whether the time difference between the value of the timestamp corresponding to the current moment and the value of the timestamp corresponding to the last log report is greater than a first preset time period threshold, wherein the first preset time period threshold is negatively correlated with the data processing frequency value of the target module to be tested; The log processing and reporting module is used to read the original log information generated when the target module to be tested is running, and at the same time, modify the value of the log time variable in the original log information to the value of the timestamp corresponding to the current moment, report the modified log information to the database, and then record the value of the timestamp corresponding to the current moment, so as to calculate the difference between the value of the timestamp corresponding to the next log reporting moment and the next log reporting moment; A log query module, used to query the target log information within a target time interval in the database based on the interface to be tested corresponding to the target module to be tested, wherein the target time interval represents the time interval corresponding to the first preset time period threshold shifted forward from the current moment; The interface testing module is used to perform a logic test of the interface to be tested based on the target log information if the target log information contains the original log information reported to the database, and obtain a test result of the interface to be tested.

8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the interface automation testing method based on data preprocessing described in any one of claims 1 to 6 by executing the computer instructions.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the interface automation testing method based on data preprocessing according to any one of claims 1 to 6.

10. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to enable a computer to execute the interface automatic testing method based on data preprocessing according to any one of claims 1 to 6.