Data testing method and apparatus
By using automated data testing methods, test cases are processed together with the original data, solving the challenges of complex SQL testing, reducing testing difficulty and cost, and protecting data integrity.
Patent Information
- Application Number
- CN202110189341.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-19
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2041-02-19
AI Technical Summary
In existing technologies, complex SQL tests used in industry are difficult to understand, especially for non-professionals, posing a risk of misoperation, resulting in long testing cycles, increased costs, and the vulnerability of raw data to contamination.
By automatically inserting test cases into the original data, executing the same data processing logic, obtaining the total execution result, and separating the actual execution result of the test cases from the result, and comparing it with the expected result, automated testing is achieved.
It lowers the requirements for testers' business proficiency and professionalism, reduces testing time and manpower costs, avoids data pollution, and protects the original data.
Smart Images

Figure CN113760737B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a data testing method and device. BACKGROUND
[0002] HIVE is the most core technology of big data, which is a data warehouse tool built on Hadoop (Hadoop is a distributed system infrastructure), can map structured data in HDFS (Hadoop Distributed File System) into tables, and perform statistical analysis through MapReduce process (MapReduce is a computing model frequently used in offline big data processing). In industry, HIVE QL (HIVE Query Language) is often used in combination with multiple table queries, such as extracting part of data from two tables and then associating the data.
[0003] However, in the process of implementing the present application, the inventors found that at least the following problems exist in the prior art: the complex SQL used in industry is not easy to understand even for professional researchers, and it is even more difficult for testers with relatively weak professional ability; the confidence is low, there is a risk of misoperation in the execution process, which pollutes and destroys the original data; the test period is long, which slows down the development progress and increases the cost. SUMMARY
[0004] Therefore, the embodiments of the present application provide a data testing method and device, which reduces the requirements for the business proficiency and professionalism of testers, so that non-professional testers can also complete the corresponding work of big data testing, and reduces the time cost and labor cost of big data testing; the data testing method of the embodiments of the present application can automatically mix and separate the original data and the test data, without the need for manual insertion and deletion of test cases into the original data, thereby avoiding the problem of data pollution caused by human error, and protecting the original data to the greatest extent.
[0005] To achieve the above object, according to an aspect of the embodiments of the present application, a data testing method is provided, comprising:
[0006] obtaining original data, a structured query statement to be tested, a test case and an expected result corresponding to the test case;
[0007] inserting the test case into the original data to obtain intermediate data;
[0008] execute the structured query statement to be tested based on the intermediate data, and obtain a total execution result;
[0009] screen the actual execution result of the test case from the total execution result;
[0010] compare the expected result corresponding to the test case with the actual execution result of the test case, and obtain a test result.
[0011] Optionally, inserting the test case into the original data to obtain intermediate data comprises:
[0012] inserting the test case into the original data to obtain intermediate data, and adding a label field in the intermediate data to distinguish the test case in the intermediate data from the original data through the label field;
[0013] screening the actual execution result of the test case from the total execution result comprises:
[0014] screening the actual execution result of the test case from the total execution result based on the label field.
[0015] Optionally, executing the structured query statement to be tested based on the intermediate data, and obtaining a total execution result comprises:
[0016] inserting the test case into the original data to obtain intermediate data, and adding a label field in the intermediate data to distinguish the test case in the intermediate data from the original data through the label field;
[0017] parsing the structured query statement to be tested to obtain a first execution plan;
[0018] adding the label field in the first execution plan to obtain a second execution plan;
[0019] executing the structured query statement to be tested based on the intermediate data and the second execution plan, and obtaining a total execution result.
[0020] Optionally, inserting the test case into the original data to obtain intermediate data comprises:
[0021] determining whether the library table field used by the structured query statement to be tested and the library table field in the test case are the same;
[0022] if the same, inserting the test case into the original data to obtain intermediate data.
[0023] Optionally, determining whether the library table field used by the to-be-tested structured query statement and the library table field in the test case are same includes:
[0024] parsing the to-be-tested structured query statement to obtain a first database name, a first data table name and a first data field;
[0025] parsing the test case to obtain a second database name, a second data table name and a second data field;
[0026] respectively determining whether the first database name, the first data table name and the first data field are same as the second database name, the second data table name and the second data field.
[0027] Optionally, parsing the to-be-tested structured query statement to obtain a first database name, a first data table name and a first data field includes:
[0028] parsing the to-be-tested structured query statement to obtain a first database name and an abstract syntax tree;
[0029] translating the abstract syntax tree by using a preset translation model to obtain the first data table name and the first data field.
[0030] Optionally, comparing the expected result corresponding to the test case and the actual execution result of the test case to obtain a test result includes:
[0031] determining a keyword of the to-be-tested structured query statement;
[0032] determining a verification rule corresponding to the keyword;
[0033] according to the verification rule, comparing the expected result corresponding to the test case and the actual execution result of the test case to obtain a test result.
[0034] To achieve the above object, according to another aspect of the embodiment of the present application, a data testing device is provided, comprising:
[0035] an acquisition module, configured to acquire original data, a to-be-tested structured query statement, a test case and an expected result corresponding to the test case;
[0036] a mixing module, configured to insert the test case into the original data to obtain intermediate data;
[0037] an execution module, configured to execute the to-be-tested structured query statement based on the intermediate data to obtain a total execution result;
[0038] a screening module, configured to screen an actual execution result of the test case from the total execution result;
[0039] The comparison module is configured to compare the expected result corresponding to the test case with the actual execution result of the test case to obtain a test result.
[0040] Optionally, the mixing module is further configured to insert the test case into the original data to obtain intermediate data, and add a label field in the intermediate data to distinguish the test case in the intermediate data from the original data through the label field.
[0041] The screening module is further configured to screen the actual execution result of the test case from the total execution result based on the label field.
[0042] Optionally, the mixing module is further configured to insert the test case into the original data to obtain intermediate data, and add a label field in the intermediate data to distinguish the test case in the intermediate data from the original data through the label field; parse the structured query statement to be tested to obtain a first execution plan; add the label field in the first execution plan to obtain a second execution plan.
[0043] The execution module is further configured to execute the structured query statement to be tested based on the intermediate data and the second execution plan to obtain a total execution result.
[0044] Optionally, the mixing module is further configured to determine whether a library table field used by the structured query statement to be tested and a library table field in the test case are the same; if the same, insert the test case into the original data to obtain intermediate data.
[0045] Optionally, the mixing module is further configured to:
[0046] parse the structured query statement to be tested to obtain a first database name, a first data table name and a first data field;
[0047] parse the test case to obtain a second database name, a second data table name and a second data field;
[0048] determine whether the first database name, the first data table name and the first data field are the same as the second database name, the second data table name and the second data field, respectively.
[0049] Optionally, the mixing module is further configured to parse the structured query statement to be tested to obtain a first database name and an abstract syntax tree; and translate the abstract syntax tree by using a preset translation model to obtain a first data table name and a first data field.
[0050] Optionally, the comparing module is further configured to determine a keyword of the structured query statement to be tested, determine a verification rule corresponding to the keyword, and compare the expected result corresponding to the test case and the actual execution result of the test case according to the verification rule to obtain a test result.
[0051] To achieve the above object, according to another aspect of the embodiments of the present application, an electronic device is provided, which comprises one or more processors, and a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the data testing method of the embodiments of the present application.
[0052] To achieve the above object, according to still another aspect of the embodiments of the present application, a computer readable medium is provided, which stores a computer program, when the program is executed by a processor, the data testing method of the embodiments of the present application is implemented.
[0053] The embodiment of the above application has the following advantages or beneficial effects: the test case is automatically inserted into the original data, so that the test case and the original data enter the execution process together and experience the same data processing logic to obtain the total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the test case separated from the total execution result is compared with the expected result of the test case to obtain the test result. The technical means reduces the requirements for the business proficiency and professionalism of the tester, so that non-professional testers can also complete the corresponding work of big data testing, and reduces the time cost and labor cost of big data testing. The data testing method of the embodiments of the present application can automatically mix and separate the original data and the test data, without manually inserting and deleting the test case into the original data, which avoids the problem of data pollution caused by human error and maximally protects the original data. Since the method of the embodiments of the present application automatically inserts the test case into the original data and automatically separates the actual execution result of the test case from the total execution result, the method is suitable for the scene of big data testing, reduces the testing difficulty, and shortens the time required for single testing.
[0054] The further effects of the above-mentioned non-conventional optional mode will be described in the following combined with the specific embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0055] The accompanying drawings are used to better understand the present application, and do not constitute an improper limitation on the present application. Among them:
[0056] Figure 1 is a schematic diagram of the main process of the data testing method of the embodiments of the present application;
[0057] Figure 2This is a schematic diagram of the main flow of a data testing method according to another embodiment of the present invention;
[0058] Figure 3 This is a schematic diagram of the main flow of a data testing method according to another embodiment of the present invention;
[0059] Figure 4 This is a schematic diagram illustrating the parsing of the structured query statement to be tested in the data testing method of this invention.
[0060] Figure 5 This is a schematic diagram of the execution plan in the data testing method of this invention.
[0061] Figure 6 This is a schematic diagram of the main modules of the data testing device according to an embodiment of the present invention;
[0062] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0063] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0064] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0065] Figure 1 This is a schematic diagram of the main flow of the data testing method according to an embodiment of the present invention, as shown below. Figure 1 As shown, the method includes:
[0066] Step S101: Obtain the original data, the structured query statement to be tested, the test cases, and the expected results corresponding to the test cases;
[0067] Step S102: Insert the test cases into the original data to obtain intermediate data;
[0068] Step S103: Based on the intermediate data, execute the structured query statement to be tested to obtain the overall execution result;
[0069] Step S104: Filter out the actual execution results of the test cases from the total execution results;
[0070] Step S105: comparing the expected result corresponding to the test case with the actual execution result of the test case to obtain a test result.
[0071] For step S101, the test case and the expected result corresponding to the test case can be input in the form of a parameter file or directly input by a user. The format of the parameter file is not limited, which can be EXCEL, TXT, CSV or various formats. In the embodiment, the tester does not need to understand the specific content of the original data, and only needs to design the test case and the expected result of the test case according to the business requirement, thereby reducing the requirement for the business proficiency and professionalism of the tester.
[0072] For steps S102-S105, the test case is inserted into the original data, so that the test case and the original data enter the execution process together and experience the same data processing logic to obtain a total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the test case separated from the total execution result is compared with the expected result of the test case. If the comparison is consistent, the test passes, otherwise the test fails.
[0073] In an optional embodiment, if the test fails, the actual execution result and the part inconsistent between the actual execution result and the expected result can be output to prompt the user of the reason for the test failure.
[0074] The data test method of the embodiment of the application inserts the test case into the original data automatically, so that the test case and the original data enter the execution process together and experience the same data processing logic to obtain a total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the test case separated from the total execution result is compared with the expected result of the test case to obtain a test result, thereby reducing the requirement for the business proficiency and professionalism of the tester, enabling a non-professional tester to complete the corresponding work of the big data test, and reducing the time cost and labor cost of the big data test. The data test method of the embodiment of the application can automatically mix and separate the original data and the test data, and does not need to manually insert and delete the test case into the original data, thereby avoiding the problem of data pollution caused by human error and protecting the original data to the greatest extent.
[0075] In a big data test, due to the large amount of data, the difficulty of the test is much higher than that of a small amount of data, mainly reflected in the longer execution time (the execution time of a single query of big data is ten million times of that of a small amount of data), and the difficulty of data insertion and deletion operation. The method of the embodiment of the present application can automatically insert the test case into the original data before executing the structured query statement to be tested, so that the test case enters the execution process together with the original data and undergoes the same data processing logic, obtains the total execution result, then separates the actual execution structure of the test case from the total execution result, compares the actual execution structure with the expected result, and obtains the test result. Therefore, the method is suitable for the scene of big data test, effectively reduces the test difficulty and shortens the time required for a single test.
[0076] Figure 2 is the main flowchart of the data test method of another embodiment of the present application. In the method of this embodiment, the test case is mixed and separated with the original data through a label control method. Specifically, as shown in Figure 2 , the method comprises:
[0077] Step S201: obtaining original data, a structured query statement to be tested, a test case and an expected result corresponding to the test case;
[0078] Step S202: inserting the test case into the original data to obtain intermediate data, and adding a label field in the intermediate data to distinguish the test case and the original data in the intermediate data through the label field;
[0079] Step S203: executing the structured query statement to be tested based on the intermediate data to obtain a total execution result;
[0080] Step S204: screening the actual execution result of the test case from the total execution result based on the label field;
[0081] Step S205: comparing the expected result corresponding to the test case with the actual execution result of the test case to obtain a test result.
[0082] Steps S201, S203 and S205 are the same as those of the embodiment shown in Figure 1 , and will not be repeated here.
[0083] For step S202, the test case is merged with the original data, i.e., the test case is inserted into the original data to obtain intermediate data. After the insertion, the test case is labeled. The labeling manner can be that a label field is inserted in the intermediate data, and the values of the original data and the test case under the label field are different, so as to distinguish the test case and the original data in the intermediate data. As an example, the label field can be test_sign, the value of the original data under the label field is 0, and the value of the test case under the label field is 1.
[0084] For step S204, after the execution of the structured query statement to be tested is completed, the total execution result is obtained. In the total execution result, there are both the execution result of the original data and the actual execution result of the test case. The execution result of the original data and the actual execution result of the test case are separated through the label field, and the actual execution result of the test case is compared with the expected result to obtain the test result.
[0085] The data test method of the embodiment of the present application inserts the test case into the original data automatically, so that the test case and the original data enter the execution process together and experience the same data processing logic to obtain the total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the test case separated is compared with the expected result of the test case to obtain the test result. The technical means reduces the requirements for the business proficiency and professionalism of the tester, so that the non-professional tester can also complete the corresponding work of the big data test, and reduces the time cost and the labor cost of the big data test. The data test method of the embodiment of the present application can automatically mix and separate the original data and the test data, and does not need to manually insert and delete the test case into the original data, so as to avoid the problem of data pollution caused by human error and maximize the protection of the original data.
[0086] Figure 3 is a schematic diagram of the main process of the data test method of another embodiment of the present application. As shown in Figure 3 , the method comprises:
[0087] Step S301: obtaining original data, a structured query statement to be tested, a test case, and an expected result corresponding to the test case;
[0088] Step S302: determining whether the library table field used by the structured query statement to be tested and the library table field in the test case are the same;
[0089] Step S303: if the same, inserting the test case into the original data to obtain intermediate data, and adding a label field in the intermediate data to distinguish the test case and the original data in the intermediate data through the label field.
[0090] Step S304: parsing the structured query statement to be tested to obtain a first execution plan;
[0091] Step S305: adding the label field in the first execution plan to obtain a second execution plan;
[0092] Step S306: executing the structured query statement to be tested based on the intermediate data and the second execution plan to obtain a total execution result;
[0093] Step S307: filtering the actual execution result of the test case from the total execution result based on the label field;
[0094] Step S308: comparing the expected result corresponding to the test case with the actual execution result of the test case to obtain a test result.
[0095] For step S301, the test case and the expected result corresponding to the test case can be input in the form of a parameter file or input by a user. The format of the parameter file is not limited, which can be EXCEL, TXT, CSV, etc. In this embodiment, the tester does not need to understand the specific content of the original data, and only needs to design the test case and the expected result of the test case according to the business requirement.
[0096] For step S302, the step is used to check the structured query statement to be tested and the test case input by the user, and determine whether the condition for continuing execution is met. If yes, the following steps are continued, and if not, the test is determined to fail.
[0097] Specifically, the structured query statement to be tested and the test case are checked by the following steps:
[0098] parsing the structured query statement to be tested to obtain a first database name, a first data table name and a first data field;
[0099] parsing the test case to obtain a second database name, a second data table name and a second data field;
[0100] determining whether the first database name, the first data table name and the first data field are the same as the second database name, the second data table name and the second data field, respectively.
[0101] More specifically, the first database name, the first data table name and the first data field can be obtained by the following steps:
[0102] parsing the structured query statement to be tested to obtain a first database name and an abstract syntax tree;
[0103] Translate the abstract syntax tree by using a preset translation model to obtain a first data table name and a first data field.
[0104] The abstract syntax tree (AST), or simply syntax tree, is an abstract representation of the syntax structure of the source code. It represents the syntax structure of the programming language in the form of a tree, and each node on the tree represents a structure in the source code. In the execution process of HIVE, the first step is the parsing process, through which the parsed abstract syntax tree can be obtained. According to the running order of HIVE, after a single HIVE task is submitted, the structured statement to be queried (SQL to be queried) will first be translated into an abstract syntax tree by ANTLR3 syntax rules. The abstract syntax tree can convert SQL with the same meaning but different writing methods into the same syntax rule. For example, although DISTINCT and GROUP BY are different in writing, their abstract syntax trees are the same.
[0105] After obtaining the abstract syntax tree, the abstract syntax tree is translated by using a preset translation model to obtain a translated text, from which a first data table name and a first data field can be obtained. The preset translation model can be obtained by training a neural network model. As shown in FIG. 8, the translation model takes the abstract syntax tree as input and outputs the literal translation of the SQL execution logic as a result, aiming to translate the complex SQL into a logically coherent literal language, thereby helping users to understand and logically verify the structured query statement to be tested. Figure 4
[0106] For steps S303 to S306, first, the original data and the test case are combined to obtain intermediate data, and a label field is added to the intermediate data, and then the label field is added to the first execution plan to obtain a second execution plan. Based on the intermediate data and the second execution plan, the structured query statement to be queried is executed to obtain a total execution result. In the total execution result, there are both the execution result of the original data and the actual execution result of the test case. Through the label field, the execution result of the original data is separated from the actual execution result of the test case, and the actual execution result of the test case is compared with the expected result to obtain a test result. Since a single structured query statement can obtain data from multiple tables and is executed in multiple stages, the label field added in the first execution plan needs to follow a specific naming rule, for example, the label column added in Stage-1 is named stage1_test_sign, the label column added in Stage-2 is named stage2_test_sign, and so on. In this way, the column name of the label column is unique and distinguishable in the query process. For example, the first execution plan is SELECT name FROM table1, and the modified first execution plan becomes SELECT name, test_sign FROM table1. The label field test_sign is also added to each select statement layer by layer, to ensure that the final running result contains the label field test_sign.
[0107] For step S307, after the execution of the structured statement to be tested, the actual execution result of the test case is mixed into the total execution result, and therefore, the actual execution result of the test case needs to be separated from the total execution result according to the label field. After the actual execution result of the test case is separated, the label column is deleted from the remaining execution result, and the remaining result is the execution result of the original data.
[0108] For step S308, the actual execution result of the separated test case is compared with the expected result of the test case, if the comparison is consistent, the test passes, otherwise the test fails. Among them, for different SQL keywords, different verification rules can be set. For example, for SQL with JOIN, JOIN is used to query data from two or more tables according to the relationship between the columns in the tables, so it is necessary to find the result with the label field before and after JOIN, that is, the data with 2 label fields in the execution result. And if the keyword is LEFT JOIN, RIGHT JOIN or OUTER JOIN, it is also necessary to find the data with 2 label fields in the execution result. For SQL with ORDER BY, the ORDER BY statement is used to sort the result set according to the specified column, and when comparing the actual execution result and the expected result of the test case, the comparison needs to be performed in order. And if there is no ORDER BY keyword in the SQL, since the data order of HIVE query is indefinite, as long as the actual execution result is the same as the expected result, there is no requirement for the data order. For SQL with UNION, the UNION operation combines the results of two or more SELECT statements, so only the execution result with the label field needs to be found and compared directly.
[0109] The data test method of the embodiment of the present application automatically inserts the test case into the original data, so that the test case and the original data enter the execution process together and go through the same data processing logic to obtain the total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the separated test case is compared with the expected result of the test case to obtain the test result. The technical means reduces the requirements for the business proficiency and professionalism of the test personnel, so that non-professional test personnel can also complete the corresponding work of big data test, while reducing the time cost and labor cost of big data test. The data test method of the embodiment of the present application can automatically mix and separate the original data and the test data, without manually inserting and deleting the test case into the original data, avoiding the problem of data pollution caused by human error, and protecting the original data to the greatest extent.
[0110] In practical application, the data test method of the embodiment of the present application can be packaged into a plug-in or a tool. When using the plug-in or the tool, the user only needs to determine the structured query statement to be tested and the test case, which reduces the user threshold and improves the convenience.
[0111] In order to make the data test method of the embodiment of the present application more clear, the following embodiments are taken as examples for illustration.
[0112] (1) Obtain the structured query statement to be tested (hereinafter referred to as the to-be-tested SQL), the structured query statement to be tested, the test case, and the expected result corresponding to the test case. The to-be-tested SQL is as follows:
[0113]
[0114]
[0115] ORDER BY id
[0116] In the app_demoofnik_2 table, the following data is designed:
[0117] id name price 1 cup 3.5 13 hat 2.7 4 balloon 4.3
[0118] In the app_demoofnik_1 table, the following data is designed:
[0119] name price cup 0.8 hat 1.1 book 5.9
[0120] The expected result is as follows:
[0121] id name price risk_price 1 cup 3.5 0.8 4 balloon 4.3 NULL 13 hat 2.7 1.1
[0122] (2) After the data preparation is completed, the code execution and verification work of the embodiment is started. The same as the normal execution process of HIVE QL, the corresponding MapReduce execution plan is first generated, as shown in the following formula: Figure 5
[0123] In the HIVE execution plan, the SQL in the above example is divided into three execution stages (Stage): Stage-0 is the root stage, which executes the outer parent query and is responsible for returning the final result; Stage-1 is executed first, and Stage-2 depends on the execution result of Stage-1, so it will be arranged to be executed after Stage-1 is completed; finally, Stage-0 is executed, and the query result is returned.
[0124] The process of generating the execution plan will also generate an abstract syntax tree, which will be translated into a logical and coherent literal translation by a preset translation model and returned to the tester. In addition, the library table field of each execution stage is parsed from the literal translation, such as the library table app.app_demoofnik_1 and the field name, price in Stage-1.
[0125] Each of the above stages is a single MapReduce task, and each task also corresponds to the execution of a search of one of the tables. After the MapReduce task is generated, the table name and field of each subquery stage are first checked to determine whether the data table and field used by the test SQL are the same as the test case. If the test case and the test SQL differ in the table name or the field, execution is suspended, and the user is prompted for an error.
[0126] Then, the HIVE execution stage is entered. While the HIVE submits the MapReduce execution plan to the physical executor, the data of the user test case is also submitted to the executor. After the executor pulls the original data, the data of the test case is added to the end of the original data, and a column is added to mark all the data, as shown in the following table. The test data of the app_demoofnik_1 table is added to the end of the original data, and a new column test_sign is added at the end to mark the original data as 0 and the test case data as 1. Similarly, the same operation is performed on the test case data of the app_demoofnik_2 table.
[0127]
[0128]
[0129] (3) The select test_sign is automatically added to the execution plan to continuously mark the test case. In the example, the SQL is SELECT name, price FROM app.app_demoofnik_1. After the modification, the SQL is updated to SELECT name, price, test_sign FROM app.app_demoofnik_1.
[0130] (4) During the execution, the test_sign field follows the execution of the entire query to mark the data. After the execution of all stages is completed, the plug-in separates the data marked as 1 in the test_sign field in the result data, as shown in the following table.
[0131] id name price risk_price stage0_test_sign stage1_test_sign og_1 og_name_1 15.0 20.0 0 0 og_2 og_name_2 10.0 40.0 0 0 og_3 cup 4.2 0.8 0 1 1 cup 3.5 0.8 1 1 4 balloon 4.3 NULL 1 1 13 hat 2.7 1.1 1 1
[0132] If there is only one test_sign column in the result table, the data with the test_sign column being 1 is extracted in the separation stage; if there are multiple test_sign columns in the result table, the data with all test_sign columns being 1 is extracted, and the data with the test_sign column being 1 is the actual execution result of the test case. After the data with the test_sign column being 1 is extracted, all the data with the test_sign column being 1 is deleted, and finally the test_sign column is deleted to obtain the result of the original data of the SQL query to be tested.
[0133] (5) The actual execution result of the separated test case is compared with the expected result of the test case, if the comparison is consistent, the test passes, otherwise the test fails.
[0134] The data test method of the embodiment of the application inserts the test case into the original data automatically, so that the test case and the original data enter the execution process together and experience the same data processing logic to obtain the total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the separated test case is compared with the expected result of the test case to obtain the test result. The technical means reduces the requirements for the business proficiency and professionalism of the tester, so that the non-professional tester can also complete the corresponding work of the big data test, and reduces the time cost and labor cost of the big data test. The data test method of the embodiment of the application can automatically mix and separate the original data and the test data, and does not need to manually insert and delete the test case into the original data, so that the problem of data pollution caused by human error is avoided, and the original data is protected to the greatest extent.
[0135] Figure 6 is a schematic diagram of main modules of a data test device 600 of the embodiment of the application, as shown in the figure, the device 600 comprises: Figure 6
[0136] An acquisition module 601 is configured to acquire original data, a structured query statement to be tested, a test case and an expected result corresponding to the test case.
[0137] A mixing module 602 is configured to insert the test case into the original data to obtain intermediate data.
[0138] An execution module 603 is configured to execute the structured query statement to be tested based on the intermediate data to obtain a total execution result.
[0139] A screening module 604 is configured to screen an actual execution result of the test case from the total execution result.
[0140] The comparison module 605 is configured to compare the expected result corresponding to the test case with the actual execution result of the test case to obtain a test result.
[0141] Optionally, the mixing module 602 is further configured to insert the test case into the original data to obtain intermediate data, and add a label field in the intermediate data to distinguish the test case in the intermediate data from the original data through the label field.
[0142] The screening module 604 is further configured to screen the actual execution result of the test case from the total execution result based on the label field.
[0143] Optionally, the mixing module 602 is further configured to parse the structured query statement to be tested to obtain a first execution plan, and add the label field in the first execution plan to obtain a second execution plan.
[0144] The execution module 603 is further configured to execute the structured query statement to be tested based on the intermediate data and the second execution plan to obtain a total execution result.
[0145] Optionally, the mixing module 602 is further configured to determine whether a library table field used by the structured query statement to be tested and a library table field in the test case are the same, and if so, insert the test case into the original data to obtain intermediate data.
[0146] Optionally, the mixing module 602 is further configured to parse the structured query statement to be tested to obtain a first database name, a first data table name and a first data field, parse the test case to obtain a second database name, a second data table name and a second data field, and respectively determine whether the first database name, the first data table name and the first data field are the same as the second database name, the second data table name and the second data field.
[0147] Optionally, the mixing module 602 is further configured to parse the structured query statement to be tested to obtain a first database name and an abstract syntax tree, and translate the abstract syntax tree by using a preset translation model to obtain a first data table name and a first data field.
[0148] Optionally, the comparison module 605 is further configured to determine a keyword of the structured query statement to be tested, determine a check rule corresponding to the keyword, and compare the expected result corresponding to the test case with the actual execution result of the test case according to the check rule to obtain a test result.
[0149] The data testing device provided by the embodiment of the present application inserts the test case into the original data automatically, so that the test case and the original data enter the execution process together and experience the same data processing logic to obtain the total execution result. Then, the actual execution result of the test case is separated from the total execution result. The actual execution result of the test case separated from the total execution result is compared with the expected result of the test case to obtain the test result. The technical means for obtaining the test result reduces the requirements for the business proficiency and professionalism of the tester, so that the non-professional tester can also complete the corresponding work of the big data test, and the time cost and the labor cost of the big data test are reduced. The data testing method provided by the embodiment of the present application can automatically mix and separate the original data and the test data, and does not need to manually insert and delete the test case into the original data, so that the problem of data pollution caused by human error is avoided, and the original data is protected to the greatest extent.
[0150] The device described above can perform the method provided by the embodiment of the present application, and has the corresponding function modules and beneficial effects of the execution method. Technical details not described in detail in the embodiment can be referred to the method provided by the embodiment of the present application.
[0151] Figure 7 An exemplary system architecture 700 to which the data testing method or the data testing device provided by the embodiment of the present application can be applied is shown.
[0152] As shown in Figure 7 , the system architecture 700 can include terminal devices 701, 702, 703, a network 704 and a server 705. The network 704 is used to provide a communication link medium between the terminal devices 701, 702, 703 and the server 705. The network 704 can include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0153] A user can use the terminal devices 701, 702, 703 to interact with the server 705 through the network 704 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 701, 702, 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0154] The terminal devices 701, 702, 703 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers and desktop computers, etc.
[0155] The server 705 can be a server that provides various services, such as a background management server that provides support for a shopping website browsed by a user using the terminal device 701, 702, 703. The background management server can analyze and process received product information query requests and the like, and feed back the processing results (e.g., target push information, product information) to the terminal device.
[0156] It should be noted that the data testing method provided by the embodiment of the present application is generally executed by the server 705, and accordingly, the data testing apparatus is generally arranged in the server 705.
[0157] It should be understood that, Figure 7 The number of terminal devices, networks and servers in the above-mentioned system is merely illustrative. Any number of terminal devices, networks and servers can be provided according to the implementation needs.
[0158] Reference will now be made to Figure 8 which shows a structural schematic diagram of a computer system 800 suitable for implementing the terminal device of the embodiment of the present application. Figure 8 The terminal device shown is merely an example, and should not impose any limitation on the function and use range of the embodiment of the present application.
[0159] As shown in Figure 8 , the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 802 or programs loaded from a storage portion 808 into a random access memory (RAM) 803. Various programs and data required for the operation of the system 800 are also stored in the RAM 803. The CPU 801, the ROM 802 and the RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0160] The following components are connected to the I / O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output portion 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), and the like, and a speaker, and the like; a storage portion 808 including a hard disk, and the like; and a communication portion 809 including a network interface card such as a LAN card, a modem, and the like. The communication portion 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable media 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, and the like, is mounted on the drive 810 as needed, so that a computer program read therefrom is installed in the storage portion 808 as needed.
[0161] In particular, the processes described above with reference to the flow charts can be implemented as a computer software program in accordance with the embodiments disclosed herein. For example, embodiments disclosed herein include a computer program product which includes a computer program tangibly embodied on a computer readable medium, the computer program including program code for executing the methods illustrated by the flow charts. In such embodiments, the computer program can be downloaded and installed from a network via the communication portion 809 and / or installed from a removable media 811. When the computer program is executed by the central processing unit (CPU) 801, the above-described functions defined in the system of the present application are executed.
[0162] It should be noted that the computer readable medium shown in the present application can be a computer readable signal medium or a computer readable storage medium or any combination of the two. The computer readable storage medium may, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination of the above. More specific examples of the computer readable storage medium can include, but are not limited to, an electrical connection having one or more wires, 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), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device or apparatus. In the present application, the computer readable signal medium can include a data signal carried in a baseband or as a carrier wave in a propagated data signal, which carries computer readable program code. Such a propagated data signal can take many forms, including but not limited to, an electromagnetic signal, an optical signal or any suitable combination of the above. The computer readable signal medium can also be any computer readable medium that can send, propagate or transfer a program for use by or in connection with an instruction execution system, device or apparatus. The program code contained on the computer readable medium can be transmitted using any suitable medium, including but not limited to wireless, wire line, optical cable, RF, or any suitable combination of the above.
[0163] The computer program product of the present application can include a computer readable medium, which can be a built-in medium installed in the device or a separate medium like a USB flash drive, removable hard disk, etc. which can be connected to the device through a portable or fixed data interface. The computer program product of the present application can also be a downloaded program of an Internet website, a service mechanism of an online software service provider, or a mobile phone website.
[0164] The modules described in the embodiments of the present application can be implemented by software, or can be implemented by hardware. The described modules can also be arranged in a processor, for example, a processor can be described as: a processor includes a sending module, an obtaining module, a determining module and a first processing module. In some cases, the names of these modules do not constitute a limitation on the units themselves, for example, the sending module can also be described as: a module for sending a picture obtaining request to a connected server.
[0165] As another aspect, the present application also provides a computer readable medium, which can be included in the device described in the above embodiments, or can exist separately and not be assembled into the device. The above computer readable medium carries one or more programs, which, when executed by the device, cause the device to include:
[0166] Obtaining original data, a structured query statement to be tested, a test case and an expected result corresponding to the test case;
[0167] Inserting the test case into the original data to obtain intermediate data;
[0168] Executing the structured query statement to be tested based on the intermediate data to obtain a total execution result;
[0169] Screening an actual execution result of the test case from the total execution result;
[0170] Comparing the expected result corresponding to the test case with the actual execution result of the test case to obtain a test result.
[0171] The technical scheme of the embodiment of the present application reduces the requirements for the service proficiency and professionalism of testers, so that non-professional testers can also complete the corresponding work of big data testing, while reducing the time cost and labor cost of big data testing; the data testing method of the embodiment of the present application can automatically mix and separate original data and test data, without manually inserting and deleting test cases in the original data, thereby avoiding the problem of data pollution caused by human errors, and protecting the original data to the greatest extent.
[0172] The above detailed description does not constitute a limitation on the protection scope of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A data testing method, characterized in that, include: Obtain the raw data, the structured query statement to be tested, the test cases, and the expected results corresponding to the test cases; The test cases are inserted into the original data to obtain intermediate data; Based on the intermediate data, the structured query statement to be tested is executed to obtain the overall execution result; The actual execution results of the test cases are filtered out from the overall execution results; The test results are obtained by comparing the expected results of the test cases with the actual execution results of the test cases. Inserting the test cases into the original data to obtain intermediate data includes: The test cases are inserted into the original data to obtain intermediate data, and a label field is added to the intermediate data to distinguish the test cases in the intermediate data from the original data through the label field; The actual execution results of the test cases are filtered from the overall execution results, including: Based on the label field, the actual execution results of the test cases are filtered out from the total execution results; Inserting the test cases into the original data to obtain intermediate data includes: Determine whether the database table fields used in the structured query statement to be tested are the same as the database table fields in the test case; If they are the same, the test case is inserted into the original data to obtain intermediate data.
2. The method according to claim 1, characterized in that, Inserting the test cases into the original data to obtain intermediate data includes: The test cases are inserted into the original data to obtain intermediate data, and a label field is added to the intermediate data to distinguish the test cases in the intermediate data from the original data through the label field; Parse the structured query statement to be tested to obtain the first execution plan; Add the label field to the first execution plan to obtain the second execution plan; Based on the intermediate data, the structured query statement to be tested is executed to obtain the overall execution result, which includes: based on the intermediate data and the second execution plan, the structured query statement to be tested is executed to obtain the overall execution result.
3. The method according to claim 1, characterized in that, Determining whether the database table fields used by the structured query statement to be tested are the same as those in the database table fields in the test case includes: Parse the structured query statement to be tested to obtain the first database name, the first data table name, and the first data field; Parse the test cases to obtain the second database name, the second table name, and the second data field; Determine whether the first database name, the first data table name, and the first data field are the same as the second database name, the second data table name, and the second data field.
4. The method according to claim 3, characterized in that, Parsing the structured query statement to be tested yields the first database name, the first table name, and the first data field, including: Parse the structured query statement to be tested to obtain the first database name and abstract syntax tree; The abstract syntax tree is translated using a preset translation model to obtain the first data table name and the first data field.
5. The method according to claim 1, characterized in that, By comparing the expected results of the test cases with the actual execution results of the test cases, the test results obtained include: Determine the keywords of the structured query statement to be tested; Determine the verification rules corresponding to the keywords; According to the verification rules, the expected results corresponding to the test cases are compared with the actual execution results of the test cases to obtain the test results.
6. A data testing device, characterized in that, include: The acquisition module is used to acquire raw data, the structured query statement to be tested, test cases, and the expected results corresponding to the test cases; A hybrid module is used to insert the test cases into the original data to obtain intermediate data; The execution module is used to execute the structured query statement to be tested based on the intermediate data and obtain the overall execution result; The filtering module is used to filter out the actual execution results of the test cases from the total execution results; The comparison module is used to compare the expected results corresponding to the test cases with the actual execution results of the test cases to obtain the test results; The hybrid module is also used for: The test cases are inserted into the original data to obtain intermediate data, and a label field is added to the intermediate data to distinguish the test cases in the intermediate data from the original data through the label field; The filtering module is also used for: Based on the label field, the actual execution results of the test cases are filtered out from the total execution results; The hybrid module is also used to: determine whether the database table fields used by the structured query statement to be tested are the same as the database table fields in the test case; if they are the same, insert the test case into the original data to obtain intermediate data.
7. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-5.
8. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Cloud database testing method and device, equipment and storage medium
CN109271326A
Automatic testing method and device for synchronous asynchronization of cache data
CN110795494A