Automatic construction method, device, equipment and storage medium for data insertion script
By obtaining the data item name to generate a value script, calling the test data table and replacing the data value, the problem of poor automaticity of the data insertion script is solved, and the efficiency of test data insertion is improved.
Patent Information
- Application Number
- CN202111149034.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-29
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2041-09-29
AI Technical Summary
In the prior art, the data insertion script has poor automation and low efficiency, and the value of a field in the data script cannot be automatically changed, resulting in inefficient insertion of test data.
By obtaining the data insertion script construction request, extracting the data item name, generating a value script based on the preset value script generation rules, calling the test data table to extract data, performing data value replacement and splicing, and constructing a data insertion script.
Improves the automation of data insertion and improves the efficiency of test data insertion.
Smart Images

Figure CN113886233B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of research and development management, and in particular to a method, device, equipment and storage medium for automatically constructing a data insertion script. Background Art
[0002] With the development of computer technology, various applications and web page functions have become increasingly complex, and testing work has become increasingly important. During the development process, it is necessary to build a large amount of test data and insert it into the application to be tested for testing to avoid errors during operation.
[0003] In existing technologies, the method of automatically building test data and conducting tests is generally adopted. To generate data scripts, the only way is to export the data scripts through the Oracle client. This export requires manual operation and cannot automatically change the value of a certain field in the data script, resulting in poor automation and low efficiency of data insertion. Summary of the Invention
[0004] The main purpose of the present invention is to solve the technical problems of poor automation and low efficiency in data insertion during testing in the prior art.
[0005] A first aspect of the present invention provides a method for automatically constructing a data insertion script, comprising: obtaining a data insertion script construction request, extracting the name of a data item that needs to be script constructed in the data insertion script construction request; constructing a script according to the data item name to obtain a construction script fragment; generating a value-taking script based on the data item name according to a preset value-taking script generation rule; calling the value-taking script to extract test data from a preset test data table, and generating a first text sequence based on the extracted test data; replacing the data value that needs to be modified in the first text sequence to obtain a second text sequence; and splicing the construction script fragment and the second text sequence to obtain a data insertion script.
[0006] Optionally, in a first implementation method of the first aspect of the present invention, generating a value script based on the data item name according to preset value script generation rules includes: judging whether the data item needs to be modified according to the data item name; if so, universally encapsulating the data item name according to preset encapsulation rules to obtain an encapsulation field; adding a marker character after the encapsulation field to obtain a value script field template; and constructing a value script based on the value script field template.
[0007] Optionally, in a second implementation method of the first aspect of the present invention, constructing a value-taking script based on the value-taking script field template includes: obtaining a preset value-taking script prefix, a value-taking script suffix template and a preset test data table name; generating a script suffix according to the test data table name and the script suffix template; and splicing the script prefix, the value-taking script field template and the script suffix to obtain a value-taking script.
[0008] Optionally, in a third implementation method of the first aspect of the present invention, replacing the data value that needs to be modified in the first text sequence to obtain the second text sequence includes: finding the encapsulated field that needs to be modified in the first text sequence according to the marker character; extracting the preset target modification value of the encapsulated field; replacing the field value in the encapsulated field that needs to be modified according to the target modification value to obtain a modified encapsulated field; replacing the marker character of the modified encapsulated field with empty to obtain the second text sequence.
[0009] Optionally, in a fourth implementation method of the first aspect of the present invention, after replacing the marker character of the modified encapsulation field with empty space to obtain the second text sequence, it also includes: obtaining the character type of each encapsulation field, and determining the target format of the character according to the character type; obtaining a format conversion instruction according to the target format, and replacing the corresponding second text sequence based on the format conversion instruction to obtain a text sequence with an updated format.
[0010] Optionally, in the fifth implementation of the first aspect of the present invention, the automatic construction method of the data insertion script also includes: in response to the received data test processing request, deleting the existing test item data in the system to be tested through the test item corresponding to the data test processing request; extracting the preset data insertion script, and inserting the stored data into the system to be tested according to the data insertion script; running the execution interface, executing the item to be tested, and obtaining the execution result; performing data checking on the execution result to generate a test result.
[0011] The second aspect of the present invention provides an automatic construction device for data insertion scripts, including: an acquisition module for acquiring a data insertion script construction request and extracting the name of the data item that needs to be script constructed in the data insertion script construction request; a script fragment construction module for constructing a script according to the data item name to obtain a construction script fragment; a value script generation module for generating a value script based on the data item name according to a preset value script generation rule; a data extraction module for calling the value script to extract test data from a preset test data table, and generating a first text sequence according to the extracted test data; a replacement module for replacing the data value that needs to be modified in the first text sequence to obtain a second text sequence; and a splicing module for splicing the construction script fragment and the second text sequence to obtain a data insertion script.
[0012] Optionally, in a first implementation method of the second aspect of the present invention, the value-taking script generation module includes: a judgment unit, used to judge whether the data item needs to be modified based on the data item name; an encapsulation unit, used to, if so, universally encapsulate the data item name according to preset encapsulation rules to obtain an encapsulation field; a marking unit, used to add a marking character after the encapsulation field to obtain a value-taking script field template; and a construction unit, used to construct a value-taking script based on the value-taking script field template.
[0013] Optionally, in a second implementation of the second aspect of the present invention, the construction unit is specifically used to: obtain a preset value-taking script prefix, a value-taking script suffix template and a preset test data table name; generate a script suffix based on the test data table name and the script suffix template; and splice the script prefix, the value-taking script field template and the script suffix to obtain a value-taking script.
[0014] Optionally, in a third implementation of the second aspect of the present invention, the replacement module includes: a search unit, used to find the encapsulated field that needs to be modified in the first text sequence according to the mark character; an extraction unit, used to extract the preset target modification value of the encapsulated field; a modification unit, used to replace the field value in the encapsulated field that needs to be modified according to the target modification value to obtain a modified encapsulated field; a replacement unit, used to replace the mark character of the modified encapsulated field with empty to obtain a second text sequence.
[0015] Optionally, in a fourth implementation of the second aspect of the present invention, the automatic construction device of the data insertion script also includes a format conversion module, and the format conversion module includes: a target format determination unit, used to obtain the character type of each encapsulation field, and determine the target format of the character according to the character type; a format change unit, used to obtain a format conversion instruction according to the target format, and replace the corresponding second text sequence based on the format conversion instruction to obtain a text sequence with an updated format.
[0016] Optionally, in a fifth implementation of the second aspect of the present invention, the automatic construction device of the data insertion script also includes a data test execution module, and the data test execution module is specifically used to: respond to a received data test processing request, delete the existing test item data in the system to be tested through the test item corresponding to the data test processing request; extract a preset data insertion script, and insert stored data into the system to be tested according to the data insertion script; run the execution interface, execute the item to be tested, and obtain an execution result; perform data checking on the execution result to generate a test result.
[0017] The third aspect of the present invention provides an automatic construction device for data insertion scripts, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the automatic construction device for data insertion scripts executes the steps of the above-mentioned automatic construction method for data insertion scripts.
[0018] A fourth aspect of the present invention provides a computer-readable storage medium having instructions stored therein, which, when executed on a computer, causes the computer to execute the steps of the above-mentioned method for automatically constructing a data insertion script.
[0019] The technical solution provided by the present invention comprises obtaining a data insertion script construction request, extracting the name of the data item for which script construction is required, constructing a script based on the data item name, and obtaining a construction script fragment; generating a value-taking script based on the data item name according to a value-taking script generation rule; calling the value-taking script to extract test data from a preset test data table and generate a first text sequence; replacing the data values that need to be modified in the first text sequence to obtain a second text sequence; and concatenating the construction script fragment and the second text sequence to obtain a data insertion script. In this embodiment of the present invention, the automation of data insertion during testing is improved, thereby increasing the efficiency of data insertion. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 This is a schematic diagram of a first embodiment of a method for automatically constructing a data insertion script according to an embodiment of the present invention;
[0021] Figure 2 Schematic diagram of a second embodiment of a method for automatically constructing a data insertion script according to an embodiment of the present invention;
[0022] Figure 3 Schematic diagram of a third embodiment of a method for automatically constructing a data insertion script according to an embodiment of the present invention;
[0023] Figure 4 A schematic diagram of an embodiment of an automatic construction device for data insertion scripts according to an embodiment of the present invention;
[0024] Figure 5 A schematic diagram of another embodiment of an automatic construction device for data insertion scripts according to an embodiment of the present invention;
[0025] Figure 6 This is a schematic diagram of an embodiment of an automatic construction device for data insertion scripts in an embodiment of the present invention. DETAILED DESCRIPTION
[0026] An embodiment of the present invention provides a method, apparatus, device, and storage medium for automatically constructing a data insertion script. In the technical solution provided by the present invention, a data insertion script construction request is obtained, and the name of the data item for which the script construction is required is extracted; the script is constructed according to the data item name to obtain a construction script fragment; a value-taking script is generated based on the data item name according to a value-taking script generation rule; the value-taking script is called to extract test data from a preset test data table and generate a first text sequence; the data values that need to be modified in the first text sequence are replaced to obtain a second text sequence; and the construction script fragment and the second text sequence are spliced to obtain a data insertion script. In the embodiment of the present invention, the automation of data insertion during testing is improved, and the efficiency of data insertion is increased.
[0027] The terms "first," "second," "third," "fourth," and the like (if any) in the description and claims of the present invention and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or apparatus.
[0028] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1An embodiment of a method for automatically constructing a data insertion script according to an embodiment of the present invention includes:
[0029] 101. Obtain a data insertion script construction request, and extract the name of the data item that needs to be script constructed in the data insertion script construction request;
[0030] It is understandable that the execution subject of the present invention can be an automatic construction device for inserting data into a script, or a terminal or a server, and the specific details are not limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example; wherein the server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0031] During the development of software or applications, a large amount of testing is required. Since the data that needs to be tested is of various types and formats, a large amount of test data needs to be constructed for each different project for testing.
[0032] In this embodiment, when a user wants to perform a test and insert test data into the software or application under test, they can use the automatic data construction and insertion operations provided in this embodiment. First, they send a data insertion script automatic construction request to the server based on the specific data item name and other information of the data to be inserted. In response to the received construction request, the server extracts the data item name to be constructed.
[0033] The data item names may be derived from the data column names of the constructed data table included in the data construction request, and the data item names correspond to the data column names in a one-to-one correspondence.
[0034] 102. Construct a script according to the data item name to obtain a construction script fragment;
[0035] After obtaining the data item name, the script is constructed based on the data item name according to the pre-set script construction rules. Specifically, the script to be constructed in this embodiment is a test data insertion script, and the pre-set script construction rules are a specific method of generating the beginning of the insertion script field according to the data item name.
[0036] To illustrate with a specific example, the insert script in this embodiment may begin with an insert into ... values statement, where the insert into statement is used in SQL (Structured Query Language) to insert new records into a table. In this step, field1, field2, and field3 represent data names, and the constructed script fragment may be: insert into tab1 (field1, field2, field3) values.
[0037] Among them, SQL (Structured Query Language) is a special-purpose programming language and a database query and programming language used to access data and query, update and manage relational database systems.
[0038] 103. Generate a value script based on the data item name according to a preset value script generation rule;
[0039] After obtaining the data item name, a value extraction script is generated based on the data item name, wherein the data extraction script is specifically used to extract data from a preset test data table to obtain the test data to be used. In this embodiment, the corresponding test data can be found in the test data table based on the data item name.
[0040] First, the data item name is encapsulated according to general encapsulation rules in Oracle to obtain an encapsulated data template. The Oracle database is currently the most widely used database management system in the world. As a general database system, it has complete data management functions. After obtaining the encapsulated data template, a value script prefix and a value script suffix are added to the encapsulated data template according to pre-defined value script generation rules to obtain a value script.
[0041] Specifically, the value script prefix can use the select command as a prefix, and the value script suffix can be constructed by adding the preset extraction condition and the table name or table address of the test data table through the from command.
[0042] 104. Calling a value extraction script to extract test data from a preset test data table, and generating a first text sequence according to the extracted test data;
[0043] After the constructed value extraction script is obtained, the value extraction script is called to extract the test data in the preset test data table to obtain candidate test data, and the extracted candidate test data are combined into a first text sequence.
[0044] The value-taking script extracts test data according to the required data item name, wherein there may be multiple data items. The specific test data extracted from the preset test data table according to the aforementioned data items are combined to obtain multiple first text sequences.
[0045] 105. Replace the data value that needs to be modified in the first text sequence to obtain a second text sequence;
[0046] 106. Concatenate the constructed script fragment and the second text sequence to obtain a data insertion script.
[0047] After obtaining the first text sequence in this embodiment, regular expression replacement is performed on the data values that need to be modified according to the specific requirements of the generated test. For example, if the script construction request received in this embodiment contains a specific data item that needs to be modified, the data value that needs to be modified is found based on the name of the data item, and the data value that needs to be modified is replaced with the target data required for this data test according to a preset regular expression replacement instruction. Specifically, the regular expression replacement instruction can be a replace instruction.
[0048] Subsequently, the script fragment constructed in the above steps and the second text sequence are spliced to obtain a data insertion script.
[0049] In the embodiment of the present invention, the automation of data insertion during testing is improved, and the efficiency of data insertion is increased.
[0050] See also Figure 2 The second embodiment of the method for automatically constructing a data insertion script according to the embodiment of the present invention includes:
[0051] 201. Obtain a data insertion script construction request, and extract the name of the data item that needs to be script constructed in the data insertion script construction request;
[0052] First, a data insertion script automatic construction request is sent to the server based on the specific data item name and other information of the data to be inserted. In response to the received construction request, the server extracts the data item name that needs to be constructed.
[0053] 202. Construct a script according to the data item name to obtain a construction script fragment;
[0054] In this embodiment, the script to be constructed is a test data insertion script. The pre-set script construction rule is a specific method of generating the beginning of the insertion script field according to the data item name. After obtaining the data item name, the script is constructed based on the data item name according to the pre-set script construction rule.
[0055] 203. Determine whether the data item needs to be modified based on the data item name;
[0056] In this embodiment, when a data insertion script construction request is received, the specific test business point in the insertion script construction request can be extracted, the data item that needs to be modified is determined based on the specific test business point, and the project name of the data item that needs to be modified is obtained.
[0057] In this step, it is determined whether the data item belongs to the aforementioned data item that needs to be modified based on the obtained data item name. If the data item does not belong to the aforementioned data item that needs to be modified, the data item name is universally encapsulated according to the preset encapsulation rules to obtain the encapsulation field, and converted into a value script based on the second encapsulation field name.
[0058] Specifically, the general encapsulation refers to the general data encapsulation operation in Oracle, which uses quotation marks and Oracle connectors to concatenate before the field name, and quote marks, commas, and Oracle connectors to concatenate after the field name.
[0059] 204. If yes, then universally encapsulate the data item name according to a preset encapsulation rule to obtain an encapsulation field;
[0060] 205. Add a marker character after the encapsulated field to obtain a value script field template;
[0061] 206. Construct a value script based on the value script field template;
[0062] If the data item requires modification, the data item name is generically encapsulated according to pre-set encapsulation rules to obtain an encapsulated field. This generic encapsulation is similar to the aforementioned method, using Oracle's generic data encapsulation operations. A marker character is then added after the encapsulated field to obtain a value script field template. The marker character in this step can be a pre-specified special character, such as "@" or "#."
[0063] In a specific example, when the data item name is field1, field2 or field3, the obtained encapsulated field can be: ""||field1||"','||""||field2||"','||""||to_char(field3,'yyyy-mm-dd')||"", when the data item needs to be modified, mark characters are added to the encapsulated field, and the value script field template after adding the mark characters can be: ""||field1||"','||""||field2||"'@! ,'||""||to_char(field3,'yyyy-mm-dd')||""@#.
[0064] 207. Calling a value extraction script to extract test data from a preset test data table, and generating a first text sequence according to the extracted test data;
[0065] After the constructed value extraction script is obtained, the value extraction script is called to extract the test data in the preset test data table to obtain candidate test data, and the extracted candidate test data are combined into a first text sequence.
[0066] 208. Find the encapsulation field that needs to be modified in the first text sequence according to the mark character;
[0067] 209. Extracting the preset target modification value of the encapsulated field;
[0068] 210. Replace the field value in the encapsulated field that needs to be modified according to the target modification value to obtain a modified encapsulated field;
[0069] 211. Replace the marker character of the modified encapsulation field with a blank to obtain a second text sequence;
[0070] After obtaining the first text sequence, firstly, it is checked whether the first text sequence contains any marked characters.
[0071] If a text sequence contains a marker character, it is considered that the first text sequence contains an encapsulated field that needs to be modified. If the first text sequence contains an encapsulated field that needs to be modified, the encapsulated field that needs to be modified is determined based on the collective position of the marker character. Based on the service point to be tested obtained in the above steps, a preset target modification value of the encapsulated field is extracted; and the field value in the encapsulated field that needs to be modified is replaced based on the target modification value.
[0072] To illustrate, let's take a specific example. If we need to change field2_value to field2_value_new in the aforementioned 'field1_value', 'field2_value'@!, '2020-12-25'@#, we can use regular replacement to change the field value to the desired value and replace the marker characters with empty spaces. For example, if we replace 'field2_value'@! with 'field2_value_new', we get the second text sequence 'field1_value', 'field2_value_new', '2020-12-25'.
[0073] 212. Concatenate the constructed script fragment and the second text sequence to obtain a data insertion script.
[0074] According to the specific requirements of the generated test, regular replacement is performed on the data value that needs to be modified. Specifically, the regular replacement instruction can be a replace instruction; the data value that needs to be modified is found according to the data item name, and the data value that needs to be modified is replaced with the target data required for this data test according to the preset regular replacement instruction. The script fragment constructed in the above steps and the second text sequence are spliced to obtain a data insertion script.
[0075] In the embodiment of the present invention, the automation of data insertion during testing is improved, and the efficiency of data insertion is increased.
[0076] See also Figure 3 A third embodiment of the method for automatically constructing a data insertion script according to an embodiment of the present invention includes:
[0077] 301. Obtain a data insertion script construction request, and extract the name of the data item that needs to be script constructed in the data insertion script construction request;
[0078] 302. Construct a script according to the data item name to obtain a construction script fragment;
[0079] Step 301 and step 302 in this embodiment are substantially the same as step 101 and step 102 in the aforementioned embodiment, and therefore are not described again here.
[0080] 303. Determine whether the data item needs to be modified based on the data item name;
[0081] 304. If yes, then universally encapsulate the data item name according to a preset encapsulation rule to obtain an encapsulation field;
[0082] Step 303 and step 304 in this embodiment are substantially the same as step 203 and step 204 in the aforementioned embodiment, and therefore are not described again here.
[0083] 305. Add a marker character after the encapsulated field to obtain a value script field template;
[0084] If the data item requires modification, the data item name is generically encapsulated according to pre-set encapsulation rules to obtain an encapsulated field. This generic encapsulation is similar to the aforementioned method, using Oracle's generic data encapsulation operations. A marker character is then added after the encapsulated field to obtain a value script field template. The marker character in this step can be a pre-specified special character, such as "@" or "#."
[0085] 306. Obtain a preset value script prefix, a value script suffix template, and a preset test data table name;
[0086] 307. Generate a script suffix according to the test data table name and the script suffix template;
[0087] 308. Concatenate the script prefix, the value script field template, and the script suffix to obtain a value script;
[0088] In this embodiment, the value-taking script prefix can be a select instruction, and the value-taking script suffix template can be a from instruction. The test data table name and data acquisition conditions are obtained, and the from instruction, the test data table name and the data acquisition conditions are combined to obtain the script suffix. The script prefix, the second encapsulated field name and the script suffix are spliced to obtain the value-taking script.
[0089] After obtaining the value script, call the execute immediate instruction to retrieve the data value in the test data table. In a specific example, the retrieved text may be similar to: 'field1_value', 'field2_value'@!, '2020-12-25'@#.
[0090] The execute immediate instruction is used to dynamically execute SQL statements and stored procedures. SQL refers to Structured Query Language (Structured Query Language), which is a special-purpose programming language and a database query and programming language used to access data and query, update, and manage relational database systems.
[0091] 309. Calling a value extraction script to extract test data from a preset test data table, and generating a first text sequence according to the extracted test data;
[0092] Step 207 in this embodiment is substantially the same as step 104 in the aforementioned embodiment, and therefore will not be described again here.
[0093] 310. Find the encapsulation field that needs to be modified in the first text sequence according to the mark character;
[0094] 311. Extract the preset target modification value of the encapsulated field;
[0095] 312. Replace the field value in the encapsulated field that needs to be modified according to the target modification value to obtain a modified encapsulated field;
[0096] Steps 310 to 312 in this embodiment are substantially the same as steps 208 to 210 in the aforementioned embodiment, and therefore are not described again here.
[0097] 313. Replace the marker character of the modified encapsulation field with a blank to obtain a second text sequence;
[0098] After obtaining the first text sequence, the first text sequence is checked to see if it contains any marker characters. If so, it is considered that the first text sequence contains an encapsulated field that needs to be modified. If so, the encapsulated field that needs to be modified is determined based on the collective position of the marker characters. Based on the service points to be tested obtained in the previous step, the preset target modification value of the encapsulated field is extracted; and the field value in the encapsulated field that needs to be modified is replaced based on the target modification value.
[0099] To illustrate with a specific example, if we need to change field2_value to field2_value_new in the aforementioned 'field1_value', 'field2_value'@!, '2020-12-25'@#, the specific operation is to use regular replacement to change the field value to be modified to the required value and replace the marker character with space.
[0100] After obtaining the second text sequence, the character type of each encapsulation field is obtained, and the target format of the character is determined according to the character type; a format conversion instruction is obtained according to the target format, and the corresponding second text sequence is replaced based on the format conversion instruction to obtain a text sequence with an updated format.
[0101] Specifically, the value retrieved from the date format field is the character type converted previously, and needs to be replaced with the date format in a regular expression so that the generated script can run correctly, such as replacing '2020-12-25' with: to_date('2020-12-25','yyyy-mm-dd').
[0102] 314. Concatenate the constructed script fragment and the second text sequence in the updated format to obtain a data insertion script.
[0103] The script fragment constructed in the above steps is concatenated with the second text sequence after the updated format to obtain a data insertion script. After obtaining the data insertion script, in response to a received data test processing request, the existing test item data in the system under test is deleted through the test item corresponding to the data test processing request; a preset data insertion script is extracted and the stored data is inserted into the system under test according to the data insertion script; an execution interface is run to execute the test item to obtain an execution result; and a data check is performed on the execution result to generate a test result.
[0104] In the embodiment of the present invention, the automation of data insertion during testing is improved, and the efficiency of data insertion is increased.
[0105] The above describes the automatic construction method of the data insertion script in the embodiment of the present invention. The following describes the automatic construction device of the data insertion script in the embodiment of the present invention. Figure 4 In one embodiment of the present invention, an automatic construction device for a data insertion script includes:
[0106] An acquisition module 401 is configured to acquire a data insertion script construction request and extract the name of a data item that needs to be scripted in the data insertion script construction request;
[0107] A script fragment construction module 402 is used to construct a script according to the data item name to obtain a constructed script fragment;
[0108] A value script generation module 403 is configured to generate a value script based on the data item name according to a preset value script generation rule;
[0109] The data extraction module 404 is configured to call the value extraction script to extract test data from a preset test data table, and generate a first text sequence based on the extracted test data;
[0110] A replacement module 405 is configured to replace the data value that needs to be modified in the first text sequence to obtain a second text sequence;
[0111] The splicing module 406 is used to splice the constructed script fragment and the second text sequence to obtain a data insertion script.
[0112] In the embodiment of the present invention, the automation of data insertion during testing is improved, and the efficiency of data insertion is increased.
[0113] See also Figure 5Another embodiment of the automatic construction device for data insertion script in the embodiment of the present invention includes:
[0114] An acquisition module 401 is configured to acquire a data insertion script construction request and extract the name of a data item that needs to be scripted in the data insertion script construction request;
[0115] A script fragment construction module 402 is used to construct a script according to the data item name to obtain a constructed script fragment;
[0116] A value script generation module 403 is configured to generate a value script based on the data item name according to a preset value script generation rule;
[0117] The data extraction module 404 is configured to call the value extraction script to extract test data from a preset test data table, and generate a first text sequence based on the extracted test data;
[0118] A replacement module 405 is configured to replace the data value that needs to be modified in the first text sequence to obtain a second text sequence;
[0119] The splicing module 406 is used to splice the constructed script fragment and the second text sequence to obtain a data insertion script.
[0120] In another embodiment of the present application, the value script generation module 403 includes:
[0121] A judging unit 4031 is configured to judge whether the data item needs to be modified according to the data item name;
[0122] The encapsulation unit 4032 is configured to, if yes, perform universal encapsulation on the data item name according to a preset encapsulation rule to obtain an encapsulation field;
[0123] A marking unit 4033 is used to add a marking character after the encapsulation field to obtain a value script field template;
[0124] The construction unit 4034 is configured to construct a value-taking script based on the value-taking script field template.
[0125] In another embodiment of the present application, the construction unit 4034 is specifically configured to:
[0126] Get the preset value script prefix, value script suffix template and preset test data table name;
[0127] Generate a script suffix according to the test data table name and the script suffix template;
[0128] The script prefix, the value script field template and the script suffix are concatenated to obtain a value script.
[0129] In another embodiment of the present application, the replacement module 405 includes:
[0130] A searching unit 4051 is configured to search for an encapsulation field that needs to be modified in the first text sequence according to the marking character;
[0131] An extraction unit 4052 is configured to extract a preset target modification value of the encapsulation field;
[0132] The modifying unit 4053 is configured to replace the field value in the encapsulated field to be modified according to the target modification value to obtain a modified encapsulated field;
[0133] The replacing unit 4054 is configured to replace the marker character of the modified encapsulation field with a space to obtain a second text sequence.
[0134] In another embodiment of the present application, the automatic construction device for the data insertion script further includes a format conversion module, and the format conversion module includes:
[0135] a target format determination unit, configured to obtain a character type of each encapsulation field and determine a target format of the character according to the character type;
[0136] The format changing unit is configured to obtain a format conversion instruction according to the target format, and replace the corresponding second text sequence based on the format conversion instruction to obtain a text sequence with an updated format.
[0137] In another embodiment of the present application, the automatic construction device for data insertion script further includes a data test execution module, and the data test execution module is specifically configured to:
[0138] In response to the received data test processing request, deleting existing test item data in the system to be tested through the test item corresponding to the data test processing request;
[0139] Extracting a preset data insertion script, and inserting stored data into the system under test according to the data insertion script;
[0140] Run the execution interface, execute the project to be tested, and obtain the execution result;
[0141] Perform data check on the execution result to generate a test result.
[0142] In the embodiment of the present invention, the automation of data insertion during testing is improved, and the efficiency of data insertion is increased.
[0143] above Figure 4 and Figure 5 The automatic construction device for data insertion scripts in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The automatic construction device for data insertion scripts in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0144] Figure 6 : This is a schematic diagram of the structure of an automatic construction device for data insertion scripts provided by an embodiment of the present invention. The automatic construction device 600 for data insertion scripts may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 610 (for example, one or more processors) and a memory 620, and one or more storage media 630 (for example, one or more mass storage devices) for storing application programs 633 or data 632. Among them, the memory 620 and the storage medium 630 can be temporary storage or permanent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the automatic construction device 600 for data insertion scripts. Furthermore, the processor 610 can be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the automatic construction device 600 for data insertion scripts.
[0145] The automatic construction device 600 for inserting data into a script may further include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input and output interfaces 660, and / or one or more operating systems 631, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It will be understood by those skilled in the art that Figure 6 The structure of the automatic data insertion script construction device shown does not limit the automatic data insertion script construction device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0146] The server described in the embodiment of the present invention can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0147] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0148] The present invention also provides a computer device, which can be any device capable of executing the automatic construction method of data insertion scripts described in the above embodiments. The computer device includes a memory and a processor, and the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor executes the steps of the automatic construction method of data insertion scripts in the above embodiments.
[0149] Blockchain, as used in this article, refers to a novel application model for computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Blockchain is essentially a decentralized database, a series of data blocks generated using cryptographic methods. Each block contains information about a batch of online transactions, used to verify the validity of this information (to prevent counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.
[0150] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores instructions, which, when executed on a computer, cause the computer to execute the steps of the automatic construction method of the data insertion script.
[0151] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0152] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc., various media that can store program code.
[0153] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that the technical solutions described in the above embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for automatically constructing a data insertion script, characterized in that: The automatic construction method of the data insertion script includes: Obtain a data insertion script construction request, and extract the name of the data item that needs to be script constructed in the data insertion script construction request; Perform script construction according to the data item name to obtain a construction script fragment; Generate a value script based on the data item name according to a preset value script generation rule; Calling the execute immediate instruction to execute the value-taking script, extracting test data from a preset test data table, and generating a first text sequence according to the extracted test data; Replacing the data values that need to be modified in the first text sequence to obtain a second text sequence; splicing the construction script fragment and the second text sequence to obtain a data insertion script; Generating a value script based on the data item name according to a preset value script generation rule includes: Determining whether the data item needs to be modified according to the name of the data item; If so, the data item name is universally encapsulated according to a preset encapsulation rule to obtain an encapsulation field; Add a marker character after the encapsulation field to obtain a value script field template; Constructing a value script based on the value script field template; The replacing the data value that needs to be modified in the first text sequence to obtain the second text sequence includes: Finding the encapsulation field that needs to be modified in the first text sequence according to the mark character; Extracting a preset target modification value of the encapsulated field; According to the target modification value, the field value in the encapsulated field to be modified is replaced by a regular replacement instruction to obtain a modified encapsulated field; The mark character of the modified encapsulation field is replaced with space to obtain a second text sequence.
2. The automatic construction method of data insertion script according to claim 1, characterized in that: The constructing of the value script based on the value script field template includes: Get the preset value script prefix, value script suffix template and preset test data table name; Generate a script suffix according to the test data table name and the script suffix template; The script prefix, the value script field template and the script suffix are concatenated to obtain a value script.
3. The automatic construction method of data insertion script according to claim 1, characterized in that: After replacing the marker character of the modified encapsulation field with a space to obtain the second text sequence, the method further includes: Obtaining the character type of each encapsulated field, and determining the target format of the character according to the character type; A format conversion instruction is obtained according to the target format, and the corresponding second text sequence is replaced based on the format conversion instruction to obtain a text sequence with an updated format.
4. The method for automatically constructing a data insertion script according to any one of claims 1 to 3, characterized in that: The automatic construction method of the data insertion script also includes: In response to the received data test processing request, deleting existing test item data in the system to be tested through the test item corresponding to the data test processing request; Extracting a preset data insertion script, and inserting stored data into the system under test according to the data insertion script; Run the execution interface, execute the project to be tested, and obtain the execution result; Perform data check on the execution result to generate a test result.
5. An automatic construction device for data insertion script, characterized in that: The automatic construction device of the data insertion script includes: An acquisition module is used to acquire a data insertion script construction request and extract the name of a data item that needs to be script constructed in the data insertion script construction request; A script fragment construction module is used to construct a script according to the data item name to obtain a construction script fragment; A value script generation module, configured to generate a value script based on the data item name according to preset value script generation rules; a data extraction module, configured to call an execute immediate instruction to execute the value extraction script to extract test data from a preset test data table, and generate a first text sequence according to the extracted test data; a replacement module, configured to replace data values that need to be modified in the first text sequence to obtain a second text sequence; a splicing module, configured to splice the construction script fragment and the second text sequence to obtain a data insertion script; The value script generation module includes: a judging unit, configured to judge whether the data item needs to be modified according to the name of the data item; an encapsulation unit, configured to, if yes, perform universal encapsulation on the data item name according to a preset encapsulation rule to obtain an encapsulation field; a marking unit, configured to add a marking character after the encapsulated field to obtain a value script field template; A construction unit, configured to construct a value script based on the value script field template; The replacement module includes: a search unit, used to find the encapsulated field that needs to be modified in the first text sequence based on the mark character; an extraction unit, used to extract a preset target modification value of the encapsulated field; a modification unit, used to replace the field value in the encapsulated field that needs to be modified using a regular replacement instruction according to the target modification value to obtain a modified encapsulated field; and a replacement unit, used to replace the mark character of the modified encapsulated field with empty space to obtain a second text sequence.
6. The automatic construction device for data insertion script according to claim 5, characterized in that: The construction unit is specifically used to: obtain a preset value script prefix, a value script suffix template and a preset test data table name; Generate a script suffix according to the test data table name and the script suffix template; The script prefix, the value script field template and the script suffix are concatenated to obtain a value script.
7. The automatic construction device for data insertion script according to claim 5, characterized in that: The automatic construction device of the data insertion script also includes a format conversion module, which includes: a target format determination unit, which is used to obtain the character type of each encapsulation field and determine the target format of the character according to the character type; a format change unit, which is used to obtain a format conversion instruction according to the target format and replace the corresponding second text sequence based on the format conversion instruction to obtain a text sequence with an updated format.
8. The automatic construction device for data insertion script according to any one of claims 5 to 7, characterized in that: The automatic construction device for data insertion scripts further includes a data test execution module, the data test execution module being specifically configured to: in response to a received data test processing request, delete existing test item data in the system under test through the test item corresponding to the data test processing request; extract a preset data insertion script, and insert stored data into the system under test according to the data insertion script; Run the execution interface, execute the project to be tested, and obtain the execution result; Perform data check on the execution result to generate a test result.
9. An automatic construction device for data insertion script, characterized in that: The automatic construction device for data insertion script includes: a memory and at least one processor, wherein the memory stores instructions; The at least one processor calls the instructions in the memory to enable the automatic construction device of the data insertion script to perform the steps of the automatic construction method of the data insertion script according to any one of claims 1 to 4.
10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by a processor, the steps of the method for automatically constructing a data insertion script as described in any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Intelligent test method and device, equipment and storage medium
CN112035357A
Method and device for generating database insertion statement and performing system testing
CN112286783A