Method and device for testing function of sql translation into target language, and storage medium

By automatically configuring test cases and interface test code, and using pre-built temporary data tables to store test data, the problem of low efficiency in functional testing when translating SQL into the target language is solved, thus achieving highly efficient automated testing.

CN114691524BActive Publication Date: 2025-11-07CHINA PING AN LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210439658.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-25
Publication Date
2025-11-07
Estimated Expiration
2042-04-25

AI Technical Summary

Technical Problem

In existing technologies, functional testing that translates SQL into the target language is inefficient and requires a lot of manual work, making the testing process cumbersome and complicated.

Method used

By obtaining the interface parameters and test data source of the interface to be tested, test cases and interface test code are automatically configured, test data is stored in a pre-built temporary data table, and test functions are called in the database to generate functional test results.

Benefits of technology

It reduced manpower consumption, improved the efficiency of functional testing for language conversion, and achieved automated test data comparison and accurate test result generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114691524B_ABST
    Figure CN114691524B_ABST
Patent Text Reader

Abstract

The application provides a function test method and device for translating SQL into a target language, electronic equipment and a computer readable storage medium. The method comprises the following steps: creating SQL interface test code and target language interface test code according to obtained interface parameters; obtaining test cases matched with the interface to be tested according to a test data source of the interface parameters; for each test case, calling a pre-generated SQL test function based on the SQL interface test code to obtain first test data, and calling a pre-generated target language test function based on the target language interface test code to obtain second test data; saving the first test data to a pre-built first temporary data table and saving the second test data to a pre-built second temporary data table; and generating a function test result according to the first temporary data table and the second temporary data table. In the embodiment of the application, a temporary data table does not need to be manually created, which can reduce the consumption of manpower and improve the function test efficiency of language conversion.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to, but are not limited to, the technical field of software, and particularly relate to a method and device for testing the function of sql translation into a target language, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] After the procedural language structured query language (PLSQL) is translated into other languages, the correctness of the target code needs to be verified. At present, the common test method in the industry is: for the interface to be tested, the relevant test cases, interface test codes, and database related parameters are manually assigned and then the function test is performed. Although the function test can be realized, it greatly consumes the energy and time of manual testing, and the operation is relatively cumbersome and complex, so the function test efficiency is low. SUMMARY

[0003] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.

[0004] The embodiments of the present application provide a method and device for testing the function of sql translation into a target language, an electronic device, and a computer readable storage medium, which can reduce the consumption of manpower and improve the function test efficiency of language conversion.

[0005] In a first aspect, the embodiments of the present application provide a method for testing the function of sql translation into a target language, comprising:

[0006] Obtaining interface parameters corresponding to a to-be-tested interface, and creating sql interface test code and target language interface test code according to the interface parameters;

[0007] Obtaining a test data source of the interface parameters, and obtaining at least one test case matched with the to-be-tested interface according to the test data source of the interface parameters;

[0008] For each test case, calling a pre-generated sql test function based on the sql interface test code to obtain first test data, and calling a pre-generated target language test function based on the target language interface test code to obtain second test data;

[0009] Saving the first test data to a pre-built first temporary data table, and saving the second test data to a pre-built second temporary data table;

[0010] Generating a function test result of the test case according to the first temporary data table and the second temporary data table.

[0011] According to the function test method for translating the SQL into the target language provided in the embodiments, the following beneficial effects are achieved: the test cases and the interface test code related to the interface parameters and the test data source are configured automatically based on the interface parameters and the test data source, without manual operation, so that the human consumption is greatly reduced; and the two temporary data tables are pre-built, so that the two groups of test data are directly saved into the pre-built temporary data tables, the test data comparison is accurately performed, the interface test comparison is optimized, and the function test efficiency of language conversion is greatly improved.

[0012] According to some embodiments of the present application, the test data source according to the interface parameters is obtained at least one test case matched with the interface to be tested, comprising:

[0013] According to the test data source of the interface parameters, all test data sets corresponding to the interface to be tested are obtained, wherein each test data set includes at least one test data;

[0014] The Cartesian product of any two test data sets is obtained, and at least one test case matched with the interface to be tested is obtained according to all Cartesian products.

[0015] After obtaining the interface parameters, the test data source of the interface parameters is recorded, each test data set including test data is obtained based on the test data source configuration query, and all test cases are formed by calculating the Cartesian product of the test data sets. In this process, the final confirmation of the test cases can be realized by pre-configuring the interface parameters, and the consumption of manual configuration is greatly reduced.

[0016] According to some embodiments of the present application, the pre-generated sql test function is called based on the sql interface test code, to obtain first test data, and the pre-generated target language test function is called based on the target language interface test code, to obtain second test data, comprising:

[0017] According to the interface to be tested, the sql test interface and the target language test interface corresponding to the interface to be tested are obtained;

[0018] According to the sql test interface, the sql test function is generated, and according to the target language test interface, the target language test function is generated;

[0019] The sql test function and the target language test function are written into the database matched with the interface to be tested.

