Code testing method and device, equipment, medium and program product

By creating shadow tables in code testing and performing data synchronization and performance testing, the problem of insufficient data in the test database was solved, resulting in more accurate and reliable test results, and ensuring the stability of the code in the production environment and the user experience.

CN121833545APending Publication Date: 2026-04-10INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-31
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Traditional code testing methods often suffer from insufficient test data in the test database, leading to significant differences between the test and production environments. This results in inadequate testing, low accuracy and reliability of the generated test results, increased risk of code running in the production environment, and reduced user experience.

Method used

Obtain the names and table structures of key tables from the production database, create shadow tables and synchronize the data, perform performance testing on the target test code using the shadow tables, and optimize the target test code if it fails, including code lightweighting, index optimization and business logic refactoring.

Benefits of technology

It improves the accuracy and reliability of performance test results for the target test code, ensures data security and stability, reduces code maintenance costs, and enhances user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833545A_ABST
    Figure CN121833545A_ABST
Patent Text Reader

Abstract

The invention provides a code testing method. The method can be applied to the technical fields of financial science and technology and big data. The method comprises the following steps: obtaining names of n key tables and table structures of the n key tables from a production database, and creating shadow tables according to the names of the n key tables and the table structures of the n key tables to generate n first shadow tables; and obtaining data in the n key tables, performing data synchronization on the n first shadow tables according to the data in the n key tables, and generating n target shadow tables. And obtaining a target test code, performing performance test on the target test code based on the n target shadow tables, and generating a performance test result of the target test code. And if the performance test result of the target test code is that the test is not passed, performing data optimization on the target test code. The invention further provides a code testing device and equipment, a storage medium and a program product.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of big data, in particular to the technical field of financial technology, and more particularly to a code testing method and device, equipment, medium and program product. BACKGROUND

[0002] With the progress of computer technology, enterprises including banks have gradually increased the demand for code testing in the software development process. The traditional code testing method generally sends test code to a test database for code testing, and the test data in the traditional test database is generally the key data in the production database, not the full data in the production database.

[0003] This traditional code testing method can easily lead to insufficient test data available in the test database, making the test environment and the production environment differ greatly, resulting in insufficient testing, low accuracy and poor reliability of the test results, and increasing the risk of code running in the production environment, which reduces the user experience. SUMMARY

[0004] In view of the above problems, the present application provides a code testing method, device, equipment, medium and program product.

[0005] According to a first aspect of the present application, a code testing method is provided, which comprises: obtaining the names of n key tables and the table structures of n key tables from a production database, creating shadow tables according to the names of n key tables and the table structures of n key tables, and generating n first shadow tables, wherein n is an integer and n is greater than 0; obtaining data in the n key tables, synchronizing the data in the n key tables with the n first shadow tables to generate n target shadow tables; obtaining target test code, performing performance testing on the target test code based on the n target shadow tables, and generating performance test results of the target test code; and if the performance test results of the target test code are not passed, performing data optimization on the target test code.

[0006] According to an embodiment of the present application, the shadow table creation is performed according to the naming of the n key tables and the table structure of the n key tables, to generate n first shadow tables, including: presetting a naming rule of the shadow table; performing naming mapping on the naming of the n key tables based on the naming rule of the shadow table, to generate the naming of the n shadow tables, wherein the naming of the n key tables and the naming of the n shadow tables have a one-to-one mapping relationship; generating n second shadow tables based on the naming of the n shadow tables; and performing table structure synchronization on the n second shadow tables based on the table structure of the n key tables, to generate n first shadow tables, wherein the table structure of the n first shadow tables is consistent with the table structure of the n key tables.

[0007] According to an embodiment of the present application, the data synchronization is performed on the n first shadow tables according to the data in the n key tables, to generate n target shadow tables, including: performing sensitive data replacement on the data in the n key tables, to generate n key tables after data replacement; performing sensitive data masking on the data in the n key tables after data replacement, to generate n key tables after data masking; performing sensitive data generalization on the data in the n key tables after data masking, to generate n key tables after data generalization; performing sensitive data encryption on the data in the n key tables after data generalization, to generate n key tables after data encryption; and synchronizing the data in the n key tables after data encryption into the n first shadow tables, to generate n target shadow tables.

[0008] According to an embodiment of the present application, the performance test is performed on the target test code based on the n target shadow tables, to generate a performance test result of the target test code, including: obtaining a structured query language operation statement in the target test code, replacing the naming of m key tables called in the structured query language operation statement in the target test code with the naming of the target shadow tables, so that the structured query language operation statement in the target test code calls m target shadow tables for database access, wherein m is an integer, m is greater than 0 and m is less than n; determining a performance index of the structured query language operation statement in the target test code calling m target shadow tables for database access; and generating the performance test result of the target test code based on the performance index.

[0009] According to an embodiment of the present application, the performance index includes a response time, a resource consumption and a database specific index, and the performance test result of the target test code is generated based on the performance index, including: presetting a performance index threshold; performing weighted calculation on the response time, the resource consumption and the database specific index, to generate the performance index; and if the performance index is greater than the performance index threshold, determining that the performance test result of the target test code is test failed.

