Database application programming interface testing method and system and medium
By encapsulating the database API interface and writing black box test cases, the problem of low testing efficiency of API interfaces in the existing technology is solved, and a simplified test process and efficient test results are achieved.
Patent Information
- Application Number
- CN202411180523.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-12-27
AI Technical Summary
In the prior art, the testing efficiency of the underlying API interface of the database is low, the writing efficiency of test cases is difficult, the writing efficiency is low, and the operation is complicated, resulting in low testing efficiency.
By encapsulating the API interface of the database to be tested, a simplified target API interface is generated, a black box test case is written based on this interface, and a link is established with the database through the use case manager, and a test case is executed to obtain test results, supporting batch testing.
Improves test case writing efficiency and API interface testing efficiency, simplifies the testing process, and reduces the testing complexity.
Smart Images

Figure CN119201685A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of database detection, and in particular to a database application programming interface testing method, system and medium. Background Art
[0002] With the deepening and accelerated advancement of digital transformation in various industries, Application Programming Interface (API) has become a crucial part of the database system development process as the cornerstone for expanding database business functions and connecting various systems and services. Currently, most of the common API interface testing tools are interface tests based on network protocols. There are very few tools for API interface testing in C or C++. The most commonly used one is the C++ test framework GTest, which requires the use of the Visual Studio Code code editor to write test cases. With the help of the CMake compilation tool, the test cases are compiled and executed by executing cmd commands or executing script files in the terminal. At the same time, manual confirmation of the test case execution results is required. This test method is difficult to write test cases, has low writing efficiency, and the test steps are complicated to operate, which leads to low testing efficiency.
[0003] Therefore, there is an urgent need for a database application programming interface testing method to solve the problem of low testing efficiency when testing the underlying API interface in the existing technology. Summary of the Invention
[0004] In view of this, the present invention provides a database application programming interface testing method, system and medium, the main purpose of which is to solve the problem of low testing efficiency when testing the underlying database API interface.
[0005] To solve the above problems, the present application provides a database application programming interface testing method, comprising:
[0006] Encapsulate each application programming interface (API) to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested;
[0007] In response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a black box test case corresponding to each API interface to be tested is obtained;
[0008] Establishing links with the database to be tested based on the configuration information of the database in each black box test case, and calling each API interface to be tested to execute the corresponding black box test case;
[0009] Target execution information of each of the API interfaces to be tested when executing the test case is obtained, so as to obtain test results of each of the API interfaces to be tested based on the target execution information.
[0010] Optionally, before responding to the user's operation of writing a test case based on each of the target API interfaces and the configuration information of the database to be tested, the method further includes:
[0011] Obtain the configuration information of the database to be tested and store the configuration information in a preset location according to the preset format of the use case file. The configuration information includes any one or more of the following: database IP address information, database account name, password information, database startup port information, database version information, database operating system name information, maximum number of online users and maximum number of threads.
[0012] Optionally, encapsulating each application programming interface (API) to be tested in the database to be tested to obtain the encapsulated target API interface corresponding to each API interface to be tested specifically includes:
[0013] Responding to a test case writing request, obtaining identification information of each API interface to be tested in the database to be tested from the test case writing request;
[0014] Determine the interface type of the API interface to be tested based on the flag information of the API interface to be tested; the interface type includes any one of a multi-combination parameter type, a single parameter type, a multi-function type, and a single function type;
[0015] When the interface type is a multi-combination parameter type or a multi-function type, the API interface to be tested is encapsulated to obtain a target API interface of a single parameter type or a single function type.
[0016] Optionally, the responding user obtains a black box test case corresponding to each of the target API interfaces and the configuration information of the database to be tested, and performs a test case writing operation, specifically including:
[0017] In response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a use case file of a black box test case corresponding to each API interface to be tested is obtained;
[0018] Analyzing and processing each of the use case files to obtain key information, and generating a code file in a predetermined programming language corresponding to the use case file based on each of the key information;
[0019] The code files are compiled respectively using a predetermined compilation tool to obtain executable files corresponding to the code files, so as to obtain black box test cases.
[0020] Optionally, after obtaining each black box test case, the method further includes:
[0021] Create reference execution files that have been successfully tested and correspond to each black box test case in advance;
[0022] The obtaining of the test results of each of the API interfaces to be tested based on the target execution information specifically includes:
[0023] Compare the target execution information corresponding to the same black box test case with the reference execution information in the corresponding reference execution file to obtain a comparison result;
[0024] Based on the comparison result, it is determined whether the API interface to be tested passes or fails the test to obtain a test result.
[0025] Optionally, when the test result of the API interface to be tested is a test failure, the method further includes:
[0026] The target API interface corresponding to the API interface under test that failed the test is used as a gray box test case for the API interface under test;
[0027] Perform grey box testing on the API interface to be tested that failed the test based on the grey box test case to obtain a test result.
[0028] Optionally, the method further includes: storing each black box test case and / or gray box test case according to a predetermined storage method.
[0029] Optionally, after obtaining the test results of each API interface to be tested, the method further includes: generating a test report based on each test result.
[0030] To solve the above problems, the present application provides a database application programming interface testing system, comprising:
[0031] The database API interface encapsulator is used to encapsulate each application programming interface API to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested;
[0032] The use case manager is configured to obtain a black box test case corresponding to each of the target API interfaces and the configuration information of the database to be tested in response to the user's operation of writing the test case based on the target API interface and the configuration information of the database to be tested;
[0033] The use case manager is further configured to establish a link with the database to be tested based on the configuration information of the database in each black box test case, and call each API interface to be tested to execute the corresponding black box test case;
[0034] The use case manager is further configured to obtain target execution information when each of the API interfaces to be tested executes the test case, so as to obtain test results of each of the API interfaces to be tested based on the target execution information.
[0035] To solve the above problems, the present application provides a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned database application programming interface testing methods are implemented.
[0036] To solve the above problems, the present application provides an electronic device, which includes at least a memory and a processor, wherein a computer program is stored on the memory, and the processor implements the steps of any of the above-mentioned database application programming interface testing methods when executing the computer program on the memory.
[0037] The database application programming interface testing method, system, and medium in this application can provide a simplified API interface for black box test cases by encapsulating the underlying API interface, that is, encapsulating the database API interface with multiple combination parameters and the API interface with complex logical functions. This allows testers to quickly and concisely write black box test cases based on the simplified target API interface, thereby improving the efficiency of writing test cases and thus improving the efficiency of testing API interfaces. At the same time, by creating black box test cases corresponding to each API interface to be tested, this application can subsequently perform batch testing on each API interface to be tested based on each black box test case, further improving testing efficiency.
[0038] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0040] Figure 1 This is a flowchart of a database application programming interface testing method according to an embodiment of the present application;
[0041] Figure 2 This is a structural block diagram of a database application programming interface testing system according to another embodiment of the present application;
[0042] Figure 3 This is a structural block diagram of an electronic device according to another embodiment of the present application. DETAILED DESCRIPTION
[0043] Various aspects and features of the present application are described herein with reference to the accompanying drawings.
[0044] It should be understood that various modifications may be made to the embodiments of the present application. Therefore, the above description should not be considered as limiting, but merely as an example of an embodiment. Other modifications within the scope and spirit of the present application will occur to those skilled in the art.
[0045] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present application and, together with the general description of the present application given above and the detailed description of the embodiments given below, serve to explain the principles of the present application.
[0046] These and other characteristics of the present application will become apparent from the following description of a preferred form of embodiment given as a non-limiting example with reference to the accompanying drawings.
[0047] It should also be understood that although the present application has been described with reference to certain specific examples, those skilled in the art will readily be able to implement many other equivalent forms of the present application.
[0048] The above and other aspects, features and advantages of the present application will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings.
[0049] Specific embodiments of the present application will be described hereinafter with reference to the accompanying drawings; however, it should be understood that the embodiments described are merely examples of the present application and may be implemented in a variety of ways. Familiar and / or repetitive functions and structures are not described in detail to avoid obscuring the present application with unnecessary or redundant details. Therefore, the specific structural and functional details described herein are not intended to be limiting, but rather serve merely as a basis and representative basis for the claims to teach those skilled in the art to variously utilize the present application with substantially any suitable detailed structure.
[0050] This specification may use the phrases "in one embodiment," "in another embodiment," "in a further embodiment," or "in other embodiments," which may all refer to one or more of the same or different embodiments according to the present application.
[0051] The present application embodiment provides a database application programming interface testing method, which can be applied to electronic devices such as terminals and servers, such as Figure 1 As shown, the method in this embodiment includes the following steps:
[0052] Step S101, encapsulating each application programming interface (API) to be tested in the database to be tested, and obtaining the encapsulated target API interface corresponding to each API interface to be tested;
[0053] In this step, since the database underlying API interface / API interface to be tested may be a combination of multiple API interface functions or logical function interface functions, this type of API interface can be encapsulated to obtain a target API interface of a single parameter type or a single function type, that is, a simplified target API interface, which lays the foundation for the subsequent rapid writing of black box test cases based on the simplified target API interface.
[0054] During the specific implementation of this step, the user can input / write the identification information of the database to be tested and the identification information of the underlying API interface to be tested in the database to be tested in the predetermined interactive interface, thereby generating a test case writing request, and then the back-end server / electronic device can call the predetermined encapsulation method / API interface encapsulator according to the writing request to directly encapsulate the corresponding underlying API interface, thereby obtaining a simplified / encapsulated target API interface.
[0055] Step S102, in response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, obtaining a black box test case corresponding to each API interface to be tested;
[0056] In this step, the user can write a black box test case for the corresponding API interface to be tested based on the target API interface and the configuration information of the database to be tested in the predetermined interactive interface. Specifically, the electronic device or server can respond to the user's parameter input operation or test statement input operation for the target API interface in the predetermined interactive interface to obtain the target parameters and / or target test statements, and then generate a black box test case based on the target parameters and / or target test statements. That is, the user completes the writing of the black box test case by inputting the target parameters and / or target test statements according to the target API interface in the predetermined interactive interface. In this embodiment, the target API interface is a simplified interface provided by the database API interface encapsulator for black box testing, and is also a gray box test case for the database's underlying API interface / API interface to be tested.
[0057] In this embodiment, when the underlying API interface to be tested is a simple database API interface (that is, the type of the underlying API interface to be tested is a single parameter type or a single function type), the user can directly write the gray box test code of the API interface in the predetermined interactive interface.
[0058] Step S103: establishing links with the database to be tested based on the configuration information of the database in each black box test case, and calling each API interface to be tested to execute the corresponding black box test case;
[0059] During the specific implementation of this step, the executable file of the black box test case can be executed by calling the cmd command. Specifically, a link can be established with the database to be tested based on the database configuration information in the black box test case, and then the API interface to be tested can be called to execute the black box test case. During the execution process, the target execution information of the API interface to be tested can be collected, including any one or more of the API interface return value, API interface execution time, and SQL statement retrieval results, thereby obtaining the target execution information. This lays the foundation for the subsequent rapid determination of the test results of the API interface to be tested based on the target execution information.
[0060] Step S104 , obtaining target execution information when each of the API interfaces to be tested executes the test case, so as to obtain a test result of each of the API interfaces to be tested based on the target execution information.
[0061] In this step, after obtaining the target execution information of the API interface to be tested, the target execution information can be compared with the predetermined reference execution information, thereby quickly determining the test result of the API to be tested.
[0062] The database application programming interface testing method in this application can provide a simplified API interface for black box test cases by encapsulating the underlying API interface, that is, encapsulating the database API interface with multiple combination parameters and the API interface with complex logical functions. This allows testers to quickly and concisely write black box test cases based on the simplified target API interface, thereby improving the efficiency of writing test cases and thus improving the efficiency of testing API interfaces. At the same time, by creating black box test cases corresponding to each API interface to be tested, this application can subsequently perform batch testing on each API interface to be tested based on each black box test case, further improving testing efficiency.
[0063] Based on the above embodiment, another embodiment of the present application provides a database application programming interface testing method. In this embodiment, before writing a test case, that is, before executing step S102, the configuration information of the database to be tested can also be obtained and stored in a preset location according to the preset format of the use case file. The configuration information includes any one or more of the following: database IP address information, database account name, password information, database startup port information, database version information, database operating system name information, maximum number of online users, and maximum number of threads. In this embodiment, the database to be tested can be a database on a Windows or Linux system, that is, interface testing of the database's underlying API interface on Windows and Linux systems is supported. In this embodiment, the database configuration information specifically includes: database link configuration information and / or database initial state configuration information. Among them, the database link configuration information includes any one or more of the following: database IP address information, database account name, password information, and database startup port information. The database initial state configuration information includes any one or more of the following: database version information, database operating system name information, maximum number of online users, and maximum number of threads. In this embodiment, by collecting and storing the database configuration information in advance, it is convenient to quickly obtain the configuration information of the database to be tested from the corresponding file / location, laying the foundation for quickly writing test cases for the corresponding test interface of the database in combination with the configuration information of the database to be tested.
[0064] Based on the above embodiment, another embodiment of the present application provides a database application programming interface testing method. In this embodiment, when encapsulating the API interface to be tested, that is, when executing step S101, the specific process is as follows:
[0065] Step 1: responding to a test case writing request to obtain identification information of each application programming interface to be tested in the database to be tested from the test case writing request;
[0066] In this step, the user enters / writes the identification information of the database to be tested and the identifier of the underlying API interface to be tested in the database to be tested in a predetermined interactive interface. This generates a test case writing request, and the backend server / electronic device can then obtain the identifier of the API interface to be tested from the writing request. The identifier uniquely represents the API interface to be tested and can specifically be a unique string, etc.
[0067] Step 2: Determine the interface type of the API interface to be tested; the interface type includes any one of a multi-combination parameter type, a single parameter type, a multi-function type, and a single function type;
[0068] In this step, since the interface type of the API interface can be a multi-combination parameter type or a complex function type, by encapsulating the database API interface with multi-combination parameters and the API interface with complex logical functions, a simplified API interface / target API interface can be provided for the black box test case, laying the foundation for the subsequent rapid writing of test cases based on the target API interface.
[0069] Step 3: When the interface type is a multi-parameter type or a multi-function type, encapsulate the API interface to be tested to obtain a target API interface of a single parameter type or a single function type;
[0070] During the specific implementation of this step, a predetermined encapsulation method may be called, or a predetermined API interface encapsulator may be called to directly encapsulate the corresponding underlying API interface, thereby obtaining a simplified / encapsulated target API interface.
[0071] In this embodiment, the database API interface with multiple combination parameters (i.e., the API interface with multiple combination parameters) refers to the interface parameters being of complex types, such as structure types. The code for constructing structure type parameters is relatively complex. Therefore, by encapsulating the underlying API interface, the parameters of the externally provided API interface (the encapsulated target API interface) are all basic or simple data types, making it easier for ordinary testers to write black box test cases.
[0072] Complex logical functions (i.e., multi-functional functions), such as table record retrieval, require multiple database APIs to implement. The dependencies between these APIs increase code complexity, requiring testers to possess higher coding skills. Encapsulating these APIs simplifies test case writing. Black-box test cases can be created by simply passing in SQL statements, paving the way for rapid black-box test case development.
[0073] In this embodiment, an abstract layer is provided for writing black box test cases by uniformly encapsulating the underlying API interface of the database. A parameter construction class or function is defined to create and verify the parameters required by the API interface. In the parameter construction class, the incoming parameters are verified to ensure that they meet the requirements. A function implementation class or function is defined to execute the operations of the API interface. In the function implementation class, the operations of the API interface are executed and possible errors are handled. An error code mapping table is created to map the error code to the corresponding error message. In the function implementation class, the execution results and error messages are packaged into a highly readable structure.
[0074] Another embodiment of the present application provides a database application programming interface testing method. In this embodiment, when executing step S202, that is, when responding to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a black box test case corresponding to each API interface to be tested is obtained, the specific process is as follows: responding to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a use case file of the black box test case corresponding to each API interface to be tested is obtained; each use case file is analyzed and processed respectively to obtain key information, and a code file in a predetermined programming language corresponding to the use case file is generated respectively based on each key information; each code file is compiled respectively using a predetermined compilation tool to obtain an executable file corresponding to each code file to obtain a black box test case.
[0075] In this embodiment, the key information may specifically include: function names and corresponding function parameters, etc. The predetermined programming language may be C++. The code file is specifically a C++ source file. In other words, a predetermined use case parser may be used to deeply parse and process the code / use case file of the black box test case, extracting key information from the test case statement, such as the function name and corresponding function parameters. Then, based on the function name and function parameters, a C++ source file that meets the requirements, i.e., a code file, may be automatically generated.
[0076] In this embodiment, after generating the code files / C++ language source files, each of the code files can be compiled using a predetermined compilation tool to obtain an executable file corresponding to each code file. After the code files are built / compiled, a build log can be collected and displayed. If the build / compilation fails, a detailed prompt message will be provided in the build log. After modifying the test case code / use case file, the code file of the test case can be built / compiled again to regenerate the executable file corresponding to each code file.
[0077] In this embodiment, after generating the executable file of the test case, when the API interface to be tested is subsequently tested, a link can be established with the database to be tested based on the configuration information of the database in each black box test case, and each API interface to be tested can be called to execute the black box test case, thereby performing a black box test on the API interface to be tested. Specifically, the executable file of the test case can be executed by calling the cmd command, and a link can be established with the database to be tested according to the database configuration information to perform the API interface test. During the execution process, API interface execution information is collected, such as API interface return value, API interface execution time, SQL statement retrieval results and other target execution information.
[0078] Another embodiment of the present application provides a database application programming interface testing method. In this embodiment, after obtaining each black box test case, a reference execution file corresponding to each black box test case and having successfully tested can also be created in advance. After the API interface to be tested is subsequently tested and the target execution information is obtained, the target execution information corresponding to the same black box test case can be compared with the reference execution information in the corresponding reference execution file to obtain a comparison result; based on the comparison result, it is determined whether the test of the API interface to be tested passed or failed to obtain a test result. The execution information refers to the execution result of the API interface, including: success, failure, error code, error description, etc.
[0079] Specifically, when the target execution information is inconsistent with the reference execution information, it can be determined that the API interface test to be tested has failed; conversely, when the target execution information is consistent with the reference execution information, it can be determined that the API interface test to be tested has passed. In this application, by comparing the target execution information with the reference information, the pass status of the test case can be automatically determined, thereby quickly obtaining the test results.
[0080] In the specific implementation process of this embodiment, when the test result of the API interface to be tested is a test failure, the method also includes: using the target API interface corresponding to the API interface to be tested that failed the test as a gray box test case for the API interface to be tested; performing gray box testing on the API interface to be tested that failed the test based on the gray box test case to obtain a test result.
[0081] During the specific implementation of this embodiment, each black box test case and / or gray box test case can also be stored in a predetermined storage method. For example, the open source test framework GTest can be introduced to achieve centralized management and organization of a large number of test cases (black box test cases and gray box test cases), and support the creation and editing of test cases. Specifically, each test case (gray box test case and black box test case) can be stored based on the use case directory. The use case directory is divided into a common directory and a use case directory. The common directory is used to store database configuration information files, global variable declaration files, GTest test framework header files and lib library files, database underlying API interface header files and lib library files. The use case directory is used to store all test case files, and the test cases are independent and do not depend on each other.
[0082] During the specific implementation of this embodiment, after obtaining the test results for each API interface under test, the method further includes: generating a test report based on each test result. Specifically, the target execution information / execution result of each test case, the execution time of each test case, and the pass rate of all test cases can be collected. Then, combined with information such as the internal configuration of the database under test, a test report is generated. The report can include necessary report elements such as the test date, test environment, pass rate, execution time, and a list of test cases.
[0083] Another embodiment of the present application provides a database application programming interface testing system, such as Figure 2 Shown, including:
[0084] The database API interface encapsulator is used to encapsulate each application programming interface API to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested;
[0085] The use case manager is configured to obtain a black box test case corresponding to each of the target API interfaces and the configuration information of the database to be tested in response to the user's operation of writing the test case based on the target API interface and the configuration information of the database to be tested;
[0086] The use case manager is further configured to establish a link with the database to be tested based on the configuration information of the database in each black box test case, and call each API interface to be tested to execute the corresponding black box test case;
[0087] The use case manager is further configured to obtain target execution information when each of the API interfaces to be tested executes the test case, so as to obtain test results of each of the API interfaces to be tested based on the target execution information.
[0088] During the specific implementation of this embodiment, the database application programming interface testing system may further include a database configuration information manager, which is used to: obtain configuration information of the database to be tested, and store the configuration information in a preset location or a preset file according to the preset format of the use case file. The configuration information includes any one or more of the following: database IP address information, database account name, password information, database startup port information, database version information, name information of the operating system where the database is located, the maximum number of online users, and the maximum number of threads.
[0089] In the specific real-time process of this embodiment, the database API interface encapsulator is specifically used to: respond to a test case writing request to obtain the flag information of each API interface to be tested in the database to be tested from the test case writing request;
[0090] Determine the interface type of the API interface to be tested based on the flag information of the API interface to be tested; the interface type includes any one of a multi-combination parameter type, a single parameter type, a multi-function type, and a single function type;
[0091] When the interface type is a multi-combination parameter type or a multi-function type, the API interface to be tested is encapsulated to obtain a target API interface of a single parameter type or a single function type.
[0092] Specifically, the use case editor in the use case manager can provide a predetermined interactive interface, and the user can input / write / the identification information of the database to be tested and the identification information of the underlying API interface to be tested in the database to be tested in the predetermined interactive interface, and generate a test case writing request through the use case editor. The writing request will transmit the database API interface wrapper, so the database API interface wrapper can respond to the writing request to find the corresponding API interface to be tested from the identification information of the database to be tested and the identification information of the API interface to be tested in the writing request, and then determine whether the API interface is an interface with multiple parameters or complex functions, and if the API interface is an interface with multiple parameters or complex functions, encapsulate the API interface to obtain the target API interface, that is, obtain the simplified API interface, and feed the target API interface back to the use case editor for display.
[0093] During the specific implementation of this embodiment, the use case manager uses a graphical interface and the open source testing framework GTest to centrally manage and organize a large number of test cases. It supports the creation, editing, automated construction, and execution of test cases, tracks the test case construction and execution process, generates test case result files, compares them with preset test success files, and automatically analyzes the test case results. The use case manager includes a use case editor, a use case analyzer, and a use case compiler.
[0094] Specifically, the use case editor is used to: in response to the user's operation of writing a test case based on each target API interface and the configuration information of the database to be tested, obtain a use case file of a black box test case corresponding to each API interface to be tested;
[0095] The use case analyzer is used to analyze and process each of the use case files to obtain key information, and generate a code file in a predetermined programming language corresponding to the use case file based on each of the key information;
[0096] The use case compiler is used to compile each of the code files using a predetermined compilation tool to obtain an executable file corresponding to each code file, so as to obtain a black box test case.
[0097] That is, after obtaining the encapsulated target API interface, the user performs the test case writing operation in the predetermined interactive interface of the use case editor according to the interface information of the target interface, and obtains the use case file of the black box test case corresponding to each of the API interfaces to be tested. Specifically, the predetermined interactive interface of the use case editor can respond to the user's parameter input operation or test statement input operation for the target API interface, so as to obtain the target parameters and / or target test statements, and then generate the use case file of the black box test case based on the target parameters and / or target test statements. In this embodiment, when a certain underlying API interface to be tested is a simple database API interface (that is, the type of the underlying API interface to be tested is a single parameter type or a single function type), the user can directly write the use case file of the gray box test of the API interface in the predetermined interactive interface of the use case editor.
[0098] The use case manager also includes a use case executor, which is configured to establish a link with the database under test based on the database configuration information in each black box test case and invoke each API interface under test to execute the corresponding black box test case. Specifically, the use case executor may execute the executable file of the use case by invoking the cmd command, establish a link with the database under test based on the database configuration information, and execute the API interface test.
[0099] In the specific implementation process of this embodiment, the use case manager includes a use case result analyzer, and the use case editor is further used to pre-create a reference execution file corresponding to each black box test case and having been successfully tested;
[0100] The use case result analyzer is used to obtain the target execution information of each API interface under test when executing the test case, so as to obtain the test result of each API interface under test based on the target execution information. The use case result analyzer is specifically used to obtain the target execution information of each API interface under test when executing the test case, compare the target execution information corresponding to the same black box test case with the reference execution information in the corresponding reference execution file to obtain a comparison result; and determine whether the test of the API interface under test passes or fails based on the comparison result to obtain a test result.
[0101] During the specific implementation of this embodiment, when the test result of the API interface to be tested is a test failure, the use case manager is also used to use the target API interface corresponding to the API interface to be tested that failed the test as a gray box test case for the API interface to be tested; based on the gray box test case, the API interface to be tested that failed the test is gray box tested to obtain a test result.
[0102] During the specific implementation of this embodiment, the use case manager is also used to store each black box test case and / or gray box test case in a predetermined storage method. During the specific implementation of this embodiment, test cases can be stored based on the use case target. The use case directory is divided into a common directory and a use case directory. The common directory is used to store database configuration information files, global variable declaration files, GTest test framework header files and lib library files, database underlying API interface header files and lib library files. The use case directory is used to store all test case files, and the test cases are independent and do not depend on each other.
[0103] In the specific implementation process of this embodiment, the database application programming interface testing system further includes a test report generator, which is used to: after obtaining the test results of each API interface to be tested, generate a test report based on each test result.
[0104] The database application programming interface testing system in this application provides a graphical interface for managing and organizing use cases, supporting functions such as use case navigation, use case display, and use case grouping. A use case execution button is also provided on the graphical interface, which can compile and execute all test cases and display the collected use case execution information in the graphical interface.
[0105] This application can improve testing efficiency and support testers at different levels to write test cases. The function of writing gray box test cases is reserved for senior testers, allowing access to the internal implementation details of the database's underlying API interface to track underlying errors and conduct in-depth analysis of the causes. It also supports complex test scenarios and multi-parameter combinations, as well as the writing of complex logical functions. At the same time, it provides ordinary testers with the function of writing black box test cases. Test cases involving complex functions directly call the simplified API interface provided by the database API interface encapsulator. There is no need to pay attention to the implementation of the underlying code, so test cases can be written quickly to improve testing efficiency.
[0106] Another embodiment of the present application provides a storage medium storing a computer program. When the computer program is executed by a processor, the following method steps are implemented:
[0107] Step 1: Encapsulate each API to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested;
[0108] Step 2: In response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a black box test case corresponding to each API interface to be tested is obtained;
[0109] Step 3: Establish a link with the database to be tested based on the configuration information of the database in each black box test case, and call each API interface to be tested to execute the corresponding black box test case;
[0110] Step 4: Obtain target execution information when each of the API interfaces to be tested executes the test case, so as to obtain test results of each of the API interfaces to be tested based on the target execution information.
[0111] The specific implementation process of the above method steps can be found in any of the above-mentioned embodiments of the database application programming interface testing method, and this embodiment will not be repeated here.
[0112] The storage medium in this application can provide a simplified API interface for black box test cases by encapsulating the underlying API interface, that is, encapsulating the database API interface with multiple combination parameters and the API interface with complex logical functions. This allows testers to quickly and concisely write black box test cases based on the simplified target API interface, thereby improving the efficiency of writing test cases and thus improving the testing efficiency of the API interface. At the same time, by creating black box test cases corresponding to each API interface to be tested, this application can subsequently perform batch testing on each API interface to be tested based on each black box test case, further improving the testing efficiency.
[0113] Another embodiment of the present application provides an electronic device, such as Figure 3 As shown, it at least includes a memory 1 and a processor 2. The memory 1 stores a computer program. When the processor 2 executes the computer program on the memory 1, it implements the following method steps:
[0114] Step 1: Encapsulate each API to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested;
[0115] Step 2: In response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a black box test case corresponding to each API interface to be tested is obtained;
[0116] Step 3: Establish a link with the database to be tested based on the configuration information of the database in each black box test case, and call each API interface to be tested to execute the corresponding black box test case;
[0117] Step 4: Obtain target execution information when each of the API interfaces to be tested executes the test case, so as to obtain test results of each of the API interfaces to be tested based on the target execution information.
[0118] The specific implementation process of the above method steps can be found in any of the above-mentioned embodiments of the database application programming interface testing method, and this embodiment will not be repeated here.
[0119] The electronic device in this application can provide a simplified API interface for black box test cases by encapsulating the underlying API interface, that is, encapsulating the database API interface with multiple combination parameters and the API interface with complex logical functions. As a result, testers can quickly and concisely write black box test cases based on the simplified target API interface, thereby improving the efficiency of writing test cases and thus improving the testing efficiency of the API interface. At the same time, in this application, by creating black box test cases corresponding to each API interface to be tested, each API interface to be tested can be batch tested based on each black box test case, further improving the testing efficiency.
[0120] The above embodiments are merely exemplary embodiments of the present application and are not intended to limit the scope of the present application. The scope of protection of the present application is defined by the claims. Those skilled in the art may make various modifications or equivalent substitutions to the present application within the essence and scope of protection of the present application, and such modifications or equivalent substitutions shall also be deemed to fall within the scope of protection of the present application.
Claims
1. A database application programming interface testing method, characterized in that: include: Encapsulate each application programming interface API to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested; In response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a black box test case corresponding to each API interface to be tested is obtained; Based on the configuration information of the database in each black box test case, a link is established with the database to be tested, and each API interface to be tested is called to execute the corresponding black box test case; Target execution information of each of the API interfaces to be tested when executing the test case is obtained, so as to obtain test results of each of the API interfaces to be tested based on the target execution information.
2. The method according to claim 1, characterized in that Before responding to the user's writing operation for the test case based on each of the target API interfaces and the configuration information of the database to be tested, the method further includes: Obtain configuration information of the database to be tested, and store the configuration information in a preset location according to the preset format of the use case file, wherein the configuration information includes any one or more of the following: database IP address information, database account name, password information, database startup port information, database version information, database operating system name information, maximum number of online users, and maximum number of threads.
3. The method according to claim 1, characterized in that The step of encapsulating each application programming interface API to be tested in the database to be tested and obtaining the encapsulated target API interface corresponding to each API interface to be tested specifically includes: In response to the test case writing request, the marking information of each API interface to be tested in the database to be tested is obtained from the test case writing request; Determine the interface type of the API interface to be tested based on the flag information of the API interface to be tested; the interface type includes any one of a multi-combination parameter type, a single parameter type, a multi-function type, and a single function type; When the interface type is a multi-combination parameter type or a multi-function type, the API interface to be tested is encapsulated to obtain a target API interface of a single parameter type or a single function type.
4. The method according to claim 1, characterized in that The responding user obtains a black box test case corresponding to each of the target API interfaces and the configuration information of the database to be tested and a test case writing operation based on the target API interfaces and the configuration information of the database to be tested, specifically including: In response to the user's operation of writing test cases based on the configuration information of each target API interface and the database to be tested, a use case file of a black box test case corresponding to each API interface to be tested is obtained; Analyze and process each of the use case files to obtain key information, and generate code files in a predetermined programming language corresponding to the use case files based on each of the key information; The code files are compiled respectively using a predetermined compilation tool to obtain executable files corresponding to the code files, so as to obtain black box test cases.
5. The method according to claim 1, characterized in that After obtaining each black box test case, the method further includes: Pre-create reference execution files corresponding to each black box test case and with successful testing; The obtaining the test result of each of the API interfaces to be tested based on the target execution information specifically includes: Compare the target execution information corresponding to the same black box test case with the reference execution information in the corresponding reference execution file to obtain a comparison result; Based on the comparison result, it is determined whether the API interface to be tested passes or fails the test to obtain a test result.
6. The method according to claim 1, characterized in that When the test result of the API interface to be tested is a test failure, the method further includes: The target API interface corresponding to the API interface under test that failed the test is used as a gray box test case of the API interface under test; Based on the gray box test case, gray box testing is performed on the API interface to be tested that failed the test to obtain a test result.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: Each black box test case and / or grey box test case is stored according to a predetermined storage method.
8. The method according to claim 1, characterized in that After obtaining the test results of each API interface to be tested, the method further includes: A test report is generated based on each test result.
9. A database application programming interface testing system, characterized in that: include: The database API interface encapsulator is used to encapsulate each application programming interface API to be tested in the database to be tested, and obtain the encapsulated target API interface corresponding to each API interface to be tested; The use case manager is used to respond to the user's writing operation for the test case based on the configuration information of each target API interface and the database to be tested, and obtain the black box test case corresponding to each API interface to be tested; The use case manager is further used to establish a link with the database to be tested based on the configuration information of the database in each black box test case, and call each API interface to be tested to execute the corresponding black box test case; The use case manager is further used to obtain target execution information when each of the API interfaces to be tested executes the test case, so as to obtain the test results of each of the API interfaces to be tested based on the target execution information.
10. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the database application programming interface testing method described in any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Database interface testing method and device, equipment and storage medium
CN114385483A
Test case generation method, test method, electronic equipment and storage medium
CN115373988A
Method and device for verifying query interface of database table and electronic equipment
CN116991732A
Interface testing method and device, equipment, storage medium and program product
CN117520195A
Method and system for testing application programming interface
CN118349448A