[0020] Based on the sql interface test code, the first test data is obtained by calling the sql test function from the database, and based on the target language interface test code, the second test data is obtained by calling the target language test function from the database.

[0021] The test interface is determined in advance based on the interface to be tested, so that the corresponding test function is determined according to the test interface, that is, the required test function can be determined by configuring the parameters of the interface to be tested, and the test function is written into the database, so that the test function can be further called from the database, and the test function can be well applied, so as to obtain accurate and reliable test data based on the test function.

[0022] According to some embodiments of the application, the first temporary data table and the second temporary data table are generated based on the following steps:

[0023] A temporary table creation statement is generated according to the interface to be tested;

[0024] The temporary table creation statement is written into the database, so that the database generates the first temporary data table and the second temporary data table according to the temporary table creation statement.

[0025] By constructing a temporary table creation statement and writing it into a database, the database can construct a corresponding temporary data table based on the temporary table creation statement, so that the test data obtained in the functional test can be directly input into the temporary data table which has been constructed, and the efficiency of functional test is improved.

[0026] According to some embodiments of the application, after the functional test result of the test case is generated according to the first temporary data table and the second temporary data table, the method further comprises:

[0027] The first test data in the first temporary data table is rolled back, and the second test data in the second temporary data table is rolled back, to obtain the initial data corresponding to the interface to be tested.

[0028] By rolling back the test data in the temporary data table, the modified data in the main transaction can be restored, so that the initial data corresponding to the interface to be tested is obtained, and the test of the next test case will not have adverse effects, facilitating repeated testing.

[0029] According to some embodiments of the application, after the at least one test case matched with the interface to be tested is determined according to the test data source of the interface parameter, the method further comprises:

[0030] The number of all the test cases is determined;

[0031] A plurality of test processes are created, and each of the test processes is assigned with the same number of test cases according to the number of the test cases.

[0032] A plurality of test processes are created according to the number of test cases, and each of the test processes is assigned with the same number of test cases, so as to realize multi-process parallel testing and improve the testing efficiency.

[0033] According to some embodiments of the present application, the functional test result of the test case comprises at least one of the following types:

[0034] The number information of the interface to be tested;

[0035] The number information of the test case;

[0036] The test information corresponding to each of the test cases;

[0037] The calling time information of the sql test function;

[0038] The calling time information of the target language test function;

[0039] The generation time information of the first test data;

[0040] The generation time information of the second test data.

[0041] The output functional test result can be related to, but is not limited to, the test information such as the interface to be tested, the test case, the test function and the test data, and can well represent the actual situation of the functional test and meet the functional test requirement of language conversion.

[0042] In a second aspect, the embodiments of the present application further provide a functional test device for converting sql into a target language, comprising:

[0043] A first processing module is configured to obtain interface parameters corresponding to an interface to be tested, and create sql interface test code and target language interface test code according to the interface parameters;

[0044] A second processing module is configured to obtain a test data source of the interface parameters, and obtain at least one test case matched with the interface to be tested according to the test data source of the interface parameters;

[0045] A third processing module is configured to, for each of the test cases, call a pre-generated sql test function based on the sql interface test code to obtain first test data, and call a pre-generated target language test function based on the target language interface test code to obtain second test data;

[0046] The fourth processing module is configured to save the first test data into a pre-constructed first temporary data table and save the second test data into a pre-constructed second temporary data table.

[0047] The fifth processing module is configured to generate a function test result of the test case according to the first temporary data table and the second temporary data table.

[0048] According to the embodiment provided in the present application, the sql translation function test device for the target language has at least the following beneficial effects: the interface parameters and the test data source of the interface to be tested are obtained through the first processing module and the second processing module, the relevant test case and the interface test code can be configured based on the interface parameters and the test data source, this process does not require manual operation, and the configuration can be automatically performed based on the obtained data, so that the human consumption can be greatly reduced; and the two temporary data tables are pre-constructed, so that in the case that the two groups of test data are obtained based on the third processing module, the two groups of test data can be directly saved into the pre-constructed temporary data tables based on the fourth processing module, the test data comparison can be accurately performed by the fifth processing module, the purpose of optimizing the interface test comparison is achieved, and since the temporary data table does not need to be manually created, the target code can be directly compiled and run for the test case test, so that the function test efficiency of the language conversion can be greatly improved.

[0049] In a third aspect, the embodiments of the present application further provide an electronic device, which comprises a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the sql translation function test method for the target language as described in the first aspect.

[0050] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores computer executable instructions, and the computer executable instructions are used to execute the sql translation function test method for the target language as described in the first aspect.

[0051] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent from the description, or can be learned by practice of the present application. The objects and other advantages of the present application will be realized and achieved by means of the structures particularly pointed out in the description and the appended claims. BRIEF DESCRIPTION OF DRAWINGS

[0052] The accompanying drawings are included to provide a further understanding of the technical solutions of the present application, and constitute a part of the specification, and are used to explain the technical solutions of the present application together with the embodiments of the present application, and do not constitute a limitation to the technical solutions of the present application.

