CN113868138A - Method, system, equipment and storage medium for acquiring test data - Google Patents

Method, system, equipment and storage medium for acquiring test data Download PDF

Info

Publication number
CN113868138A
CN113868138A CN202111149797.8A CN202111149797A CN113868138A CN 113868138 A CN113868138 A CN 113868138A CN 202111149797 A CN202111149797 A CN 202111149797A CN 113868138 A CN113868138 A CN 113868138A
Authority
CN
China
Prior art keywords
query
data
statement
discrimination
executing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111149797.8A
Other languages
Chinese (zh)
Inventor
季景瑜
梁树峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Weikun Shanghai Technology Service Co Ltd
Original Assignee
Weikun Shanghai Technology Service Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Weikun Shanghai Technology Service Co Ltd filed Critical Weikun Shanghai Technology Service Co Ltd
Priority to CN202111149797.8A priority Critical patent/CN113868138A/en
Publication of CN113868138A publication Critical patent/CN113868138A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention provides a method for acquiring test data, which comprises the following steps: executing a test case, and monitoring and intercepting SQL sentences in the test case; analyzing a table name from the SQL sentence, and inquiring whether a corresponding data table exists in a first database or not through the table name; executing SQL sentences with the types of query sentences in a first database, sequentially deleting the query conditions according to the discrimination of each query condition, and executing the query sentences with the deleted query conditions until data are obtained from a data table; by the method, the SQL sentences in the test cases can not be abnormal when being executed in the database, the acquisition rate of the test data is improved, and the energy consumption of computer equipment is reduced.

Description

