Unit test method and device for database access component and storage medium

By constructing inheritance instances of empty execution components and combining them for processing, the problem of low efficiency of database access component unit testing in the prior art is solved, and efficient database access component testing is achieved.

CN118626397APending Publication Date: 2024-09-10CCB FINTECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410973559.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

The existing unit testing method based on Spring-test results in low unit testing efficiency of database access components and reduces the testing efficiency of database access components.

Method used

By constructing an inheritance instance of the empty execution component for connecting to the database, and combining the constructed inheritance instances and execution scripts according to the instance type of each inheritance instance, a combined instance for executing database operations is obtained. Based on the to-be-tested The database access component executes the combined instance, and performs verification processing on the obtained execution results and the received execution scripts.

Benefits of technology

It improves the efficiency of unit testing of database access components and avoids the Spring container loading process, thus significantly improving the efficiency and accuracy of testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626397A
    Figure CN118626397A
Patent Text Reader

Abstract

The invention provides a unit testing method and device for a database access component and a storage medium, and relates to the field of big data. The method comprises the following steps: responding to a database access request based on a target component, and calling a preset structured query language (SQL) execution file; obtaining an execution script corresponding to the database access request; based on the instance type of each inheriting instance, performing combination processing on each inheriting instance and the execution script to obtain a combined instance corresponding to each inheriting instance; based on the target component, executing the combined instance to obtain an execution result; and performing verification processing on the execution result to obtain a first verification result. According to the method, the unit testing efficiency of the database access component is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of big data, and in particular to a unit testing method, device and storage medium for a database access component. Background Art

[0002] When accessing the database, you need to use database access components, such as the persistence layer framework Mybatis. Therefore, you need to test the database access components to ensure normal database access.

[0003] In the prior art, a spring-test plug-in is used to load a Spring container in a test framework, and through the Spring container, relevant components in a database access component Mybatis to be tested are assembled to implement unit testing of Mybatis.

[0004] However, in the above method, the unit testing method based on Spring-test has low efficiency in the Spring container loading process, which in turn reduces the unit testing efficiency of the database access component. Summary of the invention

[0005] The present application provides a unit testing method, device and storage medium for a database access component, which are used to solve the technical problem that a unit testing method based on Spring-test reduces the unit testing efficiency of database access components.

[0006] In a first aspect, the present application provides a unit testing method for a database access component, the method comprising:

[0007] Based on the target component, responding to the database access request, and calling a preset structured query language execution file; wherein the target component is the database access component to be tested; the execution file includes at least one inheritance instance, the inheritance instance is an inheritance instance of an empty execution component for connecting to a database; the inheritance instance has an instance type;

[0008] Obtaining an execution script corresponding to the database access request; and combining each inheritance instance and the execution script based on the instance type of each inheritance instance to obtain a combination instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; and the combination instance is used to execute database operations;

[0009] Based on the target component, executing the combination instance to obtain an execution result; wherein the execution result includes preset test data;

[0010] The execution result is verified to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

[0011] In a second aspect, the present application provides a unit testing device for a database access component, the device comprising:

[0012] A calling module, for responding to a database access request based on a target component and calling a preset structured query language execution file; wherein the target component is a database access component to be tested; the execution file includes at least one inheritance instance, the inheritance instance is an inheritance instance of an empty execution component for connecting to a database; the inheritance instance has an instance type;

[0013] A combination module, used to obtain an execution script corresponding to the database access request; and based on the instance type of each inheritance instance, combine each inheritance instance and the execution script to obtain a combination instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; the combination instance is used to execute database operations;

[0014] An execution module, used to execute the combination instance based on the target component to obtain an execution result; wherein the execution result includes preset test data;

[0015] The verification module is used to verify the execution result to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

[0016] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0017] The memory stores computer-executable instructions;

[0018] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect.

[0019] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.

[0020] In a fifth aspect, the present application provides a computer program product, the computer program product comprising: a computer program, and when the computer program is executed by a processor, it is used to implement the method described in the first aspect.