[0053] Figure 1is a flowchart of a functional test method for sql translation into a target language provided by an embodiment of the present application;

[0054] Figure 2 is a flowchart of obtaining at least one test case matched with the to-be-tested interface in the functional test method for sql translation into a target language provided by an embodiment of the present application;

[0055] Figure 3 is a flowchart of obtaining first test data and second test data in the functional test method for sql translation into a target language provided by an embodiment of the present application;

[0056] Figure 4 is a flowchart of generating a first temporary data table and a second temporary data table in the functional test method for sql translation into a target language provided by an embodiment of the present application;

[0057] Figure 5 is a flowchart after obtaining at least one test case matched with the to-be-tested interface in the functional test method for sql translation into a target language provided by an embodiment of the present application;

[0058] Figure 6 is a flowchart after generating a functional test result of the test case in the functional test method for sql translation into a target language provided by an embodiment of the present application;

[0059] Figure 7 is an execution flowchart of the functional test method for sql translation into a target language provided by an embodiment of the present application;

[0060] Figure 8 is a schematic diagram of a functional test device for sql translation into a target language provided by an embodiment of the present application;

[0061] Figure 9 is a schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0062] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.

[0063] It should be noted that, although the functional modules are divided in the device schematic diagram, and the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a manner different from the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification and claims and the above-described drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.

[0064] It should be noted that, unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0065] This application provides a functional testing method, apparatus, electronic device, and computer-readable storage medium for translating SQL into a target language. By obtaining the interface parameters and test data source of the interface to be tested, relevant test cases and interface test code can be configured based on the interface parameters and test data source. This process requires no manual operation and can be automatically configured based on the obtained data, thus greatly reducing manpower consumption. Furthermore, by pre-building two temporary data tables, when two sets of test data are obtained, the two sets of test data can be directly saved to the pre-built temporary data tables respectively, ensuring accurate execution of test data comparison and achieving the purpose of optimizing interface test comparison. At the same time, since there is no need to manually create temporary data tables, this process can directly compile and run the target code for test case testing, which can greatly improve the efficiency of functional testing for language conversion.

[0066] The embodiments of this application will be further described below with reference to the accompanying drawings.

[0067] like Figure 1 As shown, Figure 1 This is a flowchart of a functional testing method for translating SQL into a target language according to an embodiment of this application. The functional testing method for translating SQL into a target language includes, but is not limited to, steps S100 to S500.

[0068] Step S100: Obtain the interface parameters corresponding to the interface to be tested, and create SQL interface test code and target language interface test code based on the interface parameters.

[0069] In one embodiment, by simply obtaining the interface parameters of the interface to be tested, the SQL interface test code before and after translation and the target language interface test code can be configured based on the interface parameters of the interface to be tested. This is relatively simple and reliable. Furthermore, since the interface parameters can characterize the features of the interface to be tested, the test code configured through the interface parameters can be well adapted to the interface to be tested, so as to facilitate the testing of the interface to be tested.

[0070] In one embodiment, there may be, but is not limited to, multiple interfaces to be tested. Each interface is tested separately without affecting the others. The target language is set by the user in the specific scenario, such as Java, Python, Perl, etc., which is not limited in this embodiment.

[0071] It should be noted that the specific way of creating the sql interface test code and the target language interface test code according to the interface parameters can be various, and is well known to those skilled in the art, and can be selected and applied in specific application scenarios, which is not limited in the embodiment.

[0072] In step S200, the test data source of the interface parameters is obtained, and at least one test case matched with the interface to be tested is obtained according to the test data source of the interface parameters.

[0073] In an embodiment, only by obtaining the test data source of the interface parameters, the corresponding test case can be configured based on the test data source of the interface parameters. Compared with the case of manually configuring the test case, the test case can be automatically matched by the test data source, and since the test data source of the interface parameters represents the characteristic situation of the interface parameters, the test case configured based on the test data source can be well adapted to the interface to be tested, so as to test the interface to be tested.

[0074] It should be noted that the content of the matching and configuration of the test data source and the test case can not be limited, and is well known to those skilled in the art, and can be selected and applied in specific application scenarios, which is not limited in the embodiment.

[0075] It can be understood that the interface parameters in the above embodiments can be multiple, and multiple parameters can constitute a parameter group. The constitution of the parameter group in different application scenarios can be different, which is not limited in the embodiment.

[0076] In Figure 2 In the example of the embodiment, the step S200 of obtaining at least one test case matched with the interface to be tested according to the test data source of the interface parameters includes but is not limited to steps S210 to S220.

[0077] In step S210, all test data sets corresponding to the interface to be tested are obtained according to the test data source of the interface parameters, wherein each test data set includes at least one test data.

[0078] In step S220, the Cartesian product of any two test data sets is obtained, and at least one test case matched with the interface to be tested is obtained according to all Cartesian products.

[0079] In an embodiment, after the interface parameters are obtained, only by recording the test data source of the interface parameters, each test data set including test data can be configured and queried based on the test data source. Further, all test cases can be constituted by calculating the Cartesian product of the test data sets. In this process, the final confirmation of the test case can be realized only by pre-configuring the interface parameters, which can greatly reduce the cost of manual configuration.

[0080] It should be noted that since the Cartesian product is the result of the multiplication of sets and sets, the obtained test cases can be multiple, and each test case can be tested in a specific application scenario.

[0081] In step S300, for each test case, the pre-generated sql test function is called based on the sql interface test code to obtain first test data, and the pre-generated target language test function is called based on the target language interface test code to obtain second test data.

[0082] In an embodiment, when in the scenario of testing each test case, the test function can be called by the configured two interface test codes to obtain test data, which is simple and reliable, does not require manual intervention, has low cost, and by obtaining the corresponding two test data before and after language translation, it is convenient to judge whether the translated code meets the functional requirements.

[0083] In Figure 3 In the example, step S300 includes but is not limited to steps S310-S340.

[0084] In step S310, the sql test interface and the target language test interface corresponding to the to-be-tested interface are obtained according to the to-be-tested interface.

[0085] In step S320, the sql test function is generated according to the sql test interface, and the target language test function is generated according to the target language test interface.

[0086] In step S330, the sql test function and the target language test function are written into the database matched with the to-be-tested interface.

[0087] In step S340, the sql test function is called from the database based on the sql interface test code to obtain first test data, and the target language test function is called from the database based on the target language interface test code to obtain second test data.

[0088] In an embodiment, the test interface is pre-confirmed based on the to-be-tested interface, so that the corresponding test function is determined according to the test interface, that is, the test function required can be determined by configuring the to-be-tested interface parameters, and the test function is written into the database, so that the test function can be further called from the database, ensuring that the test function can be well applied, so as to obtain accurate and reliable test data based on the test function.

[0089] It should be noted that the type of database matched with the to-be-tested interface can be multiple, which can be selected as needed in a specific application scenario, which is not limited in this embodiment.

[0090] The following gives specific examples to illustrate the working principle of the above embodiments.

[0091] Example one:

[0092] For the sql interface test code, an sql test interface is encapsulated for each interface to be tested, all the sql test interfaces form a test set and are written into an oracle database for the sql test code to call; the sql test interface is automatically generated according to the interface parameter description, so the parameters and return values of the sql test interface are consistent with the interface to be tested, and the functions of the sql test interface include but are not limited to:

[0093] Firstly, the interface to be tested is called;

[0094] Secondly, the interface for saving data to the corresponding temporary data table is called to save the original table data;

[0095] Thirdly, the rollback is performed to restore the modified data in the main transaction, so as to avoid affecting the test of the target language interface, and facilitate repeated testing.

[0096] Example two:

[0097] For the Java interface test code, the corresponding database access object (Data Access Object, DAO) interface and xml are created for calling the interface for saving data to the corresponding temporary data table.

[0098] Taking Java as an example, a Java test function is encapsulated for each interface to be tested, which is similar to the sql interface test code, and the functions of the Java test function include but are not limited to:

[0099] Firstly, the corresponding interface to be tested is called;

[0100] Secondly, the DAO interface for saving data to the corresponding temporary data table is called to save the original table data;

[0101] Thirdly, the exception rollback processing and solution of the main transaction are performed.

[0102] In addition, at least one Controller interface can be encapsulated for each interface to be tested for the Java test code to call; the controller interface can simply call the encapsulated Java test function and handle the thrown exception.

[0103] In step S400, the first test data is saved to the pre-constructed first temporary data table, and the second test data is saved to the pre-constructed second temporary data table.

[0104] In an embodiment, by pre-building the corresponding temporary data table, the two sets of test data can be directly saved to the pre-built temporary data table when the test data is obtained, ensuring accurate test data comparison and optimizing interface test comparison. The test data corresponding to the language before and after translation are placed in different temporary data tables, which can be compared separately to obtain more effective functional test results.

[0105] In Figure 4 In an example, the first temporary data table and the second temporary data table can be but not limited to generated based on the following steps S410 to S420.

[0106] Step S410, generating a temporary table creation statement according to the interface to be tested;

[0107] Step S420, writing the temporary table creation statement to the database to make the database generate the first temporary data table and the second temporary data table according to the temporary table creation statement.

[0108] In an embodiment, by constructing the temporary table creation statement and writing it to the database, the database can construct the corresponding temporary data table based on the temporary table creation statement, so that the test data obtained during the functional test can be directly input into the already constructed temporary data table, improving the efficiency of functional test.

[0109] The following gives specific examples to illustrate the working principle of the above-mentioned embodiments.

[0110] Example three:

[0111] Taking the creation of the first temporary data table as an example, the temporary table creation statement is automatically generated according to the configuration of the interface to be tested, and then the corresponding first temporary data table is created by connecting the oracle database. In addition, a collection of saving data to the first temporary data table is created at the same time. The saving of data to the first temporary data table is performed in a sub-transaction, ensuring that the data in the first temporary data table will not be affected when the data rollback is performed after the interface test.