Method, system, equipment and storage medium for acquiring test data
Technical Field
The present invention relates to artificial intelligence technology, and in particular, to a method, system, device, and storage medium for acquiring test data.
Background
The test is one of the links for ensuring the stability and the effectiveness of the product. Taking the unit test task as an example, it may include module interface test, module local data structure test, module boundary condition test, all independent execution paths in the module test, and each error handling path test of the module.
The test data used in the unit test task is an SQL file fixedly stored in a database and is not generated in real time; due to the upgrading and maintenance of the user framework, when the test is executed, the original test data needs to be extracted from the database again for modification and replacement, so that the efficiency of obtaining the test data is low.
Disclosure of Invention
The invention aims to provide a method, a system, equipment and a storage medium for acquiring test data, which are used for solving the problem of low efficiency of acquiring the test data by the existing database.
One aspect of the embodiments of the present invention provides a method for acquiring test data, where the method includes:
executing a test case, and monitoring and intercepting SQL sentences in the test case;
analyzing a table name of a test data table from the SQL sentence, and inquiring whether a corresponding data table exists in a first database or not through the table name;
if the data table is queried and the SQL statement is a query statement, acquiring the discrimination of each query condition in the SQL statement; the discrimination is used for expressing the probability of obtaining data after deleting the corresponding query conditions, and each query condition corresponds to one discrimination;
sequentially deleting the query conditions according to the discrimination of each query condition; and executing the query statement after the query condition is deleted until the data is obtained from the data table, and importing the data obtained from the data table into a second database as test data.
Preferably, the step after querying whether the corresponding data table exists in the first database by the table name includes: if the data table cannot be queried, acquiring a table structure corresponding to the SQL statement in a third database through the SQL statement; generating a table building statement according to the table structure; executing the table building statement in the first database to generate a target data table; and judging whether the SQL statement is an insertion statement, and if the SQL statement is the insertion statement, inserting one or more test data values in the SQL statement into the target data table.
Preferably, the querying whether a corresponding data table exists in the first database through the table name; if the data table is queried and the SQL statement is a query statement, acquiring the discrimination of each query condition in the SQL statement; sequentially deleting the query conditions according to the discrimination of each query condition; executing the query statement after deleting the query condition until the data is obtained from the data table, and importing the data obtained from the data table into a second database as test data, wherein the step comprises the following steps: judging the type of the SQL statement; if the SQL statement is a query statement, step S1 is executed;
s1: executing the SQL statement and confirming whether the data can be acquired in the data table;
if the data is acquired, executing step S3;
if the data is not acquired, acquiring the discrimination of each query condition in the SQL statement, and executing step S2;
repeatedly executing the step S2 until data are obtained from the data table, correcting the obtained data according to the SQL statement, and executing the step S3;
s2: analyzing the N query conditions in the SQL statement, and deleting one of the N query conditions according to the discrimination of each query condition;
composing the unreduced query conditions into a target query statement, executing the target query statement, wherein N is a positive integer and is more than or equal to 1, and the value of N is reduced by 1;
s3: and importing the acquired data into the second database as test data.
Preferably, the step S2 is repeatedly executed until data is obtained from the data table, and the step of modifying the obtained data according to the SQL statement includes,
repeatedly executing the steps S6-1-S6-2 until data are acquired in the data table, and executing the step S6-3;
s6-1: sorting the discrimination of each query condition in the N query conditions, deleting one of the N query conditions according to a sorting result, and forming the query conditions which are not deleted into a target query statement, wherein the value of N is reduced by 1;
s6-2: executing the target query statement;
s6-3: and correcting the acquired data according to the N query conditions in the SQL statement.
Preferably, the step of obtaining the discrimination of each query condition in the N query conditions includes a step of calculating the discrimination of each query condition in the SQL statement by using the following formula, including:
PM=KM/HM
wherein, the PMThe discrimination of the query condition M; said KMRepresenting the number of times test data is acquired after the query condition M is deleted, HMIndicating the number of times the query M is deleted.
Preferably, the step of sorting the discrimination of each of the N query conditions, deleting one of the N query conditions according to the sorting result, and forming the query conditions that are not deleted into the target query statement includes sorting the discrimination of each of the N query conditions from high to low; deleting the query condition with the highest discrimination, and forming the query conditions which are not deleted into a target query statement.
Preferably, the step of obtaining, through the SQL statement, the table structure corresponding to the SQL statement in the third database includes searching, according to the table name in the SQL statement, the third database for a field name, a field type, a field attribute, and a primary key corresponding to the table name, so as to construct the table structure corresponding to the SQL statement.
One aspect of the embodiments of the present invention further provides a system for acquiring test data, where the system for acquiring test data includes: the interception module is used for executing the test case and monitoring and intercepting SQL sentences in the test case; the query module is used for analyzing the table name of the test data table from the SQL sentence and querying whether the corresponding data table exists in the first database or not through the table name; the acquisition module is used for acquiring the discrimination of each query condition in the SQL statement; the discrimination is used for expressing the probability of obtaining data after deleting the corresponding query conditions, and each query condition corresponds to one discrimination; sequentially deleting the query conditions according to the discrimination of each query condition; and executing the query statement after the query condition is deleted until the data is obtained from the data table, and importing the data obtained from the data table into a second database as test data.
An aspect of the embodiments of the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method for acquiring test data as described above.
An aspect of the embodiments of the present invention further provides a computer-readable storage medium, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor executes the computer program to implement the steps of the method for acquiring test data as described above.
In the method, the system, the device and the computer-readable storage medium for acquiring test data provided by the embodiments of the present invention, the computer program may be executed by at least one processor, so that the at least one processor executes the steps of the method for acquiring test data.
The embodiment of the invention discloses a method, a system, equipment and a storage medium for acquiring test data; after the SQL sentences are intercepted, the SQL sentences with the types of the query sentences are executed in the first database, the query conditions are sequentially deleted according to the discrimination of each query condition, and the query sentences after the query conditions are deleted are executed until the data are obtained from the data table.
Drawings
FIG. 1 is a diagram schematically illustrating an application environment of a method for obtaining test data according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method for obtaining test data according to a first embodiment of the invention;
FIG. 3 is a diagram illustrating the steps followed by querying the first database for the presence of a corresponding data table by the table name;
FIG. 4 is a diagram illustrating sub-steps of step S103 in FIG. 2;
FIG. 5 is a diagram illustrating another sub-step of step S103 in FIG. 2;
FIG. 6 is a block diagram schematically illustrating a system for acquiring test data according to a second embodiment of the present invention; and
fig. 7 schematically shows a hardware architecture diagram of a computer device suitable for implementing the test data acquisition method according to a third embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the descriptions relating to "first", "second", etc. in the embodiments of the present invention are only for descriptive purposes and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
In the description of the present invention, it should be understood that the numerical references before the steps do not identify the order of performing the steps, but merely serve to facilitate the description of the present invention and to distinguish each step, and thus should not be construed as limiting the present invention.
The following are explanations of terms involved in the present invention:
SQL, Structured Query Language (Structured Query Language), is a special purpose programming Language, a database Query and programming Language, used to access data and Query, update, and manage relational database systems; structured query languages are high-level, non-procedural programming languages that allow users to work on high-level data structures. The method does not require a user to specify a data storage method and does not require the user to know a specific data storage mode, so that different database systems with completely different underlying structures can use the same structured query language as an interface for data input and management.
The data table is a grid virtual table for temporarily storing data; the data table is composed of three parts of a table name, fields in the table and records of the table.
Query statements, used to select data from the data tables, store the results of the query in a results table.
An insert statement for inserting data into a column specified in the data table.
Fig. 1 is a schematic diagram illustrating an environmental application of a test data acquisition method according to an embodiment of the present invention. In an exemplary embodiment, the server 1 may be configured with a plurality of databases, as shown in fig. 1.
The server 1 may be composed of a single or multiple computer devices, such as a rack server, a blade server, a tower server, or a rack server (including an independent server, or a server cluster composed of multiple servers), and the like. The server 1 may also be a cloud server that provides basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a web service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), and a big data and artificial intelligence platform.
As shown in fig. 1, the server 1 may be configured with a plurality of databases, which in this embodiment includes a first database 2, a second database 3, and a third database 4. The first database 2 is an UT database, interception, full-table scanning and judgment of SQL statements are finished in the UT database, the second database 3 is an UT code generation database, test data in the data preparation process can generate an excel table in an xls format in the second database 3 for storage, and before the test data are executed, the test data stored in the excel table can be directly called; the third database 4 is used for storing the test data of the tester, and when the UT database cannot obtain the data, the corresponding test data can be obtained in the third database 4 according to the request.
The invention provides a test data acquisition method, which can acquire data in a first database 2, a second database 3 and a third database 4 according to a server 1. A number of embodiments are provided below, each of which may be used to implement the test data acquisition steps described above. For ease of understanding, the following description will be exemplarily made with the server 1 as an execution subject.
Example one
FIG. 2 is a flow chart that schematically illustrates a method for obtaining test data, in accordance with an embodiment of the present invention.
As shown in fig. 2, the method may include steps S101 to S103, wherein:
step S101, executing a test case, monitoring and intercepting SQL sentences in the test case;
it should be noted that the test case refers to performing a test task through a specific product, and the test case of this embodiment may include a plurality of SQL statements, where the SQL statements include a plurality of groups of test data, and the server 1 monitors the SQL statements in the test case, and calls the AOP section through the server 1 to intercept the SQL statements.
It should be noted that the AOP profile is a profile-oriented programming profile. In software development, functions scattered throughout an application are referred to as cross-cutting centers (CROSS-CUTTING CONCERNS), and in general, these CROSS-CUTTING CONCERNS are conceptually separated from the business logic of the application. For example, declarative transactions, logs, security, caching and the like are all irrelevant to business logic, the things can be abstracted into modules, a section-oriented programming mode is adopted, the functions are defined where to use in a declarative mode, and the functions of the modular crosscut point-of-interest programs are realized through a pre-compiling mode and a runtime dynamic proxy to carry out unified maintenance, so that crosscut points of interest are separated from objects influenced by the functions.
Step S102, analyzing the table name of the test data table of the data table from the SQL sentence;
inquiring whether a corresponding data table exists in the first database 2 or not through the table name;
preferably, the table name in the SQL statement is extracted through natural language processing, for example, through a regular expression, and after the table name is extracted, the server 1 performs full-table scanning on the data table, where full-table scanning refers to searching each record of the data table through the server until the data table matching the given table name is returned.
Step S103: if the data table is queried and the SQL statement is a query statement, acquiring the discrimination of each query condition in the SQL statement; the discrimination is used for expressing the probability of obtaining data after deleting the corresponding query conditions, and each query condition corresponds to one discrimination;
sequentially deleting the query conditions according to the discrimination of each query condition, and executing the query statement after deleting the query conditions until data are obtained from the data table; and imports the data obtained from the data table as test data into the second database 3.
It should be noted that the data operation statement in the SQL statement may include a query statement, an insert statement, an update statement, and a delete statement; in this embodiment, there are two types of intercepted SQL statements, one is a query statement, and the other is an insertion statement, where the query statement includes one or more query conditions, and corresponding data can be queried in the data table according to the query conditions in the query statement.
It should be noted that the xls format is a common spreadsheet format, and in this embodiment, after the SQL statement is executed through the SQL statement intercepted by the server 1, the obtained data is exported as test data in the excel table of the xls format in the second database 3.
Preferably, the second database 3 of this embodiment is preferably an UT code generation database, and the test data of the data preparation process is all imported into the second database 3 and a corresponding excel table is generated.
As shown in fig. 3, the step of querying whether the corresponding data table exists in the first database 2 by the table name includes,
step S201: if the data table cannot be queried, acquiring a table structure corresponding to the SQL statement in the third database 4 through the SQL statement;
step S202: generating a table building statement according to the table structure;
step S203: and executing the table building statement in the first database 2 to generate a target data table.
Step S204: and judging whether the SQL statement is an insertion statement, and if the SQL statement is the insertion statement, inserting one or more test data values in the SQL statement into the target data table.
Preferably, the data definition statements in the SQL statements may include table building statements, modification statements, and pruning statements. The table building statement is used in this embodiment to build a target data table according to a table structure. The modify statement is used to add, modify, or delete columns in an existing data table. The prune statement is used to prune the index, table, and database.
Preferably, by executing the table building statement, the data table in the table building statement may be added to the first database 2, and then one or more values are inserted into the specified column in the target data table by an insert statement.
Preferably, the table structure is obtained in the second database 3 by jdbc, and the step of obtaining the table structure specifically comprises,
step S201-1: and searching a field name, a field type, a field attribute and a primary key corresponding to the table name in the third database 4 according to the table name in the SQL statement to construct a table structure corresponding to the SQL statement.
Exemplarily, it is assumed that the SQL statement is selected from the order word table _ name ═ student 'and product _ id ═ 1and user _ id ═ 1and status ═ INIT'; wherein table _ name ═ student' indicates that the table name is student; "product _ id", "user _ id", and "status" are all field names in the SQL statement; the table names and the field names can be extracted by regular expressions, and according to the table names and the field names, the field types, the field attributes and the primary keys corresponding to the field names are searched in the third database 4 to generate the table structure corresponding to the SQL statements.
As shown in fig. 4, the querying whether a corresponding data table exists in the first database through the table name; if the data table is queried and the SQL statement is a query statement, acquiring the discrimination of each query condition in the SQL statement; sequentially deleting the query conditions according to the discrimination of each query condition; executing the query statement after deleting the query condition until data is acquired from the data table, and importing the data acquired from the data table as test data into the second database 3, wherein the steps include:
step S103-1: judging whether the SQL statement is a query statement;
if the SQL statement is a query statement, executing the step S103-2;
preferably, the data operation statement in the SQL statement may include a query statement, an insert statement, an update statement, and a delete statement. The query statement may be used to select data from a data table. The insert statement may be used to insert a new row into the data table. The update statement may be used to modify data in a data table, and delete a row in a data table. The type of the SQL statement is mainly determined by the beginning field of the statement, for example, the beginning field of the query statement is "SELECT", the beginning field of the INSERT statement is "INSERT", the beginning field of the UPDATE statement is "UPDATE 0", and the beginning field of the DELETE statement is "DELETE"; if the field name detected by the natural language is 'SELECT', the SQL statement can be judged to be a query statement, otherwise, the SQL statement is judged to be other statements.
Step S103-2: executing the SQL statement and confirming whether the data can be acquired in the data table;
if the data is acquired, executing the step S103-4;
if the data is not acquired, acquiring the discrimination of each query condition in the SQL statement, and executing the step S103-3;
illustratively, there is one SQL statement: a select from order product _ id ═ 1and user _ id ═ 1and status ═ INIT'; executing the SQL statement, the server 1 queries a value corresponding to the product _ id, a value corresponding to the user _ id and a value corresponding to the status in the first database 2, and if the value corresponding to the product _ id is queried to be 1 in the first database 2, the value corresponding to the user _ id is 1, and the status is in an initialization state; returning data, wherein the returned data are values corresponding to product _ id, user _ id and status; otherwise no data will be returned.
Repeatedly executing the step S103-3 to the step S103-4 until data return exists, correcting the acquired data according to the SQL statement, and executing the step S103-5;
step S103-3: analyzing N query conditions in the SQL statement, and deleting one of the N query conditions;
step S103-4: and forming the non-deleted query conditions into a target query statement, executing the target query statement, wherein N is a positive integer and is greater than 1, and the value of N is reduced by 1.
Step S103-5: and importing the acquired data into the second database 3 as test data.
Illustratively, a certain SQL statement is: select from order product _ id and user _ id and status are INIT'; the three query conditions in the query sentence are that the values of "product _ id ═ xxx", "user _ id ═ xxx", and "status ═ INIT'" N are 3, respectively; data satisfying the above three query conditions simultaneously in the second database 3 cannot be found, if it is changed to select from order product _ id xxx and status INIT'; that is, after one query condition "user _ id ═ xxx" is deleted, the value of N becomes 2, and the possibility of acquiring data increases; changing from order where status as 'INIT'; the likelihood of data acquisition is further increased.
Further preferably, as shown in fig. 5, the step S103-3 to the step S103-4 are repeatedly executed until data is returned, the acquired data is corrected according to the SQL statement, and the step of executing the step S103-5 specifically includes,
repeatedly executing the steps S303-1 to S303-2 until data are obtained in the data table, and executing the step S303-4;
step S303-1: sorting the discrimination of each query condition in the N query conditions, deleting one of the N query conditions according to a sorting result, and forming the query conditions which are not deleted into a target query statement, wherein the value of N is reduced by 1;
as a preferred scheme, when the query statement executed cannot query the data in the database, the search range can be expanded by deleting the query condition, in order to reduce the number of times of deleting the query condition, the present embodiment introduces the discrimination, and deletes the query condition according to the size of the discrimination, so that the efficiency of acquiring the data is higher.
Step S303-2: executing the target query statement;
step S303-3: and correcting the acquired data according to the N query conditions in the SQL statement.
Exemplarily, assume that the query statement is select from order product _ id-1 and user _ id-1 and status-INIT'; the 3 query conditions corresponding to the query statement are "product _ id ═ 1", "user _ id ═ 1", and "status ═ INIT'", respectively; after the query condition is executed, data is not obtained after the query statement is executed, and after one query condition is deleted, the query statement becomes selected from order word product _ id 1and status INIT; the data is acquired, but the user _ id of the acquired data is not 1, so that the user _ id of the acquired data is modified to 1 to ensure consistency between the acquired data and the value of the query condition in the query statement, and when the query statement is executed again in the first database 2, the returned data are "product _ id ═ 1", "user _ id ═ 1", "status ═ INIT'", so that data cannot be acquired in the first database 2 when the test case is executed again due to data update in the first database 2.
Preferably, the step of obtaining the discrimination specifically comprises,
step S103-1A: calculating the discrimination of each query condition in the SQL statement by the following formula:
PM=KM/HM
wherein, the PMThe discrimination of the query condition M; said KMRepresenting the number of times test data is acquired after the query condition M is deleted, HMIndicating the number of times the query M is deleted.
Illustratively, there is a query statement select from order product id xxx and user id xxx and status INIT; the modification is selected from order product _ id and status as 'INIT'; and deleting the number of times of the query condition +1, if the data is acquired after the query condition is deleted, deleting the number of times of the data acquired after the condition +1, otherwise, deleting the data acquired after the condition, and repeating the above principle, wherein after the query statement with the query condition of 'user _ id ═ xxx' is deleted each time, accumulating the number of times of deleting the query condition and the number of times of acquiring the data after the query condition is deleted, and by a machine learning method, after a plurality of test cases are executed, the probability of acquiring the data after the query condition 'user _ id ═ xxx' is deleted can be acquired according to the counted data.
Further preferably, as shown in fig. 5, the step of sorting the discrimination of each of the N query conditions, deleting one of the N query conditions according to the sorting result, and composing the query conditions that are not deleted into the target query statement includes,
step S303-1A: sorting the discrimination of each query condition in the N query conditions from high to low;
step S303-1B: deleting the query condition with the highest discrimination, and forming the query conditions which are not deleted into a target query statement.
Exemplarily, it is assumed that the higher the probability of acquiring the test data after deleting the query condition "user _ id ═ xxx" is, the higher the priority of deleting the query condition "user _ id ═ xxx" is, in this embodiment, the query condition with high priority deletion discrimination is performed, which reduces the number of times of acquiring the data when executing the SQL statement; the energy consumption of the server is reduced, and the data acquisition efficiency is improved.
Example two
Fig. 6 schematically shows a block diagram of a test data acquisition system according to a second embodiment of the present invention, which may be divided into one or more program modules, the one or more program modules being stored in a storage medium and executed by one or more processors to implement the second embodiment of the present invention. The program modules referred to in the embodiments of the present invention refer to a series of computer program instruction segments that can perform specific functions, and the following description will specifically describe the functions of the program modules in the embodiments.
As shown in fig. 6, the acquiring system 500 may include an intercepting module 501, a querying module 502, and an acquiring module 503, wherein:
the interception module 501 is configured to execute a test case, and monitor and intercept an SQL statement in the test case;
the query module 502 is configured to parse a table name of the test data table from the SQL statement, and query whether a corresponding data table exists in the first database according to the table name;
an obtaining module 503, configured to obtain a discrimination of each query condition in the SQL statement; the discrimination is used for expressing the probability of obtaining data after deleting the corresponding query conditions, and each query condition corresponds to one discrimination; sequentially deleting the query conditions according to the discrimination of each query condition; and executing the query statement after the query condition is deleted until the data is obtained from the data table, and importing the data obtained from the data table into a second database as test data.
The obtaining module 503 is further configured to obtain, through the SQL statement, a table structure corresponding to the SQL statement in a third database; generating a table building statement according to the table structure; executing the table building statement in the first database to generate a target data table; and judging whether the SQL statement is an insert statement, and if the SQL statement is the insert statement, inserting one or more values in the SQL statement into the target data table.
The obtaining module 503 is further configured to determine the type of the SQL statement;
if the SQL statement is a query statement, step S1 is executed;
s1: executing the SQL statement and confirming whether the data can be acquired in the data table;
if the data is acquired, executing step S3;
if the data is not acquired, acquiring the discrimination of each query condition in the SQL statement, and executing step S2;
repeatedly executing the step S2 until data are obtained from the data table, correcting the obtained data according to the SQL statement, and executing the step S3;
s2: analyzing the N query conditions in the SQL statement, and deleting one of the N query conditions according to the discrimination of each query condition; composing the unreduced query conditions into a target query statement, executing the target query statement, wherein N is a positive integer and is more than or equal to 1, and the value of N is reduced by 1;
s3: and importing the acquired data into the second database as test data.
The obtaining module 503 is further configured to repeatedly execute steps S6-1 to S6-1 until data is obtained in the data table, and execute step S6-3;
s6-1: sorting the discrimination of each query condition in the N query conditions, deleting one of the N query conditions according to a sorting result, and forming the query conditions which are not deleted into a target query statement, wherein the value of N is reduced by 1;
s6-2: executing the target query statement;
s6-3: and correcting the acquired data according to the N query conditions in the SQL statement.
The obtaining module 503 is further configured to calculate the degree of distinction of each query condition in the SQL statement by the following formula:
PM=KM/HM
wherein, the PMThe discrimination of the query condition M; said KMRepresenting the number of times test data is acquired after the query condition M is deleted, HMIndicating the number of times the query M is deleted.
The obtaining module 503 is further configured to sort the degree of distinction of each query condition in the N query conditions from high to low; deleting the query condition with the highest discrimination, and forming the query conditions which are not deleted into a target query statement.
The obtaining module 503 is further configured to search, according to the table name in the SQL statement, the third database for a field name, a field type, a field attribute, and a primary key corresponding to the table name, so as to construct a table structure corresponding to the SQL statement.
EXAMPLE III
Fig. 7 schematically shows a hardware architecture diagram of a computer device 1000 adapted to implement the test data acquisition method according to a third embodiment of the present invention. The computer device 1000 may be an electronic device 6, such as may be part of the electronic device 6. In this embodiment, the computer device 1000 is a device capable of automatically performing numerical calculation and/or information processing in accordance with a command set in advance or stored. For example, the server may be a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server or a rack server (including an independent server or a server cluster composed of a plurality of servers), a gateway, and the like. As shown in fig. 7, the computer device 1000 includes at least, but is not limited to: the memory 1010, processor 1020, and network interface 1030 may be communicatively linked to each other via a system bus. Wherein:
the memory 1010 includes at least one type of computer-readable storage medium including flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), Static Random Access Memory (SRAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), Programmable Read Only Memory (PROM), magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage 1010 may be an internal storage module of the computer device 1000, such as a hard disk or a memory of the computer device 1000. In other embodiments, the memory 1010 may be an external storage device of the computer device 1000, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), or the like, provided on the computer device 1000. Of course, the memory 1010 may also include both internal and external memory modules of the computer device 1000. In this embodiment, the memory 1010 is generally used for storing an operating system installed in the computer apparatus 1000 and various types of application software, such as program codes of a test data acquisition method. In addition, the memory 1010 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 1020 may be, in some embodiments, a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor, or other data Processing chip. The processor 1020 is generally configured to control the overall operation of the computer device 1000, such as performing control and processing related to data interaction or communication with the computer device 1000. In this embodiment, the processor 1020 is configured to execute program codes stored in the memory 1010 or process data.
The network interface 1030 may comprise a wireless network interface or a wired network interface, with the network interface 1030 typically being used to establish communications links between the computer device 1000 and other computer devices. For example, the network interface 1030 is used to connect the computer apparatus 1000 to an external terminal via a network, establish a data transmission channel and a communication link between the computer apparatus 1000 and the external terminal, and the like. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network, Bluetooth (Bluetooth), or Wi-Fi.
It should be noted that FIG. 7 only shows a computer device having components 1010 and 1030, but it should be understood that not all of the shown components are required and that more or fewer components may be implemented instead.
In this embodiment, the method for obtaining the test data stored in the memory 1010 may be further divided into one or more program modules and executed by one or more processors (in this embodiment, the processor 1020) to implement the embodiment of the present invention.
Example four
The present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of acquiring test data in the embodiments.
In this embodiment, the computer-readable storage medium includes a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the computer readable storage medium may be an internal storage unit of the computer device, such as a hard disk or a memory of the computer device. In other embodiments, the computer readable storage medium may be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the computer device. Of course, the computer-readable storage medium may also include both internal and external storage devices of the computer device. In this embodiment, the computer-readable storage medium is generally used for storing an operating system and various types of application software installed in the computer device, for example, the program code of the test data acquisition method in the embodiment, and the like. Further, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.
It will be apparent to those skilled in the art that the modules or steps of the embodiments of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for obtaining test data, the method comprising:
executing a test case, and monitoring and intercepting SQL sentences in the test case;
analyzing a table name of a test data table from the SQL sentence, and inquiring whether a corresponding data table exists in a first database or not through the table name;
if the data table is queried and the SQL statement is a query statement, acquiring the discrimination of each query condition in the SQL statement; the discrimination is used for expressing the probability of obtaining data after deleting the corresponding query conditions, and each query condition corresponds to one discrimination;
sequentially deleting the query conditions according to the discrimination of each query condition, and executing the query statement after deleting the query conditions until data are obtained from the data table; and importing the data obtained from the data table as test data into a second database.
2. The method for acquiring test data according to claim 1, wherein the step of querying whether the corresponding data table exists in the first database by the table name is followed by:
if the data table cannot be queried, acquiring a table structure corresponding to the SQL statement in a third database;
generating a table building statement according to the table structure;
executing the table building statement in the first database to generate a target data table;
and judging whether the SQL statement is an insertion statement, and if the SQL statement is the insertion statement, inserting one or more test data values in the SQL statement into the target data table.
3. The method for acquiring test data according to claim 1, wherein the first database is queried by the table name to determine whether a corresponding data table exists; if the data table is queried and the SQL statement is a query statement, acquiring the discrimination of each query condition in the SQL statement; sequentially deleting the query conditions according to the discrimination of each query condition; executing the query statement after deleting the query condition until the data is obtained from the data table, and importing the data obtained from the data table into a second database as test data, wherein the step comprises the following steps:
judging the type of the SQL statement;
if the SQL statement is a query statement, step S1 is executed;
s1: executing the SQL statement and confirming whether the data can be acquired in the data table;
if the data is acquired, executing step S3;
if the data is not acquired, acquiring the discrimination of each query condition in the SQL statement, and executing step S2;
repeatedly executing the step S2 until data are obtained from the data table, correcting the obtained data according to the SQL statement, and executing the step S3;
s2: analyzing the N query conditions in the SQL statement, and deleting one of the N query conditions according to the discrimination of each query condition;
composing the unreduced query conditions into a target query statement, executing the target query statement, wherein N is a positive integer and is more than or equal to 1, and the value of N is reduced by 1;
s3: and importing the acquired data into the second database as test data.
4. The method according to claim 3, wherein the step S2 is repeatedly executed until data is obtained from the data table, and the step of modifying the obtained data according to the SQL statement includes:
repeatedly executing the steps S6-1-S6-2 until data are acquired in the data table, and executing the step S6-3;
s6-1: sorting the discrimination of each query condition in the N query conditions, deleting one of the N query conditions according to a sorting result, and forming the query conditions which are not deleted into a target query statement, wherein the value of N is reduced by 1;
s6-2: executing the target query statement;
s6-3: and correcting the acquired data according to the N query conditions in the SQL statement.
5. The method according to claim 3, wherein the step of obtaining the discrimination of each query condition in the SQL statement comprises:
calculating the discrimination of each query condition in the SQL statement by the following formula:
PM=KM/HM
wherein, the PMThe discrimination of the query condition M; said KMRepresenting the number of times test data is acquired after the query condition M is deleted, HMIndicating the number of times the query M is deleted.
6. The method according to claim 4, wherein the step of sorting the discrimination of each of the N query conditions, deleting one of the N query conditions according to the sorting result, and forming the query conditions that are not deleted into the target query statement comprises:
sorting the discrimination of each query condition in the N query conditions from high to low;
deleting the query condition with the highest discrimination, and forming the query conditions which are not deleted into a target query statement.
7. The method according to claim 2, wherein the step of obtaining the table structure corresponding to the SQL statement in the third database through the SQL statement comprises:
and searching a field name, a field type, field attributes and a main key corresponding to the table name in the third database according to the table name in the SQL statement so as to construct a table structure corresponding to the SQL statement.
8. A system for acquiring test data, comprising:
the interception module is used for executing the test case and monitoring and intercepting SQL sentences in the test case;
the query module is used for analyzing the table name of the test data table from the SQL sentence and querying whether the corresponding data table exists in the first database or not through the table name;
the acquisition module is used for acquiring the discrimination of each query condition in the SQL statement; the discrimination is used for expressing the probability of obtaining data after deleting the corresponding query conditions, and each query condition corresponds to one discrimination; sequentially deleting the query conditions according to the discrimination of each query condition; and executing the query statement after the query condition is deleted until the data is obtained from the data table, and importing the data obtained from the data table into a second database as test data.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor, when executing the computer program, is adapted to carry out the steps of the method of obtaining test data according to any one of claims 1 to 7.
10. A computer-readable storage medium, in which a computer program is stored, the computer program being executable by at least one processor to cause the at least one processor to perform the steps of the method for obtaining test data according to any one of claims 1 to 7.
CN202111149797.8A 2021-09-29 2021-09-29 Method, system, equipment and storage medium for acquiring test data Pending CN113868138A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111149797.8A CN113868138A (en) 2021-09-29 2021-09-29 Method, system, equipment and storage medium for acquiring test data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111149797.8A CN113868138A (en) 2021-09-29 2021-09-29 Method, system, equipment and storage medium for acquiring test data