[0010] According to the embodiment of the present application, the data optimization on the target test code comprises: code lightweight processing on the target test code to generate lightweight target test code; index optimization processing on the code lightweight target test code to generate index optimized target test code; and business logic reconstruction processing on the index optimized target test code to generate business logic reconstructed target test code.

[0011] According to the embodiment of the present application, the method further comprises: sending the performance test result of the target test code through a development tool extension plug-in, an email or an instant message.

[0012] According to the second aspect of the present application, a code testing device is provided, comprising: a first generation module configured to obtain the names of n key tables and the table structures of the n key tables from a production database, create shadow tables according to the names of the n key tables and the table structures of the n key tables, and generate n first shadow tables, wherein n is an integer and n is greater than 0; a second generation module configured to obtain data in the n key tables, synchronize the n first shadow tables according to the data in the n key tables, and generate n target shadow tables; a third generation module configured to obtain target test code, perform performance test on the target test code based on the n target shadow tables, and generate a performance test result of the target test code; and a first optimization module configured to perform data optimization on the target test code if the performance test result of the target test code is test failure.

[0013] According to the third aspect of the present application, an electronic device is provided, comprising: one or more processors; a memory configured to store one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the above method.

[0014] The fourth aspect of the present application further provides a computer readable storage medium having a computer program or instructions stored thereon, wherein the computer program or instructions are executed by a processor to implement the steps of the above method.

[0015] The fifth aspect of the present application further provides a computer program product comprising a computer program or instructions, wherein the computer program or instructions are executed by a processor to implement the steps of the above method.

[0016] The application creates a shadow table, synchronizes data of the shadow table, performs performance testing on the target test code according to the shadow table, and performs data optimization on the target test code if the test fails. The test environment and the production environment are isolated by using the shadow table to ensure the safety and stability of the data. And through performance testing and subsequent optimization mechanism, it can ensure that the code in the test phase can guarantee good performance indicators. Overall, it realizes the technical effects of improving the accuracy and reliability of the performance test results of the generated target test code, improving the quality of the test code, avoiding production problems, saving code maintenance costs, and improving user experience. The technical problem of the prior art that the available test data in the test database is insufficient when testing the code, the difference between the test environment and the production environment is large, the test is insufficient, the accuracy of the test results is low, the reliability is poor, and the risk of the code running in the production environment is high, and the user experience is reduced. BRIEF DESCRIPTION OF DRAWINGS

[0017] The above and other objects, features and advantages of the present application will become more apparent from the following description of embodiments of the present application, taken in conjunction with the accompanying drawings, in which:

[0018] Figure 1 An application scenario diagram of a code testing method, device, equipment, medium and program product according to embodiments of the present application is schematically shown;

[0019] Figure 2 A flowchart of a code testing method according to embodiments of the present application is schematically shown;

[0020] Figure 3 A flowchart of generating n first shadow tables in a code testing method according to embodiments of the present application is schematically shown;

[0021] Figure 4 A flowchart of generating n target shadow tables in a code testing method according to embodiments of the present application is schematically shown;

[0022] Figure 5 An embodiment flowchart of generating a performance test result of a target test code in a code testing method according to embodiments of the present application is schematically shown;

[0023] Figure 6 Another embodiment flowchart of generating a performance test result of a target test code in a code testing method according to embodiments of the present application is schematically shown;

[0024] Figure 7 A flowchart of performing data optimization on a target test code in a code testing method according to embodiments of the present application is schematically shown;

[0025] Figure 8A structural block diagram of a code testing apparatus according to an embodiment of the present application is schematically shown;

[0026] Figure 9 A block diagram of an electronic device suitable for implementing the code testing method according to an embodiment of the present application is schematically shown. DETAILED DESCRIPTION

[0027] Hereinafter, embodiments of the present application will be described with reference to the accompanying drawings. It is to be understood, however, that these descriptions are merely exemplary and are intended to illustrate the scope of the present application, not to limit it. In the following detailed description of the embodiments of the present application, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to one skilled in the art that the embodiments of the present application can be practiced without these specific details. In other instances, well-known structures and functions have not been described in detail in order to avoid obscuring aspects of the present application.

[0028] The terms used herein are merely used to describe specific embodiments, and are not intended to limit the present application. The terms "include" and "have" and the like used herein indicate the presence of the described features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0029] All terms used herein, including technical and scientific terms, have the same meanings as those generally understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having meanings consistent with the context of the present description, and should not be interpreted in an idealized or excessively formal manner.

[0030] In the case of using expressions similar to "at least one of A, B, and C, etc.", it is generally construed that the meaning of the expression is the same as that of "at least one of A and B; at least one of B and C; at least one of A, B, and C; etc." in terms of a meaning that one or more of the plurality of elements are included in a certain group.

[0031] Some of the blocks and / or flowcharts in the drawings represent computer program instructions or programs. These computer program instructions can be provided to a processor of a general purpose computer, a special purpose computer, or other programmable control apparatus to create means for implementing the functions / operations specified in the block(s) and / or flowchart(s).