[0112] It should be noted that the construction method of the second temporary data table is similar to that of the first temporary data table, and is not described here to avoid redundancy.

[0113] Step S500, generating a functional test result of the test case according to the first temporary data table and the second temporary data table.

[0114] In an embodiment, by obtaining the interface parameters of the interface to be tested and the test data source, the relevant test case and interface test code can be configured based on the interface parameters and the test data source. This process does not require manual operation and can be automatically configured based on the obtained data, thereby greatly reducing the labor consumption. Furthermore, by pre-building two temporary data tables, in the case of obtaining two sets of test data, the two sets of test data can be directly saved to the pre-built temporary data tables, ensuring accurate test data comparison and achieving the purpose of optimizing interface test comparison. At the same time, since the temporary data table does not need to be created manually, this process can directly compile and run the target code for test case testing, thereby greatly improving the functional test efficiency of language conversion.

[0115] It should be noted that after the above parameter content is configured, the corresponding configuration of the target language project needs to be replaced according to the configuration, for example, the database token, server listening port, etc. can be replaced and configured, and then the relevant commands are automatically assembled to compile and run the target language project. Since this part of the content is well known to those skilled in the art, it will not be described here.

[0116] It can be understood that the functional test result of the test case includes at least one of the following types:

[0117] The number of test interfaces to be tested;

[0118] The number of test cases;

[0119] The test information corresponding to each test case;

[0120] The invocation time information of the sql test function;

[0121] The invocation time information of the target language test function;

[0122] The generation time information of the first test data;

[0123] The generation time information of the second test data.

[0124] In an embodiment, the output functional test result can but is not limited to the test information of the test interface to be tested, the test case, the test function and the test data, which can well represent the actual situation of the functional test, that is, the number of each test case, the number of failed tests, the number of successful tests and the invocation time, etc. can be intuitively presented, which meets the functional test requirements of language conversion. In addition, in specific application scenarios, those skilled in the art can configure the functional test result of the output test case by themselves, which is not limited in this embodiment.

[0125] In Figure 5 the example, step S200 further includes but is not limited to steps S600 to S700.

[0126] Step S600, determine the number of all test cases;

[0127] Step S700, create multiple test processes, and assign the same number of test cases to each test process according to the number of test cases.

[0128] In an embodiment, a corresponding plurality of test processes is created according to the number of test cases, and the same number of test cases is assigned to each test process, so as to realize multi-process parallel testing and improve the testing efficiency.

[0129] It can be understood that the test process can be constructed according to the corresponding network program, and the type is not limited and can be configured according to the specific situation, which is not limited in the embodiment.

[0130] In the example of Figure 6 , step S500 further includes but is not limited to step S800.

[0131] Step S800, roll back the first test data in the first temporary data table, and roll back the second test data in the second temporary data table to obtain the initial data corresponding to the interface to be tested.

[0132] In an embodiment, by rolling back the test data in the temporary data table, the modified data in the main transaction can be restored to obtain the initial data corresponding to the interface to be tested, so as to ensure that there is no adverse effect when testing the next test case, and facilitate repeated testing.

[0133] The working principle of each embodiment is illustrated by the following specific examples.

[0134] Example four:

[0135] As shown in Figure 7 , the Figure 7 is an execution flowchart of a functional test method for translating sql into a target language according to an embodiment of the present application.

[0136] In the example of Figure 7 , first, configuration is performed, and then functional testing is performed after the configuration is completed, which includes the following step processes:

[0137] In the configuration phase, two temporary tables are automatically created for each configured main transaction data table to save the original table data modified by the sql and java interface, which is used for data comparison; and the interface test code of sql and java is automatically created based on the interface parameter description; and the source of the test data of the interface parameter group is recorded, which supports query from sql and direct configuration, and the Cartesian product of the testable data set of all parameter groups then constitutes all test cases of the interface.

[0138] Firstly, a temporary table stage is created, for example, a first temporary data table is created, a temporary table creation statement is automatically generated according to the configuration of the interface to be tested, and then the corresponding first temporary data table is created by connecting the oracle database; in addition, a set for saving data to the first temporary data table is created at the same time, and the saving data to the first temporary data table is performed in a sub-transaction, so as to ensure that the data in the first temporary data table will not be affected when the data rollback is performed after the interface test;

[0139] Secondly, an interface test code generation stage, for the sql interface test code, an sql test interface is encapsulated for each interface to be tested, all the sql test interfaces form a test set and are written into the oracle database for the sql test code to call; the sql test interface is automatically generated according to the interface parameter description, so the parameters and return values of the sql test interface are consistent with the interface to be tested, and the functions of the sql test interface include but are not limited to: 1) calling the interface to be tested; 2) calling the interface for saving data to the corresponding temporary data table to save the original table data; 3) rollback, restoring the data modified in the main transaction to avoid affecting the test of the target language interface, and also facilitating repeated testing.