Publications (1)

Publication Number Publication Date
CN113868138A true CN113868138A (en) 2021-12-31

Family

ID=78992492

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111149797.8A Pending CN113868138A (en) 2021-09-29 2021-09-29 Method, system, equipment and storage medium for acquiring test data

Country Status (1)

Country Link
CN (1) CN113868138A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115145831A (en) * 2022-09-05 2022-10-04 湖南长银五八消费金融股份有限公司 Non-invasive test data recovery method and system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115145831A (en) * 2022-09-05 2022-10-04 湖南长银五八消费金融股份有限公司 Non-invasive test data recovery method and system
CN115145831B (en) * 2022-09-05 2022-11-08 湖南长银五八消费金融股份有限公司 Non-invasive test data recovery method and system

Similar Documents

Publication Publication Date Title
CN110908997B (en) Data blood relationship construction method and device, server and readable storage medium
US11366856B2 (en) System and method for updating target schema of graph model
CN110795455B (en) Dependency analysis method, electronic device, computer apparatus, and readable storage medium
CN111367886A (en) Method and device for data migration in database
CN111708805A (en) Data query method and device, electronic equipment and storage medium
CN115599359A (en) Code generation method, device, equipment and medium
CN116483850A (en) Data processing method, device, equipment and medium
CN113868138A (en) Method, system, equipment and storage medium for acquiring test data
CN113468209A (en) High-speed memory database access method for power grid monitoring system
CN115543428A (en) Simulated data generation method and device based on strategy template
CN116126950A (en) Real-time materialized view system and method
CN115168358A (en) Database access method and device, electronic equipment and storage medium
CN114490865A (en) Database synchronization method, device, equipment and computer storage medium
CN112579705A (en) Metadata acquisition method and device, computer equipment and storage medium
CN117271481B (en) Automatic database optimization method and equipment
CN113326401B (en) Method and system for generating field blood relationship
CN117573199B (en) Model difference comparison analysis method, device, equipment and medium
CN114741408A (en) Data scheduling method, system, computer device and readable storage medium
CN116521941A (en) Semi-structured data processing method, electronic device and storage medium
CN116610711A (en) Data query method, device, equipment and storage medium
CN117493391A (en) Task matching method, device, computer equipment and storage medium
CN115934708A (en) Method, device, equipment and medium for processing database table
CN115328540A (en) Mapping method of XML document and JAVA class for application framework
CN114741666A (en) Authority control method and related device
CN115344568A (en) Memory index mechanism processing method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination