An interface test method and device, electronic equipment and storage medium
By configuring data sources and conditional expressions for interface testing, test reports are automatically generated, solving the problems of high professionalism and maintenance difficulty in existing interface testing, and realizing simplified processes and diversified assertions.
Patent Information
- Application Number
- CN202110745068.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-30
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2041-06-30
AI Technical Summary
Existing interface testing requires developers to write code, which demands a high level of expertise and makes test case maintenance difficult.
By pre-configuring data sources to obtain request source data and conditional expressions for the test interface, data-driven interface testing is used to automatically generate test reports.
It reduces the code capability requirements and maintenance difficulty for users, simplifies the interface testing process, supports various types of test assertions, and improves test functionality requirements.
Smart Images

Figure CN115543771B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to an interface testing method, apparatus, electronic device, and storage medium. Background Technology
[0002] Interface testing, also known as API (Application Programming Interface) testing, is mainly used to test the interaction interfaces between external and internal systems, as well as different interaction interfaces within the internal system. Interface testing is primarily used to test the correctness of interface parameter passing and to verify the rationality of interface function implementation.
[0003] Currently, when conducting interface testing, developers need to write code to create test cases for the interface, which presents problems such as high professional requirements and difficulty in maintaining test cases. Summary of the Invention
[0004] The purpose of this invention is to address the shortcomings of the prior art by providing an interface testing method, apparatus, electronic device, and storage medium, which is achieved through the following technical solutions.
[0005] A first aspect of the present invention provides an interface testing method, the method comprising:
[0006] Obtain request source data for each dimension of the test interface and at least one conditional expression from a pre-configured data source;
[0007] Request returned data from the test interface using source data from various dimensions;
[0008] For each conditional expression, the operator in the conditional expression is detected, and the value of the statements on both sides of the operator in the conditional expression is determined according to the returned data. The values of the statements on both sides are compared based on the operator to obtain the comparison result.
[0009] A test report is generated based on the comparison results of each conditional expression.
[0010] In some embodiments of this application, requesting the test interface to return data using request source data of each dimension includes: constructing an interface request based on request source data of each dimension; and using the interface request to obtain the return data of the test interface.
[0011] In some embodiments of this application, constructing an interface request based on request source data of various dimensions includes: extracting data from the request source data of various dimensions, including the request header, Uniform Resource Locator (URL), request parameters, and request method of the test interface; and constructing an interface request using the data of the four dimensions.
[0012] In some embodiments of this application, the operator is any one of greater than, greater than or equal to, equal to, not equal to, less than, and less than or equal to.
[0013] In some embodiments of this application, determining the values of the statements on both sides of the operator in the conditional expression based on the returned data includes: for each statement, determining whether the statement contains a first keyword; if it contains a first keyword, obtaining the preliminary value of the internal statement of the first keyword, and calculating the preliminary value using the calculation rules of the first keyword to obtain the value of the statement; if it does not contain a first keyword, determining whether the statement contains a second keyword; if it contains a second keyword, obtaining the value of the statement based on the second keyword; if it does not contain a second keyword, determining whether the string in the statement is a target field in the returned data; if it is a target field, reading the data of the target field from the corresponding level in the returned data according to the level of the string as the value of the statement; if it is not a target field, using the string as the value of the statement.
[0014] In some embodiments of this application, obtaining the value of the side statement based on the second keyword includes: obtaining the execution action corresponding to the second keyword, and obtaining data based on the execution action as the value of the side statement.
[0015] In some embodiments of this application, obtaining data as the value of the side statement based on the execution action includes: if the execution action is to obtain database data, then obtaining the target database name, database query statement, and data type to be obtained after the second keyword from the side statement; extracting the database configuration source data corresponding to the target database name from a pre-configured data source; establishing a connection with the remote database corresponding to the target database name using the database configuration source data, and obtaining the target data as the value of the side statement from the remote database based on the database query statement and the data type to be obtained.
[0016] In some embodiments of this application, the database configuration source data includes database type, database address, database port, database account, database password, and string parsing type.
[0017] A second aspect of the present invention provides an interface testing apparatus, the apparatus comprising:
[0018] The acquisition module is used to obtain request source data for each dimension of the test interface and at least one conditional expression from a pre-configured data source.
[0019] The request module is used to request data from the test interface using source data from various dimensions.
[0020] The assertion module is used to detect the operator in each conditional expression, determine the value of the statements on both sides of the operator in the conditional expression based on the returned data, and compare the values of the statements on both sides based on the operator to obtain the comparison result.
[0021] The report generation module is used to generate test reports based on the comparison results of various conditional expressions.
[0022] A third aspect of the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, performs the steps of the method described in the first aspect above.
[0023] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect above.
[0024] Based on the interface testing method and apparatus described in the first and second aspects above, the present invention has at least the following beneficial effects or advantages:
[0025] By using a pre-configured data source as a data-driven approach to implement interface testing, users do not need to write code. Users only need to configure the request source data of the test interface and the conditional expressions used for assertions. In other words, this invention leaves the complex logic to the backend program, making it simple and intuitive for users to use, reducing the code capability requirements and maintenance difficulty for users.
[0026] In addition, during the testing process, after obtaining the returned data from the interface using the source data from various dimensions, the operation method of the values on both sides of each conditional expression operator is analyzed to determine the values on both sides, so as to perform assertions and generate test reports. Therefore, by using different operators and different operation methods, various types of test assertions can be implemented, thereby improving various test function requirements. Attached Figure Description
[0027] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:
[0028] Figure 1 This is a flowchart illustrating an embodiment of an interface testing method according to an exemplary embodiment of the present invention;
[0029] Figures 2A to 2B According to the present invention Figure 1 An example illustration showing how to configure a data source in Excel format;
[0030] Figures 3A to 3B According to the present invention Figure 1 An example illustration showing the configuration of a data source in JSON format;
[0031] Figure 4 This is a flowchart illustrating the process of determining the values of statements on both sides of a conditional expression according to an exemplary embodiment of the present invention.
[0032] Figure 5 According to the present invention Figure 4 An example illustration shows a schematic diagram of the analysis of a conditional expression;
[0033] Figure 6 This is a schematic diagram of an interface testing device according to an exemplary embodiment of the present invention;
[0034] Figure 7 This is a schematic diagram of the hardware structure of an electronic device according to an exemplary embodiment of the present invention;
[0035] Figure 8 This is a schematic diagram illustrating the structure of a storage medium according to an exemplary embodiment of the present invention. Detailed Implementation
[0036] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the invention as detailed in the appended claims.
[0037] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The singular forms “a,” “the,” and “the” used in this invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0038] It should be understood that although the terms first, second, third, etc., may be used in this invention to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first information may also be referred to as second information without departing from the scope of this invention, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."
[0039] To address the challenges of traditional interface testing, which requires users to write code to create test cases, posing high professional requirements and maintenance difficulties, this invention proposes an improved interface testing method. This method receives a user-configured data source and parses it to obtain request source data for various dimensions of the test interface and at least one conditional expression. Then, it uses this request source data to request return data from the test interface. For each conditional expression, it detects the operators within the expression and determines the values of the statements on both sides of the operator based on the returned data. It then compares the values of the statements on both sides based on the operator to obtain the comparison results, and finally generates a test report based on the comparison results of each conditional expression.
[0040] The technical effects that can be achieved based on the above description are:
[0041] This invention uses the user-configured data source as a data-driven implementation for interface testing, eliminating the need for users to write code. Users only need to configure the request source data of the test interface and the conditional expressions used for assertions. In other words, this invention leaves the complex logic to the backend program, making it simple and intuitive for users to use, reducing the code capability requirements and maintenance difficulty for users.
[0042] In addition, during the testing process, after obtaining the returned data from the interface using the source data from various dimensions, the operation method of the values on both sides of each conditional expression operator is analyzed to determine the values on both sides, so as to perform assertions and generate test reports. Therefore, by using different operators and different operation methods, various types of test assertions can be implemented, thereby improving various test function requirements.
[0043] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0044] Example 1:
[0045] Figure 1This is a flowchart illustrating an embodiment of an interface testing method according to an exemplary model of the present invention. The interface testing method can be applied to electronic devices, which may include any network-connected device such as a terminal device, mobile terminal, PC, or server. Figure 1 As shown, the interface testing method includes the following steps:
[0046] Step 101: Obtain the request source data for each dimension of the test interface and at least one conditional expression from the pre-configured data source.
[0047] Before performing step 101, the user needs to pre-configure the data source as a data driver.
[0048] In one optional implementation, the data source can be in Excel format. Users fill in the interfaces and test points to be tested into the Excel file to form the data source for the test interfaces.
[0049] Optionally, the data source in Excel format can include two items: a configuration page and a test page. The configuration page contains an overall overview of the system under test and information related to the remote database, while the test page contains a set of test cases.
[0050] For example, such as Figure 2A The image shows an example of a data source configuration page, which includes four fields: the first field, name, represents the project name of the system under test; the second field, info, represents the project description of the system under test; the third field, status, indicates whether the project of the system under test is included in the test, specifically, "1" indicates inclusion in the test, and "0" indicates non-inclusion in the test; the fourth field, db_config, represents the configuration information of the remote database to be connected, which includes the database name db_name, database type driver, database address host, database port port, database account username, database password password, and string parsing type charset.
[0051] like Figure 2BThe image shows an exemplary data source test page. Each row represents a test case, and each test case includes nine fields, each representing a dimension. Specifically, the first field, `index`, represents the test case number; the second field, `name`, represents the test case name; the third field, `info`, represents the test case description; the fourth field, `status`, indicates whether the test case is included in the test ("1" indicates inclusion, "0" indicates exclusion); the fifth field, `method`, represents the API request method; the sixth field, `header`, represents the API request header; the seventh field, `url`, represents the API request address; the eighth field, `data`, represents the API request parameters; and the ninth field, `test`, represents the test module. Each cell contains one conditional expression, i.e., one test point, and each test case includes at least one test point.
[0052] In another optional implementation, the data source can also be in JSON format. Users fill in the interfaces and test points to be tested into the JSON to form the data source for the test interfaces.
[0053] Optionally, corresponding to the Excel-format data source mentioned above, the JSON-format data source can include a configuration area and a test area. The configuration area contains an overall overview of the system under test and information related to the remote database, while the test area contains a set of test cases.
[0054] For example, such as Figure 3A The image shows an example of a data source configuration area, where all fields are as described above. Figure 2A All fields in the configuration page shown are the same, and will not be listed one by one here.
[0055] like Figure 3B The image shows an example of a data source test area, where all fields are the same as those described above. Figure 2B The fields shown in the test page are all the same, and will not be listed one by one here.
[0056] It should be noted that, based on the above... Figure 2A , Figure 2B , Figure 3A ,as well as Figure 3B The data source configuration shown is simple and easy to use. Users only need to input data according to a uniform input format to form test cases without writing complex code.
[0057] In step 101, during the testing process, test cases need to be executed one by one. Each time, the source data and condition expressions for each dimension of the test case are obtained from the data source for subsequent data requests and test assertions.
[0058] Specifically, as mentioned above Figure 2B As shown, the source data for each dimension comes from the data corresponding to the first eight fields, and the data for the conditional expression comes from the data corresponding to the ninth field.
[0059] Step 102: Request the returned data from the test interface using the source data from each dimension.
[0060] In an optional embodiment, an interface request can be constructed first based on the source data of each dimension, and then the returned data of the test interface can be obtained using the constructed interface request.
[0061] Specifically, the constructed interface request can be an HTTP (Hypertext Transfer Protocol) request, which then requests data from the test interface. The returned data is the response data of the test interface.
[0062] Optionally, regarding the specific construction process of the interface request, data from four dimensions of the test interface—request header, URL (uniform resource identifier), request parameters, and request method—can be extracted from the request source data of each dimension, and then the interface request can be constructed using the data from these four dimensions.
[0063] Specifically, as mentioned above Figure 2B As shown, the data for the four dimensions—request header, URL, request parameters, and request method—comes from the data in the fifth to eighth fields.
[0064] Step 103: For each conditional expression, detect the operator in the conditional expression, determine the value of the statements on both sides of the operator in the conditional expression based on the returned data, and compare the values of the statements on both sides based on the operator to obtain the comparison result.
[0065] The operators in the conditional expression are the core of the assertion. They are located in the middle of the conditional expression and are used to compare the values on both sides of the conditional expression.
[0066] Specifically, if the values on both sides of the conditional expression are compared correctly, i.e., the comparison result is true, then the test point corresponding to the conditional expression passes the test; if the values on both sides of the conditional expression are compared incorrectly, i.e., the comparison result is false, then the test point corresponding to the conditional expression fails the test.
[0067] For example, 25 * 25 == 600, the operator is 'equals', the left side is 625 and the right side is 600, the expression is: 625 == 600, the result is false, the test failed.
[0068] In this embodiment, the present invention can support any one of the following operators: greater than (>), greater than or equal to (>=), equal to (==), not equal to (!=), less than (<), and less than or equal to (<=).
[0069] It should be noted that the process of determining the values of the statements on both sides of the operator in the conditional expression based on the returned data can be found in the relevant description of the following embodiments, which will not be detailed here.
[0070] Step 104: Generate a test report based on the comparison results of each conditional expression.
[0071] In one optional specific embodiment, test case numbers, test case names, and test case descriptions can be extracted from source data from various dimensions, and a test report can be generated using the extracted test case numbers, test case names, test case descriptions, and the comparison results obtained from the values on both sides of each conditional expression operator and assertions.
[0072] After performing step 104, the test report can be sent to the user via email, Lark, DingTalk, or other means.
[0073] This completes the above. Figure 1 The test process shown in this invention uses the user-configured data source as a data-driven implementation of interface testing. Users do not need to write code; they only need to configure the request source data of the test interface and the conditional expressions used for assertions. In other words, this invention leaves the complex logic to the backend program, making it simple and intuitive for users to use, reducing the code capability requirements and maintenance difficulty for users.
[0074] In addition, during the testing process, after obtaining the returned data from the interface using the source data from various dimensions, the operation method of the values on both sides of each conditional expression operator is analyzed to determine the values on both sides, so as to perform assertions and generate test reports. Therefore, by using different operators and different operation methods, various types of test assertions can be implemented, thereby improving various test function requirements.
[0075] Example 2:
[0076] Figure 4 This is a schematic diagram illustrating a process for determining the values of statements on both sides of a conditional expression according to an exemplary embodiment of the present invention. Based on the above... Figure 1 , 2A Based on the embodiments shown in -2B and 3A-3B, the process of retrieving values from the statements on both sides of the conditional expression includes the following steps:
[0077] Step 401: For each statement, determine whether the statement contains the first keyword. If it contains the first keyword, proceed to step 402; otherwise, proceed to step 403.
[0078] The first keyword is an aggregate function, which can include count(), Sum(), Avg(), Max(), Min(), etc.
[0079] Step 402: Obtain the preliminary value of the internal statement of the first keyword, and calculate the preliminary value using the calculation rules of the first keyword to obtain the value of the statement on that side.
[0080] Based on the five primary keywords given in step 401 above, the calculation rule for count() is to count the number of times, the calculation rule for Sum() is to count the total number, the calculation rule for Avg() is to calculate the average, the calculation rule for Max() is to take the maximum number, and the calculation rule for Min() is to take the minimum number.
[0081] It should be noted that since the internal statement of the first keyword has the same status as the statements on both sides of the operator, the preliminary value retrieval process of the internal statement of the first keyword can be found in the detailed description of the value retrieval process in steps 403 to 407 below.
[0082] For example, suppose the specific statement on one side of an operator is as follows:
[0083] count(data.apps)+sum(@data.data.list)
[0084] In this context, "data.apps" and "@data.data.list" are statements inside aggregate functions.
[0085] Step 403: Determine whether the statement contains a second keyword. If it contains a second keyword, proceed to step 404. If it does not contain a second keyword, proceed to step 405.
[0086] Optionally, the second keyword is a magic variable with a preset special symbol (such as "@").
[0087] For example, the statement "@data.data.list" in step 402 above contains "@data", which is a secondary keyword.
[0088] like Figure 5 As shown above Figure 2AThe diagram below illustrates the analysis of the second conditional expression in the second row of the test case. The statement on the right side of the operator is: @db.soyoungTest.select count(doctor_id)from db_kr.tb_doctorwhere status=1.one, where "@db" is a secondary keyword.
[0089] Step 404: Obtain the value of the statement on this side based on the second keyword.
[0090] In an optional embodiment, different second keywords can be set to different execution actions. Therefore, the execution action corresponding to the second keyword contained in the side statement can be obtained, and the data can be obtained as the value of the side statement based on the execution action.
[0091] For example, different execution actions corresponding to different second keywords can include: "@" represents the root node of the test case; "@response" represents the test interface return data node of this test case, for example: @response.time represents the time consumed to obtain the returned data; "@request" represents the request node of this test case; "@data" represents the return data of this test case; "@header" represents the obtained request header node; "@time" represents obtaining the response time; "@cookie" represents obtaining the cookie node; "@str" represents obtaining the string format of the returned data; "@status" represents the status of the returned data; "@db" represents obtaining data from a remote database.
[0092] In one optional implementation, if the corresponding action is to obtain database data, then the target database name, database query statement, and type of data to be obtained after the second keyword are obtained from the statement. The database configuration source data corresponding to the target database name is extracted from the pre-configured data source. Then, the database configuration source data is used to establish a connection with the remote database corresponding to the target database name. Based on the database query statement and the type of data to be obtained, the target data is obtained from the remote database as the value of the statement.
[0093] Optionally, the database configuration source data extracted from the data source may include the database type, database address, database port, database account, database password, and string parsing type.
[0094] For example, continuing as described above Figure 5As shown, the statement on the right side of the operator is: `@db.soyoungTest.selectcount(doctor_id)from db_kr.tb_doctor where status=1.one`, where "@db" is the second keyword, the target database name is `soyoungTest`, the database query statement is the SQL statement `select count(doctor_id)from db_kr.tb_doctor where status=1`, and the last part specifies the data type to be retrieved as `one`, as described above. Figure 2B As shown, the database configuration source data extracted from the configuration page of the data source using the database name soyoungTest includes the database type mysql, database address 10.10.10.110, database port 6033, database account test_group, database password ***, and string parsing type utf8mb4.
[0095] Step 405: Determine whether the string in the statement is the target field in the returned data. If it is the target field, proceed to step 406; otherwise, proceed to step 407.
[0096] See above Figure 2B The conditional expressions below the ninth field are as follows. The three conditional expressions in the first row are all ordinary expressions, such as "code>199", "code<201", and "msg==success". Here, "code" and "msg" are fields from the returned data, indicating that data from the target field in the returned data is retrieved. "199" and "201" are numeric strings, representing data to be directly compared with the value on the other side. Therefore, it is necessary to determine whether the string in the statement represents the target field in the returned data.
[0097] Step 406: Read the data of the target field from the corresponding level in the returned data according to the level of the string, and use it as the value of the statement on this side.
[0098] For example, in step 402 above, “data.apps” is given, where “data” and “apps” are both target fields in the returned data, and the hierarchy is distinguished by “.”.
[0099] Step 407: Use the string as the value of the statement on this side.
[0100] If the string in the statement is not the target field in the returned data, it means that the string is the value of this statement, which is a fixed value.
[0101] Regarding steps 401 to 407 above, in order to assert all levels of the returned data and expand the test coverage, a first keyword is predefined to represent various aggregate functions, thereby enabling assertions on secondary calculations of the returned data. Additionally, a second keyword is predefined to represent various magic variables, enabling assertions on all dimensions of the returned data, such as assertions on HTTP status codes, response times, request headers, response headers, etc., or, for example, assertions on retrieving dynamic data from a remote database.
[0102] This completes the above. Figure 4 The value retrieval process shown above enables this solution to assert the target field data in the returned data. Furthermore, by setting keywords, it can enable aggregate functions to perform secondary processing on the returned data, connect to remote databases to obtain dynamic data, and assert the returned data in other dimensions. The test coverage is broad, and it can achieve assertions on all levels of the returned data.
[0103] Corresponding to the embodiments of the aforementioned interface testing methods, the present invention also provides embodiments of interface testing apparatus.
[0104] Figure 6 This is a flowchart illustrating an embodiment of an interface testing apparatus according to an exemplary embodiment of the present invention. The apparatus is used to execute the interface testing method provided in any of the above embodiments, such as... Figure 6 As shown, the interface testing device includes:
[0105] The acquisition module 610 is used to acquire request source data for each dimension of the test interface and at least one conditional expression from a pre-configured data source.
[0106] Request module 620 is used to request return data from the test interface using request source data from various dimensions;
[0107] The assertion module 630 is used to detect the operator in each conditional expression, determine the value of the statements on both sides of the operator in the conditional expression based on the returned data, and compare the values of the statements on both sides based on the operator to obtain a comparison result.
[0108] The report generation module 640 is used to generate a test report based on the comparison results of each conditional expression.
[0109] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0110] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the present invention according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0111] The present invention also provides an electronic device corresponding to the interface testing method provided in the foregoing embodiments, for executing the above-described interface testing method.
[0112] Figure 7 This is a hardware structure diagram of an electronic device according to an exemplary embodiment of the present invention. The electronic device includes: a communication interface 601, a processor 602, a memory 603, and a bus 604; wherein the communication interface 601, the processor 602, and the memory 603 communicate with each other through the bus 604. The processor 602 can execute the interface testing method described above by reading and executing machine-executable instructions corresponding to the control logic of the interface testing method in the memory 603. The specific content of the method is described in the above embodiment and will not be repeated here.
[0113] The memory 603 mentioned in this invention can be any electronic, magnetic, optical, or other physical storage device, and can contain stored information such as executable instructions, data, etc. Specifically, the memory 603 can be RAM (Random Access Memory), flash memory, storage drive (such as hard disk drive), any type of storage disk (such as optical disc, DVD, etc.), or similar storage media, or combinations thereof. Communication between this system network element and at least one other network element is achieved through at least one communication interface 601 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc., can be used.
[0114] Bus 604 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. The memory 603 is used to store programs, and the processor 602 executes the programs after receiving execution instructions.
[0115] Processor 602 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 602 or by instructions in software form. The processor 602 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application-Specific Integrated Circuit (ASIC), an On-Premises Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor.
[0116] The electronic device provided in this application embodiment and the interface testing method provided in this application embodiment are based on the same inventive concept and have the same beneficial effects as the methods they adopt, operate or implement.
[0117] This application also provides a computer-readable storage medium corresponding to the interface testing method provided in the foregoing embodiments. Please refer to... Figure 8 As shown, the computer-readable storage medium is an optical disc 30, on which a computer program (i.e., a program product) is stored. When the computer program is run by a processor, it executes the interface testing method provided in any of the aforementioned embodiments.
[0118] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical and magnetic storage media, which will not be elaborated here.
[0119] The computer-readable storage medium provided in the above embodiments of this application and the interface testing method provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the applications stored therein.
[0120] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the following claims.
[0121] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0122] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. An interface testing method, characterized in that, The method includes: Obtain request source data for each dimension of the test interface and at least one conditional expression from a pre-configured data source; the data source is a user-pre-configured data-driven file, which includes the configuration content and test content of the test interface, the test content includes test cases, and the test cases contain request source data for each dimension and conditional expressions; Request returned data from the test interface using source data from various dimensions; For each conditional expression, the operator in the conditional expression is detected, and the value of the statements on both sides of the operator in the conditional expression is determined according to the returned data. The values of the statements on both sides are compared based on the operator to obtain the comparison result. A test report is generated based on the comparison results of each conditional expression; The step of determining the values of the statements on both sides of the operator in the conditional expression based on the returned data includes: For each statement, determine whether the statement contains the first keyword; If the first keyword is included, the initial value of the internal statement of the first keyword is obtained, and the initial value is calculated using the calculation rule of the first keyword to obtain the value of the statement on that side. If the first keyword is not included, determine whether the statement on this side contains the second keyword. If a second keyword is included, the value of the statement is obtained based on the second keyword, including: obtaining the execution action corresponding to the second keyword; if the execution action is to obtain database data, then the target database name, database query statement, and data type to be obtained are obtained from the statement; the database configuration source data corresponding to the target database name is extracted from the pre-configured data source; a connection is established with the remote database corresponding to the target database name using the database configuration source data; and the target data is obtained from the remote database as the value of the statement based on the database query statement and the data type to be obtained. If the second keyword is not included, determine whether the string in the statement is the target field in the returned data; if it is the target field, read the data of the target field from the corresponding level in the returned data according to the level of the string as the value of the statement; if it is not the target field, use the string as the value of the statement.
2. The method according to claim 1, characterized in that, The step of requesting data from the test interface using source data from various dimensions includes: Construct the interface request based on the request source data from each dimension; Use the interface request to obtain the returned data from the test interface.
3. The method according to claim 2, characterized in that, The construction of the interface request based on the request source data of each dimension includes: Extract data from the request source data of the test interface in four dimensions: request header, Uniform Resource Locator (URL), request parameters, and request method. The interface request is constructed using the data from the four dimensions mentioned above.
4. The method according to claim 1, characterized in that, The operator is any one of greater than, greater than or equal to, equal to, not equal to, less than, and less than or equal to.
5. The method according to claim 1, characterized in that, The database configuration source data includes the database type, database address, database port, database account, database password, and string parsing type.
6. An interface testing device, characterized in that, The device includes: The acquisition module is used to acquire request source data for each dimension of the test interface and at least one conditional expression from a pre-configured data source. The data source is a user-pre-configured data-driven file, which includes the configuration content and test content of the test interface. The test content includes test cases, and the test cases contain request source data for each dimension and conditional expressions. The request module is used to request data from the test interface using source data from various dimensions. The assertion module is used to detect the operator in each conditional expression, determine the value of the statements on both sides of the operator in the conditional expression based on the returned data, and compare the values of the statements on both sides based on the operator to obtain the comparison result. The report generation module is used to generate test reports based on the comparison results of each conditional expression; The assertion module is specifically used to determine, for each statement, whether the statement contains a first keyword; if it contains the first keyword, it obtains the preliminary value of the internal statement of the first keyword and calculates the preliminary value using the calculation rule of the first keyword to obtain the value of the statement; if it does not contain the first keyword, it determines whether the statement contains a second keyword; if it contains the second keyword, it obtains the value of the statement based on the second keyword, including: obtaining the execution action corresponding to the second keyword; if the execution action is to obtain database data, it obtains from the statement the target database name, the database query statement, and the data to be obtained after the second keyword. Type; Extract database configuration source data corresponding to the target database name from a pre-configured data source; Establish a connection with the remote database corresponding to the target database name using the database configuration source data, and obtain target data from the remote database as the value of the statement based on the database query statement and the type of data to be obtained; If it does not contain the second keyword, determine whether the string in the statement is the target field in the returned data; If it is the target field, read the data of the target field from the corresponding level in the returned data according to the level of the string as the value of the statement; If it is not the target field, use the string as the value of the statement.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method as described in any one of claims 1-5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps of the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Interface test method, device, equipment and storage medium
CN110990250A
Interface test method and device, computer equipment and storage medium
CN112597020A