[0032] First, technical terms appearing in the present document are explained as follows:

[0033] SQL (Structured Query Language), or Structured Query Language, is a standard programming language used to manage and manipulate relational databases. It allows users to store, query, update, and manage data.

[0034] SQL request traffic is the sum of real-time, continuous SQL queries and operations initiated by applications on databases in actual running, user-oriented production environment business systems.

[0035] Traffic capture and playback refers to the process of recording all SQL requests (including queries, inserts, updates, deletions, and other operations) in a production environment and re-executing these requests in a test environment to simulate real scenarios.

[0036] Shadow table: A table created in the test database that is identical in structure to the production environment table, used to store desensitized real data synchronized from the production environment, with the purpose of simulating real data scenarios without affecting the production environment.

[0037] SQL redirector: A component that automatically rewrites table names in SQL statements executed by developers in the test environment to corresponding shadow table names, ensuring that SQL is executed on shadow tables.

[0038] SQL performance monitor: A tool for monitoring the efficiency of SQL statement execution on shadow tables. When execution time exceeds a preset threshold, an alarm is triggered and optimization suggestions are provided.

[0039] The embodiments of the present application provide a code testing method, which comprises: obtaining the names of n key tables and the table structures of the n key tables from a production database, creating shadow tables according to the names of the n key tables and the table structures of the n key tables, and generating n first shadow tables, wherein n is an integer and n is greater than 0. Obtain data in the n key tables, synchronize the n first shadow tables according to the data in the n key tables, and generate n target shadow tables. Obtain target test code, perform performance testing on the target test code based on the n target shadow tables, and generate performance test results of the target test code. If the performance test results of the target test code are test failed, perform data optimization on the target test code.

[0040] According to the embodiment of the present application, by creating a shadow table, synchronizing data of the shadow table, performing performance testing on the target test code according to the shadow table, and performing data optimization on the target test code if the test fails, the test environment and the production environment are isolated by using the shadow table, and the safety and stability of the data are ensured. And through the performance testing and the subsequent optimization mechanism, it can ensure that the code in the test phase can guarantee good performance indicators. Overall, it realizes the technical effects of improving the accuracy and reliability of the performance test results of the generated target test code, improving the quality of the test code, avoiding production problems, saving code maintenance costs, and improving user experience. It solves the technical problems in the prior art that the available test data in the test database is insufficient when testing the code, the difference between the test environment and the production environment is large, the test is insufficient, the accuracy of the test results is low, the reliability is poor, the risk of the code running in the production environment is high, and the user experience is reduced.

[0041] Figure 1 The application scenario of the code testing method, apparatus, device, medium and program product according to the embodiment of the present application is schematically shown. It should be noted that, Figure 1 The shown is only an example of the scenario to which the embodiments of the present application can be applied, to help those skilled in the art understand the technical content of the present application, but does not mean that the embodiments of the present application cannot be applied to other devices, systems, environments or scenarios.

[0042] As Figure 1 The application scenario 100 according to the embodiment can include the application scenario of code testing, as shown. The network 104 is a medium for providing communication links between the first terminal device 101, the second terminal device 102, the third terminal device 103 and the server 105. The network 104 can include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0043] The user can use the first terminal device 101, the second terminal device 102, the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0044] The first terminal device 101, the second terminal device 102, the third terminal device 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smartphones, tablet computers, laptop computers and desktop computers, etc.

[0045] Server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (this is just an example). The backend management server can analyze and process data such as received user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal devices.

[0046] It should be noted that the code testing method provided in this application embodiment can generally be executed by server 105. Correspondingly, the code testing device provided in this application embodiment can generally be located in server 105. The code testing method provided in this application embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105. Correspondingly, the code testing device provided in this application embodiment can also be located in a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105.

[0047] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0048] The following will be based on Figure 1 The described scene, through Figures 2-7 The code testing method of the disclosed embodiments is described in detail. It should be noted that the above application scenarios are shown only to facilitate understanding of the spirit and principles of this application, and the implementation methods of this application are not limited in any way. On the contrary, the implementation methods of this application can be applied to any applicable scenario.

[0049] Figure 2 A flowchart illustrating a code testing method according to an embodiment of this application is shown schematically.

[0050] like Figure 2 As shown, the method 200 includes steps S201 to S204.

[0051] Step S201: Obtain the names and table structures of n key tables from the production database. Create shadow tables based on the names and table structures of the n key tables to generate n first shadow tables, where n is an integer and n is greater than 0.

[0052] Figure 3A flowchart of generating n first shadow tables in a code testing method according to an embodiment of the present application is shown.

[0053] As shown in Figure 3 The method 300 includes steps S301-S304.

[0054] In step S301, a naming rule of a shadow table is preset.

[0055] For example, the naming rule can be preset as original table name_shadow, such as user table_shadow.

[0056] In step S302, based on the naming rule of the shadow table, naming mapping is performed on the naming of the n key tables to generate the naming of the n shadow tables, wherein the naming of the n key tables and the naming of the n shadow tables have a one-to-one mapping relationship.