[0021] The unit testing method, device and storage medium of the database access component provided by the present application construct an inheritance instance of an empty execution component for connecting to a database, and combine the constructed inheritance instances and execution scripts according to the instance type of each inheritance instance to obtain a combined instance for executing database operations. The combined instance is executed based on the database access component to be tested, and the obtained execution result and the received execution script are verified, thereby improving the unit testing efficiency of the database access component. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0023] Figure 1 A schematic diagram of an application scenario provided for this application;

[0024] Figure 2 A schematic diagram of a unit testing method for a database access component provided in an embodiment of the present application;

[0025] Figure 3 A flowchart of another unit testing method for a database access component provided in an embodiment of the present application;

[0026] Figure 4 A flowchart of a unit testing method for a database access component provided in an embodiment of the present application;

[0027] Figure 5 A schematic diagram of the structure of a unit testing device for a database access component provided in an embodiment of the present application;

[0028] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0029] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0030] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0031] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data involved shall comply with the provisions of relevant laws and regulations and shall not violate public order and good morals.

[0032] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0033] It should be noted that the unit testing method, device and storage medium of the database access component of the present application can be used in the field of big data, and can also be used in any field other than big data. The application field of the unit testing method, device and storage medium of the database access component of the present application is not limited.

[0034] When accessing the database, you need to use database access components, such as the persistence layer framework Mybatis. Therefore, you need to test the database access components to ensure normal database access.

[0035] In one example, based on the use of Spring plug-in, the Spring container is loaded in the test framework, and the relevant components in the database access component Mybatis to be tested are assembled through the Spring container. In addition, the unit test of Mybatis is implemented by combining the in-memory database and test data such as Structured Query Language (SQL) scripts.

[0036] However, in the above method, based on the Spring unit test method, the Spring container loading process is inefficient, thereby reducing the unit test efficiency of the database access component.

[0037] In view of the above technical problems, the present application proposes the following technical concept: by constructing an inheritance instance of an empty execution component for connecting to a database, and combining the constructed inheritance instances and execution scripts according to the instance type of each inheritance instance, a combination instance for executing database operations is obtained, and based on the database access component to be tested, the combination instance is executed, and the obtained execution result and the received execution script are verified. In this way, the problem that the Spring-based unit test method in the prior art reduces the unit test efficiency of the database access component can be solved.

[0038] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0039] Figure 1 A schematic diagram of an application scenario provided by this application. Figure 1 As shown, the specific application scenario of the present application includes an electronic device 101 and a user 102. The user 102 can test the database access component Mybatis to be tested deployed in the electronic device 101 through the electronic device 101.

[0040] Figure 2 A flowchart of a unit testing method for a database access component provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method includes:

[0041] 201. Based on the target component, respond to the database access request and call the preset structured query language SQL execution file; wherein the target component is the database access component to be tested; the SQL execution file includes at least one inheritance instance, which is an inheritance instance of an empty execution component used to connect to the database; the inheritance instance has an instance type.

[0042] Exemplarily, the execution subject of this embodiment can be an electronic device, hereinafter referred to as the device, which is a physical device or a virtual device for unit testing of database access components. The device pre-deploys the basic framework for SQL execution, the Mybatis native running framework, and the Mybatis test execution framework; first, based on the SQL execution basic framework initialization and data preparation, that is, constructing an inheritance instance of an empty execution component for connecting to the database, storing it in a preset structured query language SQL execution file, responding to the database access request based on the database access component to be tested, that is, the target component, and calling the inheritance instance in the preset SQL execution file for processing.

[0043] For example, based on the basic framework of SQL execution, it is necessary to build inheritance instances of four major components: empty database connection object EmptyConnection, empty prepared statement object EmptyPreparedStatement, empty ordinary statement object EmptyStatement, and empty result set object EmptyResultSet, to support the execution of mybatis in unit testing, that is, to be called by Mybatis during the execution of Mybatis tests to provide the return value required by the target, and to provide the basic framework for the simulation environment of misoperation. And as a basic type, it simplifies the implementation process of non-essential methods for the subsequent inheritance types to achieve functional coverage; taking the simplest user query case as an example, we define the entity object Person, which contains three attributes: id, name, and age, and define a MockedResultSet. We can also simulate the implementation of ResultSet through preset simulation methods. The getMetaData() method of the above ResultSet needs to return a specific implementation of SetMetaData, and use the specific type of ResultSetMetaData as the return instance. At the same time, construct MockedStatement, MockedPreparedStatement, and MockedConnection instance types to combine and implement the SQL execution instance of this unit test. Obviously, this can be completed either by the actual type or by simulating the basic operation logic through the preset simulation method.

[0044] 202. Obtain an execution script corresponding to a database access request; and based on the instance type of each inheritance instance, combine each inheritance instance and the execution script to obtain a combined instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; the combined instance is used to execute database operations.

[0045] Exemplarily, the device can run the logic of the basic framework of SQL execution, intercept the execution script corresponding to the database access request, which includes SQL statements and parameters; and combine each inheritance instance and the execution script according to the instance type of each inheritance instance, so as to obtain a combined instance for executing database operations, that is, the execution code corresponding to the target database operation.

[0046] 203. Based on the target component, execute the combination instance to obtain an execution result; wherein the execution result includes preset test data.

[0047] Exemplarily, it is assumed that based on the target component Mybatis, a request execution process is performed, that is, the combined instance is executed and processed to obtain an execution result; wherein the execution result includes preset test data, such as an output return value that meets the target result requirements, deleted data, or added data.

[0048] 204. Verify the execution result to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

[0049] Exemplarily, the device performs verification processing on the data in the execution result according to the obtained execution result and based on the preset verification logic, and obtains a verification result representing the correctness of the execution result, i.e., a first verification result, and the unit test process of the target component Mybatis has been completed.

[0050] In the present embodiment, a unit testing method for a database access component is provided, wherein an inheritance instance of an empty execution component for connecting to a database is constructed, and the constructed inheritance instances and execution scripts are combined according to the instance type of each inheritance instance to obtain a combined instance for executing database operations. The combined instance is executed based on the database access component to be tested, and the obtained execution result and the received execution script are verified; thereby, the unit testing efficiency of the database access component can be improved.

[0051] Figure 3 A flow chart of another unit testing method for a database access component provided in an embodiment of the present application is shown as follows: Figure 3 As shown, the method includes:

[0052] 301. Based on the target component, respond to the database access request and call the preset structured query language SQL execution file; wherein the target component is the database access component to be tested; the SQL execution file includes at least one inheritance instance, which is an inheritance instance of an empty execution component used to connect to the database; the inheritance instance has an instance type.

[0053] Exemplarily, this step may refer to step 201 and will not be described in detail here.

[0054] 302. Obtain an execution script corresponding to a database access request; and based on the instance type of each inheritance instance, combine each inheritance instance and the execution script to obtain a combined instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; the combined instance is used to execute database operations.

[0055] Exemplarily, this step may refer to step 202 and will not be described in detail here.

[0056] 303. Obtain a session component in the target component, and based on the session component, obtain a query type instance in the target component.

[0057] Exemplarily, after the device completes the definition of the basic operating framework, it is necessary to implement the definition and initialization of the Mybatis native operating framework, define the Mybatis query type instance of PersonMapper, such as defining the PersonselectById(long id) method in PersonMapper, or through the Mybatis-plus plug-in or the method query statement definition based on the xml format, to complete the instantiation of the runtime type of the above interface; based on the Mybatis native operating framework, based on the basic framework of Mybatis, without relying on Spring-mybatis, implement the configuration implementation of the core object Configuration and the session component SqlSessionFactory, obtain the session component in the target component, and based on the session component, according to the dynamic instantiation access of the Mapper type implemented by relying on SqlSession, obtain the query type instance in the pre-defined target component Mybatis.

[0058] In one example, obtaining the session component in the target component in step 303 includes the following steps:

[0059] The first step is to construct a core object of the target component based on the target component; wherein the core object is used to store configuration data for accessing a database in the target component.

[0060] The second step is to create a session component of the target component based on the core object.

[0061] Exemplarily, the device builds the Mapper test execution runtime session environment management logic based on the Mybatis basic instance, first creates a non-configured SqlSessionFactory, that is, a core object, to store configuration data for accessing the database in the target component, and creates a SqlSession environment; and creates a SqlSession, that is, a session component, based on the SqlSessionFactory and the SqlSession environment.