[0140] For the Java interface test code, a corresponding database access object (Data Access Object, DAO) interface and xml are created for calling the interface for saving data to the corresponding temporary data table. For example, a Java test function is encapsulated for each interface to be tested, which is similar to the sql interface test code, and the functions of the Java test function include but are not limited to: 1) calling the corresponding interface to be tested; 2) calling the DAO interface for saving data to the corresponding temporary data table to save the original table data; 3) processing and solving the exception rollback of the main transaction; in addition, at least one Controller interface is encapsulated for each interface to be tested for the Java test code to call; wherein, the controller interface can simply call the encapsulated Java test function and handle the thrown exception.

[0141] Then, a compilation and running stage, according to the configuration, the corresponding configuration of the target language project is replaced, for example, the database token, the server listening port and other configurations can be replaced, and then the related commands are automatically assembled to compile and run the Java project.

[0142] Then, the test logic stage traverses these test cases, respectively calls the sql test interface and the java test interface, and compares the temporary table data on both sides according to the configuration of the temporary data table to determine whether the data is consistent; wherein, multi-process parallel testing is supported, that is, only the number of processes needs to be configured, and the corresponding number of processes will be automatically created, and the same number of testable test cases will be allocated to each process, and the testing efficiency is greatly improved.

[0143] Finally, the output test report stage collects the results of each test and outputs a complete test report, and the test report content includes the number of test interfaces, the number of test cases for each test, the number of failed tests, the number of successful tests, the calling time of the sql and java interfaces, and the like.

[0144] In addition, as shown in the Figure 8 embodiment of the present application also provides a functional test device for translating sql into a target language, comprising:

[0145] The first processing module 100 is configured to obtain interface parameters corresponding to the interface to be tested, create sql interface test code and target language interface test code according to the interface parameters;

[0146] The second processing module 200 is configured to obtain a test data source of the interface parameters, and obtain at least one test case matched with the interface to be tested according to the test data source of the interface parameters;

[0147] The third processing module 300 is configured to, for each test case, call a pre-generated sql test function based on the sql interface test code to obtain first test data, and call a pre-generated target language test function based on the target language interface test code to obtain second test data;

[0148] The fourth processing module 400 is configured to save the first test data to a pre-built first temporary data table, and save the second test data to a pre-built second temporary data table;

[0149] The fifth processing module 500 is configured to generate a functional test result of the test case according to the first temporary data table and the second temporary data table.

[0150] In an embodiment, the interface parameters and the test data source of the interface to be tested are acquired by the first processing module 100 and the second processing module 200, and the relevant test case and interface test code can be configured based on the interface parameters and the test data source. This process does not require manual operation and can be automatically configured based on the acquired data, thereby greatly reducing the labor consumption. Two temporary data tables are pre-constructed, so that in the case of obtaining two groups of test data based on the third processing module 300, the fourth processing module 400 can directly save the two groups of test data into the pre-constructed temporary data tables, ensuring that the fifth processing module 500 accurately performs the test data comparison, achieving the purpose of optimizing the interface test comparison. At the same time, since the temporary data table does not need to be manually created, this process can directly compile and run the target code for test case testing, thereby greatly improving the functional test efficiency of language conversion.

[0151] In addition, with reference to Figure 9 , one embodiment of the present application also provides an electronic device, which comprises a memory, a processor and a computer program stored in the memory and executable on the processor.

[0152] The processor and the memory can be connected through a bus or other means.

[0153] The non-transitory software programs and instructions required for implementing the above-described embodiment of the functional test method for translating SQL into a target language are stored in the memory, and when executed by the processor, the functional test method for translating SQL into a target language of the above-described embodiments is executed, for example, the method steps S100 to S600 in the above-described Figure 1 , the method steps S210 to S230 in the above-described Figure 2 , the method steps S310 to S320 in the above-described Figure 4 , the method steps S500 to S600 in the above-described Figure 5 or the method steps S800 in the above-described Figure 6 .

[0154] The device embodiments described above are only schematic, and the units described as separate components can or can not be physically separated, i.e., can be located in one place or distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment.

[0155] Furthermore, one embodiment of this application also provides a computer-readable storage medium storing computer-executable instructions that are executed by a processor or controller, for example, by a processor in the above-described device embodiment, causing the processor to execute the functional testing method for translating SQL into a target language as described above, for example, executing the above-described... Figure 1 Method steps S100 to S600 in the text Figure 2 Method steps S210 to S230 in the text Figure 4 Method steps S310 to S320 in the text Figure 5 Method steps S500 to S600 or Figure 6 The method step S800.

[0156] The above embodiments can be used in combination, and modules with the same name in different embodiments may be the same or different.

[0157] The foregoing has described specific embodiments of this application; other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than those shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily have to follow the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0158] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, devices, and computer-readable storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0159] The apparatus, device, computer-readable storage medium and method provided in the embodiments of this application are corresponding. Therefore, the apparatus, device and non-volatile computer storage medium also have similar beneficial technical effects as the corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the corresponding apparatus, device and computer storage medium will not be described again here.