[0057] In step S303, based on the naming of the n shadow tables, n second shadow tables are generated.

[0058] For example, according to the preset naming rule of the shadow table, n corresponding shadow tables can be created in the test database for the n key tables in the production environment.

[0059] In step S304, based on the table structure of the n key tables, table structure synchronization is performed on the n second shadow tables to generate n first shadow tables, wherein the table structure of the n first shadow tables is consistent with the table structure of the n key tables.

[0060] For example, field table structure synchronization can be performed on the n second shadow tables, or index table structure synchronization can be performed on the n second shadow tables, or constraint table structure synchronization can be performed on the n second shadow tables to generate n first shadow tables with the same table structure as the key tables.

[0061] By generating the naming of the n shadow tables having a mapping relationship with the naming of the n key tables through the naming rule, and then performing table structure synchronization to generate n first shadow tables consistent with the table structure of the n key tables, the consistency of the shadow tables and the production tables can be effectively improved, and the test effectiveness can be improved. At the same time, the shadow tables are easy to identify, which greatly shortens the preparation time of the test environment and improves the test efficiency.

[0062] Referring back to Figure 2 In step S202, data in the n key tables is obtained, and data synchronization is performed on the n first shadow tables according to the data in the n key tables to generate n target shadow tables.

[0063] For example, the SQL request traffic in the n key tables can be acquired by a traffic capture and playback tool, the data in the n key tables is synchronized to the n first shadow tables according to a preset synchronization frequency to generate n target shadow tables. The synchronization frequency can be set to real-time, timing or manual triggering according to requirements.

[0064] Figure 4 A flowchart of generating n target shadow tables in the code testing method according to an embodiment of the application is schematically shown.

[0065] As shown in the method 400, the method 400 includes steps S401-S405. Figure 4

[0066] Step S401, sensitive data in the n key tables is replaced to generate n key tables after data replacement.

[0067] For example, the sensitive data such as ID card in the n key tables can be replaced by replacement data generated according to rules to generate n key tables after data replacement.

[0068] Step S402, sensitive data in the n key tables after data replacement is masked to generate n key tables after data masking.

[0069] For example, the sensitive data such as mobile phone number or card number in the n key tables can be masked partially, for example, 138****1234.

[0070] Step S403, sensitive data in the n key tables after data masking is generalized to generate n key tables after data generalization.

[0071] For example, the specific data such as age in the n key tables can be converted to a range value, for example, the specific age is converted to 20-30 years old.

[0072] Step S404, sensitive data in the n key tables after data generalization is encrypted to generate n key tables after data encryption.

[0073] For example, part of the sensitive data in the n key tables can be irreversibly hashed and encrypted to keep the data format and uniqueness, but not to expose the real data.

[0074] Step S405, the data in the n key tables after data encryption is synchronized to the n first shadow tables to generate n target shadow tables.

[0075] For example, the data in the n key tables after data encryption can be incrementally or fully synchronized to the shadow tables by a data synchronization tool or a database synchronization technology. ​

[0076] The data desensitization in the manners of sensitive data replacement, sensitive data masking, sensitive data generalization and sensitive data encryption can greatly protect the data security of sensitive data, and meanwhile ensure the accuracy of data synchronization, thereby ensuring the reliability of the generated target shadow table and the data security.

[0077] Referring back to Figure 2 In step S203, a target test code is acquired, performance test is performed on the target test code based on the n target shadow tables, and a performance test result of the target test code is generated.

[0078] Figure 5 An embodiment flowchart of generating a performance test result of a target test code in a code test method according to an embodiment of the application is schematically shown.

[0079] As Figure 5 shown, the method 500 includes steps S501-S503.

[0080] In step S501, a structured query language operation statement in the target test code is acquired, and the naming of m key tables called in the structured query language operation statement in the target test code is replaced with the naming of the target shadow tables, so that the structured query language operation statement in the target test code calls m target shadow tables for database access, where m is an integer, m is greater than 0 and m is less than n.

[0081] For example, the target test code includes an SQL operation statement, for example, the target code can include an SQL operation statement such as "SELECT * FROM user table WHERE...". When the test code connects to the test database, the SQL statement can be intercepted by the SQL redirector. The SQL redirector automatically replaces the table name in the SQL with the corresponding shadow table name through regular matching or syntax analysis, for example, replaces "user table" with "user table_shadow", so that the replaced SQL statement is executed on the shadow table.

[0082] In step S502, a performance index of the structured query language operation statement in the target test code calling m target shadow tables for database access is determined.

[0083] In step S503, a performance test result of the target test code is generated based on the performance index.

[0084] For example, the performance indicators can include: response time, resource consumption and database specific indicators. The response time can include: SQL execution time. The resource consumption can include: CPU, memory and disk I / O usage. The database specific indicators can include: lock waiting time, cache hit time and temporary table usage time, etc.

[0085] Figure 6 An embodiment of a flowchart of generating a performance test result of a target test code in a code testing method according to an embodiment of the present application is shown.