[0062] 304. Based on the target component, execute the query type instance and the combination instance to obtain an execution result.

[0063] Exemplarily, the device executes the code in the query type instance and the combination instance based on the target component Mybatis to obtain the execution result; for example, if it is a query method, the query code corresponding to the query type instance and the combination instance is executed, and the query code is executed, that is, it is used to support Mybatis to perform dynamic proxy generation and execution of Mapper query type instances in a non-Spring environment to generate an output return value that meets the target result requirements. Furthermore, the container loading process of Spring is not required, and the execution of a single test case has significant efficiency.

[0064] In one example, step 304 includes the following steps:

[0065] The first step is to execute the combination instance based on the target component to obtain output data.

[0066] The second step is to execute the query type instance to map the output data and obtain the execution result.

[0067] Exemplarily, the device calls and executes the code in the combined instance based on the target component Mybatis, and provides the return value required by the target, that is, the output data. For example, the specific implementation of MetaData must at least set the definition of specific three-column range values: including the following definition form, with three attributes of serial number, name, and type for correlation definition and attribute setting of the total number of columns. When Mybatis calls ResultSet, it will be read and used to further read column data, such as by imitating the behavior of ResultSet under next and getXXX operations to implement the return value operation. After obtaining the return value required by the target, the device executes this method according to the mapping method corresponding to the query type instance to map the output data and obtain an output return value that meets the target result requirements, that is, the execution result.

[0068] In one example, the combination instance includes a result inheritance instance, and the result inheritance instance has a data list; step 304 also includes: storing the output data in the data list in the result inheritance instance; wherein the output data in the data list has an index value.

[0069] Exemplarily, the obtained combined instance includes an inheritance instance of an empty result set component, namely, a result inheritance instance MockedResultSet, which has a data list, and the device stores the obtained output data in the data list of the result inheritance instance; a list list is placed inside the MockedResultSet to store the target data instance, and an index value index is set to determine the start and end of the output data reading. Furthermore, the obtained target return value is mapped by executing the query instance, and the obtained output data is stored for subsequent verification of the correctness of the unit test execution, which greatly reduces the problem of slow unit test execution.

[0070] 305. Verify the execution result to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

[0071] Exemplarily, this step may refer to step 204 and will not be described in detail here.

[0072] 306. Verify the execution script to obtain a second verification result; wherein the second result indicates the correctness of the execution script.

[0073] Exemplarily, the device captures the verification logic of the SQL statements and parameters output by Mybatis based on the basic running framework, such as SQL text data verification based on native implementation, or further syntax-level verification and further business semantic verification of SQL statements based on SQL tools, and verifies the SQL statements and parameters in the obtained execution script to obtain a second verification result to characterize the correctness of the execution script; furthermore, the logical verification of the SQL grammar for a specific database can be more accurately verified, thereby improving the accuracy of the Mybatis unit test.

[0074] In one example, step 306 includes the following steps:

[0075] The first step is to determine the acquisition information of the execution script; wherein the acquisition information represents the interception acquisition method of the SQL statements and parameters in the execution script.

[0076] The second step is to verify the execution script according to the acquired information to obtain a second verification result.

[0077] Exemplarily, the device captures and verifies the parameter interception method based on a preset simulation method, determines the acquisition information of the execution script obtained, and the acquisition information represents the interception and acquisition method of SQL statements and parameters in the execution script; based on the acquisition information of the execution script, verifies the execution script to obtain the verification result of the execution script.

[0078] In one example, the combination instance includes a result inheritance instance; step 306 includes the following steps:

[0079] The first step is to execute the result inheritance instance to obtain a legal return value.

[0080] The second step is to verify the execution script according to the legal return value to obtain a second verification result.

[0081] Exemplarily, the combined instance includes an inheritance instance of a result set component, i.e., a result inheritance instance. Based on the target component Mybatis, the result inheritance instance is called and executed, and a legal return value can be returned to verify the correctness of Mybatis at the result processing level, i.e., the obtained execution script is verified based on the legal return value to obtain a verification result of the execution script.

[0082] 307. Generate a code generation template according to the target component; wherein the code generation template is used to generate execution code.