[0160] In the 1990s, it was fairly easy to distinguish whether an improvement in a technology was a hardware improvement (e.g., an improvement in the circuit structure of a diode, transistor, switch, etc.) or a software improvement (an improvement in a method flow). However, as technology has evolved, many improvements in method flows today can be considered as direct improvements in hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structures by programming the improved method flows into hardware circuits. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using hardware entity modules.

[0161] For example, a programmable logic device (PLD) such as a field programmable gate array (FPGA) is an integrated circuit whose logic function is determined by user programming of the device. A digital system is "integrated" on a PLD by the designer programming it, rather than by asking a chip manufacturer to design and fabricate a custom integrated circuit chip. Moreover, today, instead of manually fabricating integrated circuit chips, this programming is mostly implemented using "logic compiler" software, which is similar to software compilers used in program development, and the original code to be compiled is written in a specific programming language, called a hardware description language (HDL), of which there are many, such as:

[0162] ABEL (Advanced Boolean Expression Language); AHDL (Altera Hardware Description Language); Confluence; CUPL (Cornell University Programming Language); HDCal; and

[0163] JHDL (Java Hardware Description Language); Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc.

[0164] Currently, VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and the language Verilog are more commonly used in the art. It is clear to a person skilled in the art that, in order to implement the hardware circuit for the logic method flow, it is only necessary to make a slight logical programming of the method flow with the above-mentioned hardware description languages and program them into the integrated circuit.

[0165] The controller can be implemented in any suitable manner, for example, the controller can take the form of a microprocessor or processor and a computer readable medium storing computer readable program code (e.g. software or firmware) executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller and an embedded microcontroller, examples of the controller include but are not limited to the following microcontrollers:

[0166] The memory controller can also be implemented as part of the control logic of the memory. It is also clear to a person skilled in the art that, in addition to implementing the controller in the form of pure computer readable program code, the same function can also be implemented by making a logical programming of the method steps in the form of logic gates, switches, an application specific integrated circuit, a programmable logic controller and an embedded microcontroller. Therefore, such a controller can be considered as a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can even be considered as both a software module implementing a method and a structure within a hardware component.

[0167] The system, apparatus, module or unit illustrated in the above embodiments can be specifically implemented by a computer chip or entity, or by a product with certain functions. A typical implementation device is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0168] For the convenience of description, the above apparatus is described in various units by function respectively. Of course, in the implementation of the embodiments of the present application, the functions of each unit can be implemented in the same or more software and / or hardware.

[0169] Those skilled in the art will appreciate that embodiments of the application can be supplied as a method, a system, or a computer program product. Accordingly, embodiments of the application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of the application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, and the like) embodying computer readable program code.

[0170] The specification is presented with reference to flow diagrams and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flow diagrams and / or block diagrams, and combinations of blocks in the flow diagrams and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing element or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flow diagrams and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flow diagram and / or block diagram block or blocks. Figure 1 means for performing each of the functions specified in the flow diagram and / or block diagram block or blocks.

[0171] These computer program instructions can also be stored in a computer- readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the flow diagram and / or block diagram block or blocks. Figure 1 one or more functions specified in the flow diagram and / or block diagram block or blocks. Figure 1 means for performing each of the functions specified in the flow diagram and / or block diagram block or blocks.

[0172] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the flow diagram and / or block diagram block or blocks. Figure 1 one or more functions specified in the flow diagram and / or block diagram block or blocks. Figure 1 means for performing each of the functions specified in the flow diagram and / or block diagram block or blocks.

[0173] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0174] The memory can include non-persistent memory and / or persistent memory, such as flash memory, read-only memory (ROM), and / or random access memory (RAM), among others. The memory is an example of computer-readable media.

[0175] Computer-readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0176] It should also be noted that the terms "comprising", "including", or any other variant thereof are intended to cover non-exclusive inclusion, so that processes, methods, articles or devices including a series of elements not only include those elements, but also include other elements not explicitly listed or inherent to such processes, methods, articles or devices. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of another identical element in the process, method, article or device comprising the element.

[0177] In the embodiments of the present application, "at least one" means one or more, and "multiple" means two or more. The association relationship between the associated objects is described by "and / or", which means that there can be three kinds of relationships, for example, A and / or B, which can represent the cases of A alone, A and B together, and B alone. Wherein A, B can be singular or plural. The character " / " generally represents that the associated objects before and after are in an "or" relationship. "At least one of the following" and the like means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b and c can represent: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, c can be single or multiple.

[0178] Embodiments of the present application can be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and the like, that perform particular tasks or implement particular abstract data types. Embodiments of the present application can also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules can be located in both local and remote computer storage media including memory storage devices.

[0179] Various embodiments in the present application are described in progressive manner, and the same or similar parts between various embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. Especially, the system embodiments are described simply because they are basically similar to the method embodiments, and the relevant parts can be referred to the description of the method embodiments.