[0086] As shown in Figure 6 The method 600 includes steps S601-S603.

[0087] In step S601, a performance indicator threshold is preset.

[0088] In step S602, the response time, the resource consumption and the database specific indicators are weighted and calculated to generate the performance indicator.

[0089] For example, a response time value, a resource consumption value and a database specific indicator value can be obtained. A first weight of the response time, a second weight of the resource consumption and a third weight of the database specific indicators are preset. A first associated value of the response time value and the first weight is calculated, a second associated value of the resource consumption value and the second weight is calculated, and a third associated value of the database specific indicator value and the third weight is calculated. The sum of the first associated value, the second associated value and the third associated value is calculated as the performance indicator.

[0090] In step S603, if the performance indicator is greater than the performance indicator threshold, it is determined that the performance test result of the target test code is test failed.

[0091] By weighting and calculating the response time, the resource consumption and the database specific indicators to generate the performance indicator, and by presetting the threshold to determine the performance test result of the target test code, the authenticity and effectiveness of generating the performance test result of the target test code can be effectively improved.

[0092] In addition, a single data in the response time, the resource consumption and the database specific indicators can also be used as the performance indicator. For example, the response time can be used as the performance indicator. In a specific embodiment, a SQL performance monitor is used to capture all SQL statements executed on the shadow table in real time, and record the execution time, the number of scanned rows, the index usage and other key indicators. The monitor compares the execution time with a preset threshold (e.g. 500 ms), and if the execution time exceeds the threshold, it is determined as a slow query. The monitor compares the execution time with a preset threshold (e.g. 500 ms), and if the execution time exceeds the threshold, it is determined as a slow query, indicating that the performance test result of the target test code is test failed.

[0093] According to the embodiments of the present application, the SQL performance early warning report in the performance test result can be input into the pre-trained data repair model to generate a repair suggestion.

[0094] By testing the performance indicators of the target test code calling m target shadow tables for database access, the performance test result of the target test code is generated. The target shadow table can effectively improve the testing efficiency, improve the accuracy of the test, and improve the reliability and accuracy of the performance test result of the generated target test code. Referring back Figure 2 In step S204, if the performance test result of the target test code fails the test, the target test code is optimized.

[0095] Figure 7 The flowchart of the data optimization of the target test code in the code testing method according to the embodiments of the present application is schematically shown.

[0096] As Figure 7 The method 700 includes steps S701-S703.

[0097] Step S701, the target test code is subjected to code lightweight processing to generate a lightweight target test code.

[0098] For example, full table scanning can be avoided, and a join query can be used instead of a subquery to generate a lightweight target test code.

[0099] Step S702, the code lightweight target test code is subjected to index optimization processing to generate an index optimized target test code.

[0100] For example, missing indexes can be added or composite index sequences can be optimized for index optimization processing to generate an index optimized target test code.

[0101] Step S703, the index optimized target test code is subjected to business logic reconstruction processing to generate a business logic reconstructed target test code.

[0102] For example, the business logic reconstruction processing can be performed by processing data in batches to generate a business logic reconstructed target test code.

[0103] The code execution efficiency can be improved by code lightening of the target test code, the data access speed can be improved by index optimization of the target test code, and the code processing flow can be optimized by business logic reconstruction of the target test code, so that the performance of the optimized target test code is effectively improved, the target code is improved, the code delivery is facilitated, the overall software development efficiency is improved, and the time cost and manpower cost are saved.

[0104] According to the embodiment of the application, the performance test result of the target test code can be sent through a development tool extension plug-in, an email or an instant message.

[0105] The performance test result can further include an SQL performance warning report. For example, in a specific embodiment, the SQL performance warning report can include a test executed SQL statement "SELECT * FROM user_table_shadow WHERE age > 30", at this time, the time consumption under the production environment simulation data is 1200 ms, which exceeds the threshold of 500 ms, and there may be a performance risk! The suggestion for optimization is to add an index on the `age` field or use a paging query. The performance test result can be sent to relevant personnel through a development tool extension plug-in, an email or an instant message.

[0106] The performance test result is sent in a targeted manner, so that the timeliness of the performance test result is improved, the processing speed of the test code is effectively improved, and the efficiency of the overall software development process is significantly improved, thereby improving the user experience.

[0107] According to the embodiment of the application, if the performance index is less than or equal to the performance index threshold, it is determined that the performance test result of the target test code is test passed, and a test passed report is directly generated and sent.

[0108] According to the embodiment of the application, the method can record all SQL requests received by the production database like a video recorder without affecting the online business. In the test database, a "shadow table" is created for important data tables. The structure of the shadow table is exactly the same as that of the real table, and stores the real mass data synchronized from the production environment after desensitization. When running the new code in the test environment, the system automatically and transparently directs all SQL statements generated by the code to the corresponding "shadow table" for execution. The system monitors the execution efficiency of these SQL statements on the shadow table, and immediately alerts the developer once a slow execution of a statement is found. The performance bottleneck can be exposed during the code development or test stage, greatly reducing the maintenance cost.