[0083] Exemplarily, based on the basic framework of SQL execution in the target component, the Mybatis native running framework, the Mybatis test execution framework, and the data organization method, which have obvious structured characteristics and repeatability characteristics, the device establishes a java code generation template for a specific entity type and a specific business type based on the target component through conventional descriptive languages ​​such as json and xml and corresponding interpreters, and forms a valid Java code file based on the template and input data.

[0084] In this embodiment, a valid Java code file is generated based on a simulation SQL execution component, a formalized process and a verification method of a specific standard and a code generation technology based on a template method.

[0085] The following is a detailed description of the execution verification process of the script execution through some specific examples:

[0086] Figure 4 A flowchart of a unit testing method for a database access component provided in an embodiment of the present application is shown as follows: Figure 4 As shown, the method comprises the following steps:

[0087] 401. Based on the target component, respond to the database access request and call a preset structured query language execution file.

[0088] 402. Obtain an execution script corresponding to the database access request; and based on the instance type of each inheritance instance, combine each inheritance instance and the execution script to obtain a combination instance corresponding to each inheritance instance.

[0089] 403. Obtain a session component in the target component, and based on the session component, obtain a query type instance in the target component.

[0090] 404. Based on the target component, execute the combination instance to obtain output data.

[0091] 405. Execute the query type instance to map the output data and obtain an execution result.

[0092] 406. Verify the execution result to obtain a first verification result.

[0093] 407. Determine the interception and acquisition method of SQL statements and parameters in the execution script.

[0094] 408. Verify the execution script according to the interception and acquisition method of the SQL statement and parameters in the execution script to obtain a second verification result.

[0095] In this embodiment, the container loading process of Spring is not required, and the execution of a single test case has significant efficiency; and the capture and verification logic of the parameter interception method is used to improve the accuracy of the unit test based on the database access component.

[0096] Figure 5 A schematic diagram of the structure of a unit test device for a database access component provided in an embodiment of the present application, such as Figure 5 As shown, the device comprises:

[0097] The calling module 501 is used to respond to the database access request based on the target component and call the preset structured query language execution file; wherein the target component is the database access component to be tested; the execution file includes at least one inheritance instance, and the inheritance instance is an inheritance instance of an empty execution component used to connect to the database; the inheritance instance has an instance type;

[0098] The combination module 502 is used to obtain the execution script corresponding to the database access request; and based on the instance type of each inheritance instance, each inheritance instance and the execution script are combined to obtain a combination instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; the combination instance is used to execute database operations;

[0099] An execution module 503 is used to execute the combination instance based on the target component to obtain an execution result; wherein the execution result includes preset test data;

[0100] The verification module 504 is used to verify the execution result to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

[0101] In one example, the execution module 503 is specifically used to: obtain a session component in a target component, and based on the session component, obtain a query type instance in the target component; based on the target component, execute the query type instance and the combination instance to obtain an execution result.

[0102] In one example, the execution module 503 is further specifically used to: execute the combination instance based on the target component to obtain output data; execute the query type instance to map the output data to obtain the execution result.

[0103] In one example, the combination instance includes a result inheritance instance, and the result inheritance instance has a data list; the execution module 503 is further specifically used to: store the output data in the data list in the result inheritance instance; wherein the output data in the data list has an index value.

[0104] In one example, the execution module 503 is further specifically used to: construct a core object of the target component based on the target component; wherein the core object is used to store configuration data for accessing a database in the target component; and create a session component of the target component according to the core object.

[0105] In one example, the device is also used to: verify the execution script to obtain a second verification result; wherein the second result represents the correctness of the execution script.

[0106] In one example, the device is also specifically used to: determine acquisition information of the execution script; wherein the acquisition information represents the interception acquisition method of SQL statements and parameters in the execution script; based on the acquisition information, verify the execution script to obtain a second verification result.

[0107] In one example, the device is also specifically used to: execute the result inheritance instance to obtain a legal return value; and verify the execution script according to the legal return value to obtain a second verification result.

[0108] In one example, the device is also used to: generate a code generation template according to the target component; wherein the code generation template is used to generate execution code.

[0109] The device of this embodiment can execute the technical solution in the above method. Its specific implementation process and technical principles are the same and will not be repeated here.