[0180] The above only describes the embodiments of the present application and is not intended to limit the present application. The present application can have various modifications and changes for those skilled in the art. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application shall be included in the scope of claims of the present application.

Claims

1. A method of testing the function of translating an sql into a target language, characterized by, The method comprises the following steps: obtaining interface parameters corresponding to the interface to be tested, creating sql interface test code and target language interface test code according to the interface parameters; obtaining a test data source of the interface parameters, and obtaining at least one test case matched with the interface to be tested according to the test data source of the interface parameters; determining the number of all test cases; creating multiple test processes, assigning the same number of test cases to each test process according to the number of test cases, and realizing multi-process parallel testing; for each test case, calling a pre-generated sql test function based on the sql interface test code to obtain first test data, and calling a pre-generated target language test function based on the target language interface test code to obtain second test data; the calling of the pre-generated sql test function based on the sql interface test code to obtain the first test data, and the calling of the pre-generated target language test function based on the target language interface test code to obtain the second test data, comprises: obtaining a sql test interface and a target language test interface corresponding to the interface to be tested according to the interface to be tested; generating the sql test function according to the sql test interface, and generating the target language test function according to the target language test interface; writing the sql test function and the target language test function into a database matched with the interface to be tested; calling the sql test function from the database based on the sql interface test code to obtain first test data, and calling the target language test function from the database based on the target language interface test code to obtain second test data; calling the test function through the configured interface test code to obtain the test data, so as to facilitate the judgment of whether the translated code meets the functional requirements; saving the first test data to a pre-built first temporary data table, and saving the second test data to a pre-built second temporary data table; generating a functional test result of the test case according to the first temporary data table and the second temporary data table.

2. The functional test method of claim 1, wherein, The obtaining of at least one test case matched with the interface to be tested according to the test data source of the interface parameters comprises: obtaining all test data sets corresponding to the interface to be tested according to the test data source of the interface parameters, wherein each test data set comprises at least one test data; obtaining the Cartesian product of any two test data sets, and obtaining at least one test case matched with the interface to be tested according to all Cartesian products.

3. The functional test method of claim 1, wherein, The first temporary data table and the second temporary data table are generated based on the following steps: generating a temporary table creation statement according to the interface to be tested; writing the temporary table creation statement into the database, so that the database generates the first temporary data table and the second temporary data table according to the temporary table creation statement.

4. The functional test method of claim 1, wherein, After generating the functional test result of the test case according to the first temporary data table and the second temporary data table, the method further comprises: Roll back the first test data in the first temporary data table, and roll back the second test data in the second temporary data table, to obtain initial data corresponding to the interface to be tested.

5. The functional test method according to any one of claims 1 to 4, characterized in that, The function test result of the test case comprises at least one of the following types: The number information of the interface to be tested; The number information of the test case; The test information corresponding to each test case; The calling time consumption information of the sql test function; The calling time consumption information of the target language test function; The generation time consumption information of the first test data; The generation time consumption information of the second test data.

6. A functional test apparatus for translating an sql into a target language, characterized by, Comprise: A first processing module configured to obtain interface parameters corresponding to an interface to be tested, and create sql interface test code and target language interface test code according to the interface parameters; A second processing module configured to obtain a test data source of the interface parameters, obtain at least one test case matched with the interface to be tested according to the test data source of the interface parameters, and determine the number of all test cases; Create a plurality of test processes, and assign the same number of test cases to each test process according to the number of test cases to realize multi-process parallel testing; A third processing module configured to, for each test case, call a pre-generated sql test function based on the sql interface test code to obtain first test data, and call a pre-generated target language test function based on the target language interface test code to obtain second test data; the calling of the pre-generated sql test function based on the sql interface test code to obtain the first test data, and the calling of the pre-generated target language test function based on the target language interface test code to obtain the second test data, comprises: obtaining a sql test interface and a target language test interface corresponding to the interface to be tested according to the interface to be tested; generating the sql test function according to the sql test interface, and generating the target language test function according to the target language test interface; writing the sql test function and the target language test function into a database matched with the interface to be tested; calling the sql test function from the database based on the sql interface test code to obtain first test data, and calling the target language test function from the database based on the target language interface test code to obtain second test data; calling test functions respectively through configured interface test code to obtain test data, so as to facilitate judging whether the translated code meets the functional requirements; A fourth processing module configured to save the first test data to a pre-constructed first temporary data table, and save the second test data to a pre-constructed second temporary data table; A fifth processing module configured to generate a function test result of the test case according to the first temporary data table and the second temporary data table.

7. An electronic device comprising: The memory, the processor and the computer program stored in the memory and capable of running on the processor, wherein the processor implements the function test method for translating SQL into a target language according to any one of claims 1 to 5 when executing the computer program. 8.A computer readable storage medium storing computer executable instructions for performing the function test method for translating SQL into a target language according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data interface test method and device, server and storage medium

    CN111949524A

  • Interface test method and device and computer readable storage medium

    CN112597052A