[0109] Figure 8 The structural block diagram of the code testing device according to the embodiment of the application is schematically shown.

[0110] As Figure 8 shown, the apparatus 800 includes a first generating module 801, a second generating module 802, a third generating module 803, and a first optimizing module 804.

[0111] The first generating module 801 is configured to acquire the names of n key tables and the table structures of the n key tables from a production database, perform shadow table creation according to the names of the n key tables and the table structures of the n key tables, and generate n first shadow tables, where n is an integer and n is greater than 0. In an embodiment, the first generating module 801 can be configured to perform the step S201 described above.

[0112] The first generating module 801 includes a first preset module, a fourth generating module, a fifth generating module, and a sixth generating module.

[0113] The first preset module is configured to preset a naming rule of the shadow tables. In an embodiment, the first preset module can be configured to perform the step S301 described above, and details are not described herein again.

[0114] The fourth generating module is configured to perform naming mapping on the names of the n key tables based on the naming rule of the shadow tables, and generate the names of the n shadow tables, where the names of the n key tables and the names of the n shadow tables have a one-to-one mapping relationship. In an embodiment, the fourth generating module can be configured to perform the step S302 described above, and details are not described herein again.

[0115] The fifth generating module is configured to generate n second shadow tables based on the names of the n shadow tables. In an embodiment, the fifth generating module can be configured to perform the step S303 described above, and details are not described herein again.

[0116] The sixth generating module is configured to perform table structure synchronization on the n second shadow tables based on the table structures of the n key tables, and generate n first shadow tables, where the table structures of the n first shadow tables are consistent with the table structures of the n key tables. In an embodiment, the sixth generating module can be configured to perform the step S304 described above, and details are not described herein again.

[0117] The second generating module 802 is configured to acquire data in the n key tables, perform data synchronization on the n first shadow tables according to the data in the n key tables, and generate n target shadow tables. In an embodiment, the second generating module 802 can be configured to perform the step S202 described above.

[0118] The second generating module 802 includes a seventh generating module, an eighth generating module, a ninth generating module, a tenth generating module, and an eleventh generating module.

[0119] A seventh generating module is configured to perform sensitive data replacement on the data in the n key tables to generate n key tables after data replacement.

[0120] An eighth generating module is configured to perform sensitive data masking on the data in the n key tables after data replacement to generate n key tables after data masking.

[0121] A ninth generating module is configured to perform sensitive data generalization on the data in the n key tables after data masking to generate n key tables after data generalization.

[0122] A tenth generating module is configured to perform sensitive data encryption on the data in the n key tables after data generalization to generate n key tables after data encryption.

[0123] An eleventh generating module is configured to synchronize the data in the n key tables after data encryption to the n first shadow tables to generate n target shadow tables.

[0124] The third generating module 803 is configured to obtain target test code, perform performance testing on the target test code based on the n target shadow tables, and generate a performance testing result of the target test code.

[0125] The third generating module 803 includes a first replacing module, a first determining module, and a twelfth generating module.

[0126] The first replacing module is configured to obtain a structured query language operation statement in the target test code, replace a name of m key tables called in the structured query language operation statement in the target test code with a name of the m target shadow tables, so that the structured query language operation statement in the target test code calls the m target shadow tables to perform database access. m is an integer, m is greater than 0, and m is less than n. In an embodiment, the first replacing module can be configured to perform the step S501 described above, and details are not described herein again.

[0127] The first determining module is configured to determine a performance index of a structured query language operation statement in the target test code for database access by m target shadow tables. In an embodiment, the first determining module can be configured to perform the step S502 described above, and details are not repeated here.

[0128] The twelfth generating module is configured to generate a performance test result of the target test code based on the performance index. In an embodiment, the twelfth generating module can be configured to perform the step S503 described above.

[0129] The twelfth generating module includes a second preset module, a thirteenth generating module and a second determining module.

[0130] The second preset module is configured to preset a performance index threshold. In an embodiment, the second preset module can be configured to perform the step S601 described above, and details are not repeated here.

[0131] The thirteenth generating module is configured to perform weighted calculation on the response time, the resource consumption and the database-specific index to generate the performance index. In an embodiment, the thirteenth generating module can be configured to perform the step S602 described above, and details are not repeated here.

[0132] The second determining module is configured to determine that the performance test result of the target test code is a test failure if the performance index is greater than the performance index threshold. In an embodiment, the second determining module can be configured to perform the step S603 described above, and details are not repeated here.

[0133] The first optimization module 804 is configured to perform data optimization on the target test code if the performance test result of the target test code is a test failure. In an embodiment, the first optimization module 804 can be configured to perform the step S204 described above.

[0134] The first optimization module 804 includes a fourteenth generating module, a fifteenth generating module and a sixteenth generating module.

[0135] The fourteenth generating module is configured to perform code lightweight processing on the target test code to generate a lightweight target test code. In an embodiment, the fourteenth generating module can be configured to perform the step S701 described above, and details are not repeated here.