[0110] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. Each module can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The functions of each module. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0111] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the electronic device includes: a memory 601, a processor 602; the memory 601; and a memory for storing instructions executable by the processor 602.

[0112] The processor 602 is configured to execute the method provided in the above embodiment.

[0113] The electronic device further includes a receiver 603 and a transmitter 604. The receiver 603 is used to receive instructions and data sent by other devices, and the transmitter 604 is used to send instructions and data to external devices.

[0114] An embodiment of the present application also provides a chip for running instructions, which is used to execute the technical solutions in the above embodiments.

[0115] An embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution in the above embodiment.

[0116] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, the technical solution in the above embodiments can be implemented.

[0117] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0118] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.

[0119] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.

[0120] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0121] It should be understood that the above processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the invention can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.

[0122] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.

[0123] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of this application is not limited to only one bus or one type of bus.

[0124] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0125] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0126] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0127] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A unit testing method for a database access component, characterized in that: The method comprises: Based on the target component, responding to the database access request, and calling a preset structured query language execution file; wherein the target component is the database access component to be tested; the execution file includes at least one inheritance instance, the inheritance instance is an inheritance instance of an empty execution component for connecting to the database; the inheritance instance has an instance type; Obtaining an execution script corresponding to the database access request; and combining each inheritance instance and the execution script based on the instance type of each inheritance instance to obtain a combination instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; and the combination instance is used to execute database operations; Based on the target component, executing the combination instance to obtain an execution result; wherein the execution result includes preset test data; The execution result is verified to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

2. The method according to claim 1, characterized in that Based on the target component, executing the combination instance to obtain an execution result includes: Acquire a session component in the target component, and based on the session component, acquire a query type instance in the target component; Based on the target component, the query type instance and the combination instance are executed to obtain the execution result.

3. The method according to claim 2, characterized in that Based on the target component, executing the query type instance and the combination instance to obtain an execution result, including: Based on the target component, executing the combination instance to obtain output data; The query type instance is executed to perform mapping processing on the output data to obtain the execution result.

4. The method according to claim 3, characterized in that The combination instance includes a result inheritance instance, and the result inheritance instance has a data list; and further includes: The output data is stored in a data list in the result inheritance instance; wherein the output data in the data list has an index value.

5. The method according to claim 2, characterized in that: Obtaining a session component in the target component includes: Based on the target component, construct a core object of the target component; wherein the core object is used to store configuration data used to access a database in the target component; Based on the core object, a session component of the target component is created.

6. The method according to claim 1, characterized in that The method further comprises: The execution script is verified to obtain a second verification result; wherein the second result represents the correctness of the execution script.

7. The method according to claim 6, characterized in that The execution script is verified to obtain a second verification result, including: Determine the acquisition information of the execution script; wherein the acquisition information represents the interception acquisition method of SQL statements and parameters in the execution script; The execution script is verified according to the acquired information to obtain the second verification result.

8. The method according to claim 6, characterized in that The combination instance includes a result inheritance instance; the method further includes: Execute the result inheritance instance to obtain a legal return value; The execution script is verified according to the legal return value to obtain the second verification result.

9. The method according to any one of claims 1 to 8, characterized in that The method further comprises: A code generation template is generated according to the target component; wherein the code generation template is used to generate execution code.

10. A unit testing device for a database access component, characterized in that: The device comprises: A calling module, for responding to a database access request based on a target component and calling a preset structured query language execution file; wherein the target component is a database access component to be tested; the execution file includes at least one inheritance instance, the inheritance instance is an inheritance instance of an empty execution component for connecting to a database; the inheritance instance has an instance type; A combination module, used to obtain an execution script corresponding to the database access request; and based on the instance type of each inheritance instance, combine each inheritance instance and the execution script to obtain a combination instance corresponding to each inheritance instance; wherein the execution script includes SQL statements and parameters; the combination instance is used to execute database operations; An execution module, used to execute the combination instance based on the target component to obtain an execution result; wherein the execution result includes preset test data; The verification module is used to verify the execution result to obtain a first verification result; wherein the first verification result represents the correctness of the execution result.

11. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 9 when executed by a processor.

13. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 9 when being executed by a processor.