Disclosure of Invention
In view of at least one of the foregoing technical problems, an object of the present invention is to provide a service interface testing method, a computer device, and a storage medium.
In one aspect, an embodiment of the present invention includes a service interface testing method, including:
acquiring a test case, and determining a service request and a query request according to the test case;
sending the service request to the service interface; the service interface responds to the service request and obtains first data from the database query;
receiving the first data returned by the service interface;
sending the query request to the database; the database responds to the query request and queries to obtain second data;
receiving the second data returned by the database;
determining the accuracy of the first data according to the second data;
and determining a test result of the service interface according to the accuracy.
Further, the step of determining the accuracy of the first data according to the second data specifically includes:
performing field comparison on the first data and the second data; the field comparison is used for determining a consistent field and a non-consistent field in the first data and the second data;
and determining the accuracy of the first data according to the number of the consistent fields and the number of the non-consistent fields.
Further, the step of determining the accuracy of the first data according to the number of the consistent fields and the number of the non-consistent fields specifically includes:
determining the accuracy of the first data according to the ratio of the number of the consistent fields to the total number of fields; the total number of fields is the sum of the number of consistent fields and the number of non-consistent fields.
Further, the step of determining the accuracy of the first data according to the number of the consistent fields and the number of the non-consistent fields specifically includes:
determining importance scores of the fields according to the attributes of the fields;
taking the importance scores as weights, determining weighted scores of the consistent fields and the non-consistent fields; the weight of the consistent field is positive number, and the weight of the non-consistent field is negative number;
and determining the accuracy of the first data according to the weighted scores.
Further, the step of determining the test result of the service interface according to the accuracy specifically includes:
and when the accuracy reaches a preset threshold value, determining that the test result of the service interface is passed, otherwise, determining that the test result of the service interface is failed.
Further, the service interface testing method further comprises the following steps:
acquiring a plurality of negative sample test cases; the negative sample test case is a test case which enables the test result of the service interface to be failed;
determining the distribution of the inconsistent fields corresponding to each negative sample test case;
determining the same part of the distribution of each non-uniform field;
determining the fault reason of the service interface;
and determining the mapping relation between the same part and the fault reason.
Further, the service interface testing method further comprises the following steps:
acquiring a plurality of positive sample test cases; the positive sample test case is a test case which enables the test result of the service interface to be passed;
determining the distribution of the inconsistent fields corresponding to each positive sample test case;
determining the same part of the distribution of each non-uniform field;
and carrying out fault detection on the service interface according to the same part.
Further, the step of determining the test result of the service interface according to the accuracy specifically further includes:
when the test result of the service interface is not passed, determining the distribution of the inconsistent fields;
and determining the fault reason of the service interface according to the distribution of the inconsistent fields.
In another aspect, an embodiment of the present invention further includes a computer apparatus including a memory for storing at least one program and a processor for loading the at least one program to perform a service interface testing method.
In another aspect, embodiments of the present invention also include a storage medium having stored therein processor-executable instructions that when executed by a processor are for performing a business interface testing method.
The beneficial effects of the invention are as follows: in the embodiment of the invention, the fault or error of the service interface can be effectively eliminated by comparing the first data with the second data field by field. The accuracy of the first data is determined according to the number of the consistent fields, the number of the non-consistent fields, the importance scores of the consistent fields and the importance scores of the non-consistent fields, so that the interference on the testing process caused by the change of the service interface due to the change of the common module and not affecting the interface function can be ignored, and the stability of the testing process is improved on the basis of ensuring the reliability of the testing result.
Detailed Description
Example 1
In this embodiment, the principle of the service interface testing method is shown in fig. 1. A computer device is used to run a testing tool Jmeter, and the configuration of the Jmeter enables the computer device to run a service interface testing method, i.e. steps S1-S7 in the embodiment.
Referring to fig. 2, the service interface testing method in this embodiment includes the following steps:
s1, acquiring a test case, and determining a service request and a query request according to the test case;
s2, sending the service request to the service interface; the service interface responds to the service request and obtains first data from the database query;
s3, receiving the first data returned by the service interface;
s4, sending the query request to the database; the database responds to the query request and queries to obtain second data;
s5, receiving the second data returned by the database;
s6, determining the accuracy of the first data according to the second data;
s7, determining the test result of the service interface according to the accuracy.
In this embodiment, the first data obtained by calling the service interface may be obtained by executing steps S2 and S3 using the test tool Jmeter. In this embodiment, the first data is the actual result used to test the service interface.
In this embodiment, the second data can be obtained directly from the database by performing steps S4 and S5 using the test tool Jmeter. In this embodiment, the second data is the expected result for testing the traffic interface.
In this embodiment, by using the testing tool Jmeter to perform steps S6 and S7, verification of the first data according to the second data may be achieved, that is, the accuracy of the actual result is determined using the expected result, so as to obtain the test result for the service interface.
In this embodiment, the second data as the expected result is obtained by directly connecting to the database, and the second data may be used to verify the accuracy of the first data obtained by querying the database by the service interface, that is, the test process of the service interface may not depend on the expected result set in the test case, so as to improve the reliability of the test result and the stability of the test process. On the other hand, since the second data serving as the expected result can be obtained directly from the database, the process of setting the expected result can be avoided, so that a large number of test cases can be quickly generated, and the large-scale business interface test can be facilitated.
In this embodiment, as shown in fig. 3, the acquired first data and second data have the same format and are respectively composed of n fields, such as field 1, field 2, … …, field n, and the like. Referring to fig. 4, the consistency of each field may be determined by comparing the fields at the same location in the first data and the second data one by one, that is, comparing field 1 in the first data with field 1 in the second data, comparing field 2 in the first data with field 2 in the second data … …, and comparing field n in the first data with field n in the second data. For example, if field 1 in the first data is identical to field 1 in the second data in content, field 1 belongs to the consistent field, whereas field 1 belongs to the non-consistent field.
In this embodiment, the accuracy of the first data is determined according to the number of consistent fields and the number of non-consistent fields.
In this embodiment, when determining the accuracy of the first data, only the number of consistent fields and the number of non-consistent fields may be considered, that is, the ratio obtained by dividing the number of consistent fields by the total number of fields n may be used as the accuracy of the first data. If the accuracy of the first data obtained by calculation reaches a preset threshold value, the test result of the service interface is passed, otherwise, the test result of the service interface is failed.
In this embodiment, when determining the accuracy of the first data, the number of consistent fields and the number of non-consistent fields may be considered, and the attribute of each field may be considered. In this embodiment, the importance score of each field is determined based on the attribute of each field, including the data described in each field, and the importance score is used as the absolute value of the weight of the field. For a consistent field, its weight is a positive number, i.e., its weight is a positive importance score; for non-uniform fields, their weights are negative numbers, i.e., their weights are negative importance scores. And adding the weights of the fields to obtain a ratio which is used as the accuracy of the first data. If the accuracy of the first data obtained by calculation reaches a preset threshold value, the test result of the service interface is passed, otherwise, the test result of the service interface is failed.
A failure or error of the service interface may cause a change in the content of the data queried by the service interface from the database, so that the content of some or all of the fields in the first data returned by the service interface is different from the content of the corresponding fields of the second data. By comparing the first data with the second data field by field, faults or errors of the service interface can be effectively eliminated. The accuracy of the first data is determined according to the number of the consistent fields, the number of the non-consistent fields, the importance scores of the consistent fields and the importance scores of the non-consistent fields, so that the interference on the testing process caused by the change of the service interface due to the change of the common module and not affecting the interface function can be ignored, and the stability of the testing process is improved on the basis of ensuring the reliability of the testing result.
In this embodiment, the following steps may also be performed:
s8, acquiring a plurality of negative sample test cases; the negative sample test case is a test case which enables the test result of the service interface to be failed;
s9, determining distribution of the inconsistent fields corresponding to each negative sample test case;
s10, determining the same part of the distribution of each non-uniform field;
s11, determining a fault reason of the service interface;
s12, determining the mapping relation between the same part and the fault reason.
The principle of the steps S8-S12 is as follows: a plurality of test cases can be obtained by using one test case each time the steps S1-S7 are executed, so that the steps S1-S7 are executed for a plurality of times. If the test result obtained after each execution of the steps S1-S7 is not passed, the test case used by the execution of the steps S1-S7 is defined as a negative sample test case.
And acquiring a plurality of negative sample test cases, wherein each negative sample test case corresponds to the execution process of one step S1-S7, and the results of the execution processes of the steps S1-S7 are all test results which are not passed. Referring to fig. 5, in this embodiment, m negative sample test cases are obtained, corresponding to m execution procedures of steps S1-S7. The execution of each of steps S1-S7 determines the distribution of one non-uniform field, i.e. where each non-uniform field is located.
Referring to fig. 5, during the execution of the 1 st execution step S1-S7, the distribution of the determined non-uniform fields is (field 3, … … field n-1); during the execution of the 2 nd execution step S1-S7, the determined distribution of non-uniform fields is (field 1, field 3, … … field n-1); … … during the execution of the mth execution step S1-S7, the distribution of the non-uniform fields determined is (field 1, field 2, field 3, … … field n-1). From the distribution of these non-uniform fields, some fields are found in the distribution of all non-uniform fields, i.e. field 3 … … and field n-1, so the same part of the distribution of these non-uniform fields can be determined to be (field 3, … … field n-1).
Since the test results obtained after the m times of execution of steps S1-S7 are failed, the person skilled in the art can determine the cause of the failure of the service interface according to the professional technology. After determining the cause of the fault, a mapping relationship between the same part (field 3, … … field n-1) and the cause of the fault is established.
Based on the execution of steps S8-S12, according to the mapping relationship, if the test result of the service interface is failed in the process of executing steps S1-S7 later, the distribution of the inconsistent fields obtained in the process of executing steps S1-S7 at this time can be analyzed, and if the obtained distribution of the inconsistent fields includes (field 3, … … field n-1), the failure cause can be mapped, so as to determine the failure cause of the service interface, so that a person skilled in the art can quickly and accurately determine the failure existing in the service interface in the later test by using the experience of the previous test.
In this embodiment, the following steps may also be performed:
s13, acquiring a plurality of positive sample test cases; the positive sample test case is a test case which enables the test result of the service interface to be passed;
s14, determining distribution of the inconsistent fields corresponding to each positive sample test case;
s15, determining the same part of the distribution of each non-uniform field;
s16, according to the same part, performing fault detection on the service interface.
In this embodiment, if the test result obtained after each execution of steps S1 to S7 is a pass, the test case used for executing steps S1 to S7 at this time is defined as a positive sample test case.
And acquiring a plurality of positive sample test cases, wherein each positive sample test case corresponds to the execution process of one step S1-S7, and the results of the execution processes of the steps S1-S7 are all the passing test results. Referring to fig. 6, in this embodiment, p positive sample test cases are obtained, corresponding to the execution procedures of p steps S1 to S7. The execution of each of steps S1-S7 determines the distribution of one non-uniform field, i.e. where each non-uniform field is located.
Referring to fig. 6, during the execution of the 1 st execution step S1-S7, the distribution of the determined non-uniform fields is (field 1, field 3 … … field n); in the execution of the 2 nd execution step S1-S7, the distribution of the determined non-uniform fields is (field 1, field 3, … … field n-1, field n); … … during the execution of the p-th execution step S1-S7, the distribution of the non-uniform fields determined is (field 1, field 3, … … field n-1, field n). From the distribution of these non-uniform fields, it is possible to determine that some fields exist in the distribution of all non-uniform fields, i.e., field 1, field 3 … …, and field n, and thus the same part of the distribution of these non-uniform fields is (field 1, field 3 … … field n).
Although the test results obtained after p times of execution of the steps S1-S7 are passed, that is, the performance of the service interface can meet the service requirement, the performance of the service interface may be changed after the working parameters are adjusted due to the change of the content of part of the fields in the first data, that is, the service interface may have hidden trouble that the working process is unstable. By executing the steps S13-S15, the same part of the distribution of the inconsistent fields obtained by executing the steps S1-S7 for multiple times can be extracted, that is, the statistical rule of the data generated in the service interface working process is obtained, and when executing the step S16, the corresponding fault cause of the same part obtained by executing the steps S13-S15 can be determined through the mapping relationship between the same part determined by the step S12 and the fault cause, so that guidance is provided for the person skilled in the art, and the person skilled in the art can directionally check whether the corresponding fault cause actually exists in the service interface, thereby more possibly eliminating or reducing the hidden trouble.
Example 2
In this embodiment, a computer apparatus includes a memory for storing at least one program and a processor for loading the at least one program to perform the service interface test method in embodiment 1.
In this embodiment, a storage medium has stored therein processor-executable instructions that, when executed by a processor, are used to perform the service interface test method in embodiment 1, achieving the same technical effects as described in embodiment 1.
It should be noted that, unless otherwise specified, when a feature is referred to as being "fixed" or "connected" to another feature, it may be directly or indirectly fixed or connected to the other feature. Further, the descriptions of the upper, lower, left, right, etc. used in this disclosure are merely with respect to the mutual positional relationship of the various components of this disclosure in the drawings. As used in this disclosure, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. In addition, unless defined otherwise, all technical and scientific terms used in this example have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in the description of the embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and/or" as used in this embodiment includes any combination of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used in this disclosure to describe various elements, these elements should not be limited by these terms. These terms are only used to distinguish one element of the same type from another. For example, a first element could also be termed a second element, and, similarly, a second element could also be termed a first element, without departing from the scope of the present disclosure. The use of any and all examples, or exemplary language (e.g., "such as") provided herein, is intended merely to better illuminate embodiments of the invention and does not pose a limitation on the scope of the invention unless otherwise claimed.
It should be appreciated that embodiments of the invention may be implemented or realized by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer readable memory. The methods may be implemented in a computer program using standard programming techniques, including a non-transitory computer readable storage medium configured with a computer program, where the storage medium so configured causes a computer to operate in a specific and predefined manner, in accordance with the methods and drawings described in the specific embodiments. Each program may be implemented in a high level procedural or object oriented programming language to communicate with a computer system. However, the program(s) can be implemented in assembly or machine language, if desired. In any case, the language may be a compiled or interpreted language. Furthermore, the program can be run on a programmed application specific integrated circuit for this purpose.
Furthermore, the operations of the processes described in the present embodiments may be performed in any suitable order unless otherwise indicated herein or otherwise clearly contradicted by context. The processes (or variations and/or combinations thereof) described in this embodiment may be performed under control of one or more computer systems configured with executable instructions, and may be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications), by hardware, or combinations thereof, that collectively execute on one or more processors. The computer program includes a plurality of instructions executable by one or more processors.
Further, the method may be implemented in any type of computing platform operatively connected to a suitable computing platform, including, but not limited to, a personal computer, mini-computer, mainframe, workstation, network or distributed computing environment, separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, and so forth. Aspects of the invention may be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, optical read and/or write storage medium, RAM, ROM, etc., such that it is readable by a programmable computer, which when read by a computer, is operable to configure and operate the computer to perform the processes described herein. Further, the machine readable code, or portions thereof, may be transmitted over a wired or wireless network. When such media includes instructions or programs that, in conjunction with a microprocessor or other data processor, implement the steps described above, the invention described in this embodiment includes these and other different types of non-transitory computer-readable storage media. The invention also includes the computer itself when programmed according to the methods and techniques of the present invention.
The computer program can be applied to the input data to perform the functions described in this embodiment, thereby converting the input data to generate output data that is stored to the non-volatile memory. The output information may also be applied to one or more output devices such as a display. In a preferred embodiment of the invention, the converted data represents physical and tangible target terminals, including specific visual depictions of physical and tangible target terminals generated on a display.
The present invention is not limited to the above embodiments, but can be modified, equivalent, improved, etc. by the same means to achieve the technical effects of the present invention, which are included in the spirit and principle of the present invention. Various modifications and variations are possible in the technical solution and/or in the embodiments within the scope of the invention.