[0136] The fifteenth generating module is configured to perform index optimization processing on the code-lightweight target test code to generate an index-optimized target test code. In an embodiment, the fifteenth generating module can be configured to perform the step S702 described above, and details are not repeated here.

[0137] The sixteenth generating module is configured to perform business logic reconstruction processing on the index-optimized target test code, and generate a business logic reconstructed target test code. In an embodiment, the sixteenth generating module can be configured to perform the step S703 described above, and thus details are not repeated here.

[0138] According to an embodiment of the present application, the apparatus further includes a first sending module configured to send the performance test result of the target test code through a development tool extension plug-in, an email or an instant message.

[0139] According to an embodiment of the present application, any one or more of the first generating module 801, the second generating module 802, the third generating module 803 and the first optimizing module 804 can be combined in one module, or any one of them can be split into multiple modules. Alternatively, at least part of the function of one or more of these modules can be combined with at least part of the function of other modules, and implemented in one module. According to an embodiment of the present application, at least one of the first generating module 801, the second generating module 802, the third generating module 803 and the first optimizing module 804 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on chip, a system on board, a system on package, an application specific integrated circuit (ASIC), or any other reasonable way of hardware or firmware that can be integrated or packaged, or any one of software, hardware and firmware or any appropriate combination of any of them. Alternatively, at least one of the first generating module 801, the second generating module 802, the third generating module 803 and the first optimizing module 804 can be at least partially implemented as a computer program module which can perform corresponding functions when the computer program module is run.

[0140] Figure 9 A block diagram of an electronic device suitable for implementing the code testing method according to an embodiment of the present application is schematically shown.

[0141] As Figure 9As shown, the electronic device 900 according to an embodiment of the present application includes a processor 901 which can perform various appropriate actions and processes according to a program stored in a read only memory (ROM) 902 or a program loaded from a storage section 908 into a random access memory (RAM) 903. The processor 901 can include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor, and / or a related chipset, and / or a special purpose microprocessor (e.g., an application specific integrated circuit (ASIC)), and so on. The processor 901 can also include an on-board memory for cache use. The processor 901 can include a single processing unit or multiple processing units for executing different actions of the method processes according to embodiments of the present application.

[0142] In the RAM 903, various programs and data required for the operation of the electronic device 900 are stored. The processor 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. The processor 901 performs various operations of the method processes according to embodiments of the present application by executing the programs in the ROM 902 and / or the RAM 903. Note that the programs can also be stored in one or more memories other than the ROM 902 and the RAM 903. The processor 901 can also perform various operations of the method processes according to embodiments of the present application by executing the programs stored in the one or more memories.

[0143] According to embodiments of the present application, the electronic device 900 can also include an input / output (I / O) interface 905 which is also connected to the bus 904. The electronic device 900 can also include one or more of the following components connected to the input / output (I / O) interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a display such as a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the input / output (I / O) interface 905 as necessary. A removable medium 911 such as a magnetic disk, a magneto-optical disk, a semiconductor memory, etc. is attached to the drive 910 as necessary, so that a computer program read out from the removable medium 911 is installed in the storage section 908 as necessary.

[0144] The application further provides a computer readable storage medium, which can be included in the device / apparatus / system described in the above embodiments, or can exist independently without being assembled into the device / apparatus / system. The computer readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of the application.

[0145] According to the embodiments of the application, the computer readable storage medium can be a non-volatile computer readable storage medium, which can include, but is not limited to, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any appropriate combination thereof. In this application, a computer readable storage medium can be any tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to the embodiments of the application, the computer readable storage medium can include one or more of the above-described ROM 902 and / or RAM 903 and / or one or more memories other than the ROM 902 and the RAM 903.

[0146] The embodiments of the application also include a computer program product, which includes a computer program containing program codes for executing the methods shown in the flowcharts. When the computer program product is run in a computer system, the program codes are used to make the computer system implement the code testing method provided by the embodiments of the application.

[0147] The above-described functions defined in the system / apparatus of the embodiments of the application are performed when the computer program is executed by the processor 901. According to the embodiments of the application, the above-described system, apparatus, module, unit, etc. can be implemented by computer program modules.

[0148] In one embodiment, the computer program can rely on a tangible storage medium such as an optical storage device, a magnetic storage device, etc. In another embodiment, the computer program can also be transmitted, distributed, and downloaded in the form of a signal on a network medium, and be downloaded and installed through the communication part 909, and / or installed from the detachable medium 911. The program codes contained in the computer program can be transmitted by any appropriate network medium, including but not limited to wireless, wired, etc., or any appropriate combination thereof.

[0149] In such embodiments, the computer program can be downloaded and installed from the network via the communication section 909, and / or installed from the removable media 911. When the computer program is executed by the processor 901, the above-described functions defined in the system of the embodiments of the present application are performed. According to the embodiments of the present application, the system, device, apparatus, module, unit, and the like described above can be implemented by the computer program modules.

[0150] According to the embodiments of the present application, the program code for executing the computer program provided by the embodiments of the present application can be written in any combination of one or more programming languages, and specifically, these computer programs can be implemented using high-level procedural and / or object-oriented programming language, and / or assembly / machine language. The programming language includes, but is not limited to, such as Java, C++, python, "C" language, or similar programming language. The program code can be executed entirely on the user computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In the case involving a remote computing device, the remote computing device can be connected to the user computing device through any kind of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, connected to the Internet through an Internet service provider).

[0151] The flowcharts and block diagrams in the drawings illustrate the possible architectures, functionality, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a segment, or a portion of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks noted in succession can in fact be executed substantially concurrently or in the reverse order, depending on the functionality involved. It will also be noted that each block in the block diagrams or flowcharts, and combinations of blocks in the block diagrams or flowcharts, can be implemented by special-purpose hardware-based systems that perform the specified functions or operations, or can be implemented by a combination of special-purpose hardware and computer instructions.

[0152] Those skilled in the art can understand that the features described in various embodiments of the present application can be combined and / or integrated in various combinations and / or integrations, even if such combinations or integrations are not explicitly described in the present application. In particular, the features described in various embodiments of the present application can be combined and / or integrated in various combinations and / or integrations without departing from the spirit and teachings of the present application. All such combinations and / or integrations fall within the scope of the present application.

Claims

1. A code testing method, characterized in that, The method includes: Obtain the names and table structures of n key tables from the production database. Create shadow tables based on the names and table structures of the n key tables to generate n first shadow tables, where n is an integer and n is greater than 0. Obtain data from the n key tables, and based on the data from the n key tables, synchronize the data of the n first shadow tables to generate n target shadow tables; Obtain the target test code, perform performance testing on the target test code based on the n target shadow tables, and generate the performance test results of the target test code; and If the performance test result of the target test code is that the test fails, then the target test code will be optimized.

2. The method according to claim 1, characterized in that, Shadow tables are created based on the naming and table structure of the n key tables, generating n first shadow tables, including: Preset naming rules for shadow tables; Based on the naming rules of the shadow tables, the names of the n key tables are mapped to generate the names of the n shadow tables, wherein the names of the n key tables and the names of the n shadow tables have a one-to-one mapping relationship. Based on the naming of the n shadow tables, generate n second shadow tables; and Based on the table structure of the n key tables, the table structure of the n second shadow tables is synchronized to generate n first shadow tables, wherein the table structure of the n first shadow tables is consistent with the table structure of the n key tables.

3. The method according to claim 1, characterized in that, Based on the data in the n key tables, the n first shadow tables are synchronized to generate n target shadow tables, including: Sensitive data replacement is performed on the data in the n key tables to generate n key tables after data replacement; Sensitive data masking is performed on the data in the n key tables after the data replacement, generating n key tables after data masking; Sensitive data generalization is performed on the data in the n key tables after data masking to generate n key tables after data generalization; Sensitive data encryption is applied to the data in the n key tables after data generalization, generating n key tables with encrypted data; and The data in the n key tables after data encryption is synchronized to the n first shadow tables to generate n target shadow tables.

4. The method according to claim 1, characterized in that, Based on the n target shadow tables, performance testing is performed on the target test code to generate performance test results for the target test code, including: Obtain the Structured Query Language (SCL) operation statement in the target test code, and replace the names of the m key tables called in the SCL operation statement in the target test code with the names of the target shadow tables, so that the SCL operation statement in the target test code calls the m target shadow tables to access the database, where m is an integer, m is greater than 0 and m is less than n; Determine the performance metrics for the structured query language operations in the target test code that call m target shadow tables for database access; and Based on the performance metrics, the performance test results of the target test code are generated.

5. The method according to claim 4, characterized in that, The performance metrics include: response time, resource consumption, and database-specific metrics. Based on these performance metrics, performance test results for the target test code are generated, including: Preset performance indicator thresholds; The performance metric is generated by weighting the response time, resource consumption, and database-specific metrics; and If the performance metric is greater than the performance metric threshold, then the performance test result of the target test code is determined to be a failed test.

6. The method according to claim 1, characterized in that, Data optimization is performed on the target test code, including: The target test code is subjected to code lightweighting to generate lightweight target test code; The target test code for the lightweight code is index-optimized to generate index-optimized target test code; and The target test code for index optimization is refactored to generate target test code for business logic refactoring.

7. The method according to any one of claims 1 to 6, characterized in that, The method also includes: The performance test results of the target test code can be sent via development tool extensions, email, or instant messaging.

8. A code testing device, characterized in that, The device includes: The first generation module is used to obtain the names and table structures of n key tables from the production database, and to create shadow tables based on the names and table structures of the n key tables, generating n first shadow tables, where n is an integer and n is greater than 0; The second generation module is used to obtain data from the n key tables, synchronize the data of the n first shadow tables based on the data in the n key tables, and generate n target shadow tables. The third generation module is used to obtain the target test code, perform performance testing on the target test code based on the n target shadow tables, and generate the performance test results of the target test code; and The first optimization module is used to optimize the target test code by performing data optimization if the performance test result of the target test code is that the test fails.

9. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 7.

11. 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 7.