Interface testing method and device, electronic equipment, storage medium and program product

By extracting the expected results of the interface from the automation script and storing them independently in the database, and using associated identifiers for automated testing and maintenance, the problem of cumbersome manual setting and modification steps in the existing technology is solved, and the testing efficiency and interface logic are improved. Response speed to changes.

CN118656293APending Publication Date: 2024-09-17MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410431479.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-09
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

In automated interface testing, the existing technology requires manual setting of expected results multiple times, resulting in cumbersome steps and low testing efficiency. When the interface logic changes, multiple automated scripts need to be manually modified, affecting maintenance efficiency.

Method used

The expected results of the interface are extracted from the automated scripts and stored independently in the database. They are obtained and updated through associated identifiers to achieve automated testing and rapid maintenance.

Benefits of technology

It reduces the steps of manual settings and modifications, improves testing efficiency and response speed to interface logic changes, avoids manual errors, and improves the intelligence and accuracy of automated testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656293A
    Figure CN118656293A
Patent Text Reader

Abstract

The invention provides an interface testing method and device, electronic equipment, a storage medium and a program product. The method comprises the steps of obtaining a first output parameter and an association identifier of a to-be-tested target interface; obtaining a first expected result of the target interface from a database according to the association identifier; and verifying the first output parameter according to the first expected result to obtain a test result of the target interface. The embodiment of the invention can improve the test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to an interface testing method and device, electronic equipment, storage medium, and program product. Background Art

[0002] When performing automated testing on the interfaces in an application, the output parameters of the interfaces can generally be automatically verified through automated scripts. For example, the output parameters are verified to be correct based on a common simple comparison assertion script. In this method, the expected results of the interface in each automated script need to be manually set. For example, if the assertion is performed 100 times, the expected results need to be manually set 100 times, which results in cumbersome steps and low testing efficiency. Summary of the invention

[0003] The present invention provides an interface testing method and device, electronic equipment, storage medium, and program product.

[0004] In a first aspect, the present disclosure provides an interface testing method, the interface testing method comprising:

[0005] Obtaining a first output parameter and an associated identifier of a target interface to be tested;

[0006] According to the association identifier, obtaining a first expected result of the target interface from a database;

[0007] The first output parameter is verified according to the first expected result to obtain a test result of the target interface.

[0008] In a second aspect, the present disclosure provides an interface testing device, the interface testing device comprising:

[0009] An acquisition unit, used for acquiring a first output parameter and an associated identifier of a target interface to be tested;

[0010] The acquisition unit is further used to acquire the first expected result of the target interface from the database according to the association identifier;

[0011] A verification unit is used to verify the first output parameter according to the first expected result to obtain a test result of the target interface.

[0012] In a third aspect, the present disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the interface testing method of the first aspect mentioned above.

[0013] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the interface testing method of the first aspect when executed by a processor.

[0014] In a fifth aspect, the present disclosure provides a computer program product, comprising a computer-readable code, or a non-volatile computer-readable storage medium carrying a computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the interface testing method of the first aspect described above.

[0015] The interface testing method provided by the embodiment of the present disclosure changes the expected result of the interface from being fixedly set in an automation script to being extracted from an automation script, such as an assertion script, and then stored independently in a database. On the one hand, this makes it possible to not manually set the first expected result of the target interface in the automation script when the target interface needs to be automatically tested, but to obtain the first expected result of the target interface from the database according to the association identifier of the target interface after obtaining the first output parameter of the target interface, so as to verify the first output parameter based on the first expected result and obtain the test result; on the other hand, since the first expected result of the target interface is independently stored in the database, when its value needs to be updated, it is not necessary to manually modify multiple automation scripts using the expected result, but only to update the value of the first expected result stored in the database. In this way, the business logic changes of the target interface can be responded to, the first expected result of the target interface can be quickly maintained, and the target interface can be tested based on the first expected result after the rapid update, which can improve the testing efficiency.

[0016] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings, in which:

[0018] Figure 1 A flowchart of an interface testing method in the related art;

[0019] Figure 2 A flowchart of an interface testing method provided by an embodiment of the present disclosure;

[0020] Figure 3 A schematic block diagram of an interface testing method provided by an embodiment of the present disclosure;

[0021] Figure 4 A block diagram of an interface testing device provided in an embodiment of the present disclosure;

[0022] Figure 5 A block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0023] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0024] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.

[0025] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.

[0026] The terms used herein are only used to describe specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.

[0027] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined as such herein.

[0028] In the technical solution disclosed in this disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals. The use of user data in this technical solution complies with relevant national laws and regulations (for example, the "Information Security Technology Personal Information Security Specification", etc.). For example: corresponding prescribed measures are taken for personal information access control; prescribed restrictions are imposed on the display of personal information; the purpose of using personal information does not exceed the scope of direct or reasonable association; when using personal information, clear identity orientation is eliminated to avoid precise positioning of specific individuals.

[0029] Figure 1 FIG. 1 is a flow chart of an interface testing method in the related art. Figure 1 As shown, in the related art, when performing automated testing on an application programming interface (i.e., API interface, hereinafter referred to as interface) in an application, it generally includes:

[0030] Step S101, setting an automation script, that is, setting an automation script for testing an interface in an automation platform. In this process, the expected result of the interface can be fixedly set in a constant manner in the automation script;

[0031] Step S102, calling the interface, that is, calling the interface by running an automated script to obtain output parameters of the interface;

[0032] Step S103, verify whether the output parameters are correct, for example, through assertion, determine whether the output parameters are correct based on the expected results of the constants; if correct, the assertion passes; otherwise, execute step S104 to determine whether there is a defect (bug) in the interface. If there is a bug in the interface, restart step S101 after fixing the bug. If there is no bug in the interface, it is necessary to execute step S105 to reset the expected result; then, restart step S101.

[0033] For example, the metersphere platform can be used as a test platform. In this platform, the expected results of the interface can be fixedly set in the automation script used to test the target interface; then, the interface is tested using the automation script to run the test data to obtain the actual output parameters of the interface, and the actual output parameters of the interface are verified based on the expected results set in the script.

[0034] In the test method of the related art, the first setting or non-first setting (i.e., resetting) of the expected result of the interface needs to be manually set in the automation platform, such as the automation script page of the metersphere platform, or set in the underlying storage logic of the automation script file; and in the automation test process, there are often multiple automation scripts testing the same interface. In this case, whether it is a method of manually setting the expected result of the interface in the automation script page or a method of setting it in the underlying storage logic, it is necessary to manually operate a large number of automation scripts, which has the problem of cumbersome steps; at the same time, if the expected result is set in the underlying storage logic of the automation script file, it is often necessary to parse the storage process of the automation script file on the platform, which may involve very complex multi-layer nested logic of map objects, with a high error rate. Once an incorrect parsing occurs, it may even cause the original automation script to be unavailable.

[0035] That is, the test methods for interfaces in related technologies often result in low test efficiency due to the complicated steps of maintaining expected results.

[0036] In view of this, in the embodiments of the present disclosure, considering that the storage of expected results can actually be independent of the automation script and does not need to be strongly coupled with the automation script, the present disclosure changes the expected results of the interface from being fixedly set in the automation script to being extracted from the automation script and independently stored in the database. On the one hand, this makes it possible to not manually set the first expected result of the target interface in the automation script when the target interface needs to be automatically tested, but to obtain the first expected result of the target interface from the database according to the association identifier of the target interface after obtaining the first output parameter of the target interface, so as to verify the first output parameter based on the first expected result and obtain the test result; on the other hand, since the first expected result of the target interface is independently stored in the database, when its value needs to be updated, it is not necessary to manually modify multiple automation scripts using the expected result, but only to update the value of the first expected result stored in the database. In this way, the business logic changes of the target interface can be responded to, the first expected result of the target interface can be quickly maintained, and the target interface can be tested based on the first expected result after the rapid update, which can improve the test efficiency.

[0037] Figure 2A flowchart of an interface testing method provided by an embodiment of the present disclosure. The method can be executed by an electronic device such as a terminal device or a server. The terminal device can be a mobile device, a user terminal, a terminal, a computing device, a vehicle-mounted device, etc. The server can be an independent physical server, a server cluster composed of multiple physical servers, or a cloud server capable of cloud computing. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory.

[0038] like Figure 2 As shown, the interface testing method provided by the embodiment of the present disclosure may include the following steps S201-S203, which are described in detail below.

[0039] Step S201: Acquire the first output parameter and the associated identifier of the target interface to be tested.

[0040] In the embodiments of the present disclosure, the target interface may be any interface in the application, for example, it may be a commonly used user login interface in any application system; for example, in a call center system, the target interface may be a speech synthesis interface, a speech recognition interface, etc., which is not specifically limited here.

[0041] The first output parameter may be an output parameter returned by the target interface after the automated script calls the target interface. For example, for a user login interface, its output parameter may include a login authentication result, which is used to indicate whether the login authentication is successful; for another example, for a voice recognition interface, its output parameter may include a recognition result, which is a text obtained after performing text recognition processing on the voice data in the input parameter.

[0042] In some embodiments, the first output parameter may include the value of at least one field. For example, for a user login interface, the first output parameter may only include the value of the login authentication result, and for a voice recognition interface, its output parameter may only include the value of the recognition result. For another example, for a product information acquisition interface, its output parameters may include the values ​​of multiple fields, for example, the values ​​of fields such as product identification, product name, inventory quantity, quantity sold, etc.; for another example, for a loan product acquisition interface, its output parameters may also include the values ​​of multiple fields, for example, the values ​​of multiple fields such as loan product identification, product name, total loan amount, loan details, etc.

[0043] The association identifier can be used to obtain the first expected result of the target interface from the database. The association identifier can be, for example, a use case identifier corresponding to the target interface. The association identifier can also be generated based on other methods, which is not specifically limited here.

[0044] Specifically, in the embodiments of the present disclosure, in order to facilitate the rapid and efficient maintenance of the expected results of the interface, the expected results of the interface can be separated from the automation script corresponding to the interface and stored in a database, which can be a MySQL database, or other databases, such as a redis database, which is not specifically limited here; of course, in some embodiments, the association identifier can also be used to store the target fields that do not participate in the verification in the first output parameter of the target interface in the database, and can also be used to store the first output parameter in the database.

[0045] For example, when the database is a MySQL database, a data table can be set in the MySQL database, and the data table can include fields such as "association identifier" and "expected result". In this way, during the automated testing process, the automated script calls a certain interface to obtain its output parameters. When it is necessary to obtain the expected result of the interface to verify the output parameter, the expected result can be queried from the database based on the association identifier; of course, in actual implementation, the data table can also include other fields, for example, it can include an "actual output parameter" field, and the "actual output parameter" field can be used to store the output parameters actually output by the interface during the automated testing process; in addition, the data table can also include an ignore field, and the ignore field can be used to store the fields in the output parameters of the interface that are not involved in the verification; for example, for the user login interface, its output parameters can include the values ​​of the two fields "authentication result" and "authentication time". Considering that the actual value of the "authentication time" field is often different due to the different times of calling the user login interface during the automated testing process, therefore, when verifying its output parameters, the "authentication time" field can often be set as an ignore field to indicate that the value of this field does not participate in the verification.

[0046] In some embodiments, the first output parameter and the associated identifier can be obtained by running an automated script corresponding to the target interface in an automated platform, such as a metersphere platform, in which the associated identifier of the target interface can be fixedly set, and the automated script obtains the first output parameter output by the target interface by calling the target interface. Of course, in actual implementation, the first output parameter and the associated identifier can also be obtained by other means, which are not specifically limited here.

[0047] Step S202: acquiring a first expected result of the target interface from a database according to the association identifier.

[0048] Step S203: verify the first output parameter according to the first expected result to obtain a test result of the target interface.

[0049] The test result is used to indicate whether the target interface has passed the test. In actual implementation, for example, "1" may be used to indicate a passed test, and "0" may be used to indicate a test failure.

[0050] That is, in the process of performing automated testing on the target interface, after running the automated script to call the target interface, its first output parameter and the associated identifier of the target interface can be obtained, wherein the first output parameter can, for example, be a response variable in a response message of the target interface extracted using a jsonpath expression as the first output parameter; thereafter, the electronic device can obtain the first expected result of the target interface from a database, such as a mysql database, based on the associated identifier; thereafter, based on the first expected result, the first output parameter can be verified to be correct, thereby determining whether the target interface has passed the test.

[0051] It can be seen that based on the interface testing method provided by the embodiment of the present disclosure, by changing the expected result of the interface from being fixedly set in the automation script to being extracted from the automation script, such as the assertion script, and then being independently stored in the database, on the one hand, this makes it possible to not manually set the first expected result of the target interface in the automation script when the target interface needs to be automatically tested, but to obtain the first expected result of the target interface from the database according to the association identifier of the target interface after obtaining the first output parameter of the target interface, so as to verify the first output parameter based on the first expected result and obtain the test result; on the other hand, since the first expected result of the target interface is independently stored in the database, this makes it possible to update its value when it is necessary to manually modify multiple automation scripts using the expected result, but only to update the value of the first expected result stored in the database. In this way, the business logic changes of the target interface can be responded to, the first expected result of the target interface can be quickly maintained, and the target interface can be tested based on the first expected result after the rapid update, which can improve the testing efficiency.

[0052] It should be noted that, in some embodiments, before the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface, the method may also include: determining whether the first expected result is a preset value; when the first expected result is the preset value, updating the first expected result in the database according to the first output parameter and the associated identifier; stopping the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface; when the first expected result is not the preset value, executing the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface.

[0053] The preset value may be, for example, a null value, or may be other numerical values ​​used to indicate that the first expected result is an invalid value, which is not particularly limited here.

[0054] Specifically, in the related art, during the process of automated testing, when the expected result of the interface is set for the first time or reset, it is often necessary to manually confirm the expected result of the interface first, and then manually set the expected result in the automated script as a constant. Not only are the steps cumbersome, but subjective errors may also lead to the setting of incorrect expected results, thereby requiring a large amount of manpower to be invested in the testing process to eliminate the incorrectly set expected results, affecting the testing efficiency.

[0055] In the embodiments of the present disclosure, on the one hand, the expected result of the interface is taken out of the automation script and stored independently in a database, such as a MySQL database, so that when the expected result of the interface needs to be updated, there is no need to manually update the values ​​in each automation script that calls the interface one by one, but it can be achieved by updating the value of the expected result in the database with one click, thereby improving the maintenance efficiency of the expected result; on the other hand, in the embodiments of the present disclosure, there is no need to manually set the expected result of the interface in the database, but the expected result is automatically set during the automated testing process, thereby avoiding the expected result being set incorrectly due to human subjective errors.

[0056] For example, when the target interface is called based on the automated script at time T1 and output parameter 1 is obtained, the first preset result, such as result1, can be obtained from the MySQL database based on the association identifier 1 of the target interface; after obtaining result1, if it is confirmed that result1=null, that is, result1 is empty, then in the embodiment of the present disclosure, the value of the first preset result in the MySQL database can be updated to output parameter 1 according to the association identifier 1, and the current test process can be terminated. Based on this method, the initial setting processing of the first expected result of the target interface can be implemented; in addition, if it is confirmed that result1≠null, that is, result1 is not empty, then in the embodiment of the present disclosure, the output parameter 1 can be verified based on the result1 to obtain the test result of the target interface.

[0057] Of course, when setting the value of the first expected result of the target interface in the database based on the above example, since the first expected result is set based on the output parameter 1 of the actual output of the target interface, when the target interface has a business logic defect, this may cause the first expected result in this case to still be wrong; however, considering that when the target interface has a business logic defect, the output parameters of each output are often different, this makes it possible to call the target interface again based on the automation script at time T2 to obtain output parameter 2, and verify the output parameter 2 based on the first expected result obtained from the MySQL database. Since the first expected result is actually the output parameter 1 of the target interface output at time T1, there will be a difference between the two due to the business logic defect of the target interface, so that the test result will be a test exception; in this case, the tester and the developer can intervene to verify which specific value between the first expected result and the output parameter 2 is correct. If the first expected result is correct, there is no need to reset its value. If the first expected result is wrong, the tester can manually update the first expected result in the MySQL database. For example, after confirming that the output parameter 2 is the correct value, the first expected result can be updated to the output parameter 2.

[0058] It can be seen that based on the method provided by the embodiment of the present disclosure, in the process of automated testing of the target interface, the automated script can automatically set the first expected result with a preset value in the database according to the output parameters obtained by the first call to the target interface, without the need for the tester to manually set the value, thereby making the setting method of the expected result more intelligent.

[0059] In some embodiments, the first output parameter is verified according to the first expected result to obtain the test result of the target interface, including: comparing whether the first expected result matches the first output parameter to determine the test result.

[0060] That is, in the embodiment of the present disclosure, when the first output parameter is verified according to the first expected result, it may be verified whether the first expected result matches the first output parameter.

[0061] For example, it may be determined that the first expected result matches the first output parameter if the two are determined to have exactly the same value.

[0062] Of course, in actual implementation, it is taken into account that the output parameters of the target interface may include text content. For example, when the target interface is a voice recognition interface, its output parameters may include text recognition results for voice data. Considering that the text recognition results are often not exactly the same as the expected results, in some embodiments, when verifying whether the first expected result matches the first output parameter, it is also possible to calculate the similarity between the two. When the similarity is greater than a preset threshold, such as 90%, it is determined that the two match. The similarity can, for example, be the cosine similarity between the first feature vector of the first expected result and the second feature vector of the first output parameter.

[0063] That is, in some embodiments, when comparing whether the first expected result matches the first output parameter, it can include: obtaining a first feature vector of the first expected result, and obtaining a second feature vector of the first output parameter; obtaining the similarity between the first feature vector and the second feature vector; and when the similarity is greater than a preset threshold, determining that the first expected result matches the first output parameter.

[0064] In some embodiments, before comparing whether the first expected result matches the first output parameter and determining the test result, the method may further include: determining a target field in the first output parameter that does not participate in the verification.

[0065] In this embodiment, the comparison of whether the first expected result matches the first output parameter to determine the test result includes: removing the value of the target field in the first output parameter to obtain the second output parameter, and removing the value of the target field in the first expected result to obtain the second expected result; determining the test result based on the second expected result and the second output parameter.

[0066] Referring to the above description, the target field may be a target field in the first output parameter that does not participate in the verification.

[0067] For example, for the user login interface, its output parameter can be in the form of {authentication result, authentication time}, for example, it can be {"success", "xx hours, 53 minutes, xx seconds on x month, 20xx"}. Considering that in the process of automated testing, the authentication time is usually not exactly the same due to the different times of calling the user login interface. Therefore, in order to avoid the automated script from obtaining an erroneous test result of failing the test due to different values ​​of the "authentication time" field when verifying the output parameter based on the expected result, the target field of the target interface can be set to the "authentication time" field. In this way, when verifying the above-mentioned output parameters {"success", "xx hours, 50 minutes, xx seconds on x month, 20xx"} ​​based on the first expected result {"success", "xx hours, 53 minutes, xx seconds on x month, 20xx"} ​​obtained from the database, the values ​​of the "authentication time" fields in the two can be removed first, thereby obtaining the second expected result: {"success"}, and the second output parameter: {"success"}. Afterwards, the two can be compared to see if they match to obtain accurate test results.

[0068] It can be seen that in the embodiment of the present disclosure, in the process of performing automated testing on the target interface, by setting a target field that does not participate in the verification, and based on the target field, removing the numerical value that affects the accuracy of the test result from the first output parameter and the first expected result of the target interface, respectively, the influence of interference elements can be eliminated and the accuracy of the test results can be improved.

[0069] In some embodiments, determining the test result based on the second expected result and the second output parameter includes: determining whether the first value of the first field in the second expected result matches the second value of the first field in the second output parameter; if the first value and the second value do not match, setting the test result to a test exception; otherwise, setting the test result to a test pass.

[0070] That is, after removing the values ​​of the target fields in the first expected result and the first output parameter, when verifying the obtained second output parameter based on the obtained second expected result, it is taken into account that the two may include values ​​of multiple fields. Therefore, in actual implementation, the test result can be determined by determining whether the values ​​in the same field in the two match, for example, whether they are exactly the same or whether the similarity is greater than a preset threshold.

[0071] It can be seen that in the embodiment of the present disclosure, when the first output parameter generated by the target interface during the test process is verified based on the first expected result of the interface in the database, by comparing the values ​​in each identical field in a fine-grained manner one by one to see if they match, it is possible to avoid the possibility of giving incorrect test results due to small local differences when the two are compared as a whole, thereby improving the accuracy of the test results.

[0072] It can be understood that, in some embodiments, when the test result is a test abnormality, the method further includes: generating and storing second prompt information, the second prompt information including the test result.

[0073] The second prompt information, for example, may be assertion prompt information generated by assertion, and the prompt information may be used to prompt the tester that the test result for the target interface is a test exception.

[0074] Of course, if the test result is that the test passes, it can be asserted that it passes. If there are test processes for other interfaces in the automation script, the test can continue for other interfaces, and there is no special limitation here.

[0075] In some embodiments, when the test result is a test exception, the method may also include: determining whether the first expected result is correct; when the first expected result is incorrect, updating the first expected result according to the first output parameter and the associated identifier; when the first expected result is correct, generating and storing first prompt information, the first prompt information including the test result.

[0076] The first prompt information may be assertion prompt information generated in an assertion manner, and the prompt information may be used to prompt the tester that the test result for the target interface is a test exception.

[0077] Specifically, when the test result is a test exception, it is generally that the first expected result does not match the first output parameter actually output by the target interface during the test process, that is, there is a difference between the two; in this case, one possibility is that there is a defect in the target interface, that is, there is an error in the business logic processing. In this case, after the developer fixes the defect, the automated script can be run again to test the target interface; however, there is another possibility that the first expected result stored in the database is incorrect. In this case, the value of the first expected result needs to be reset.

[0078] In the related art, since the expected result of an interface is usually fixed in the form of a constant in each automation script that calls the interface, and since there may usually be multiple automation scripts in the automated testing process, for example, 100 automation scripts all call the same interface, when it is necessary to reset the expected result of the interface, the related art often requires a lot of manpower to manually modify the expected result of the interface in each automation script one by one, which has the problem of cumbersome steps and inconvenience, which often affects the testing efficiency.

[0079] In the embodiment of the present disclosure, since the first expected result of the target interface is separated from the automation script of the target interface based on the association identifier of the target interface and stored separately in a database, such as a MySQL database, when it is necessary to reset the first expected result of the target interface, the first expected result can be quickly achieved by directly updating the first expected result based on the association identifier and the value that needs to be reset.

[0080] When the test result is a test exception, if the developer confirms that there is an error in the first expected result, it usually means that the actual first output parameter of the current target interface is correct. At this time, the value of the first expected result in the database can be updated to the value of the first output parameter.

[0081] For example, for the user login interface, if its corresponding expected result in the database is as shown in Table 1 below:

[0082] Association ID Expected Results … xx1 fail …

[0083] Table 1

[0084] In this case, if the automated script calls the user login interface and extracts its response variable through the Jsonpath expression to obtain the output parameter of the actual output of the interface: {"success"}, then the test result obtained by combining the expected result with the output parameter is a test exception; if the developer confirms that the expected result is set incorrectly, in this case, the expected result can be directly updated based on the output parameter, and the expected result is updated as shown in the following Table 2:

[0085] Association ID Expected Results … xx1 success …

[0086] Table 2

[0087] In this way, the next time the target interface is tested based on the same automated script, the expected result in the database can be guaranteed to be correct. At the same time, when other automated scripts that call the target interface call the target interface, the output parameters of the target interface can be verified by the reset expected result, and accurate test results can also be obtained. It can be seen that in the embodiment of the present disclosure, by taking the expected result of the target interface out of its automated script and storing it independently in the database, the processing speed of resetting the expected result can be improved, thereby improving the test efficiency.

[0088] In some embodiments, after obtaining the first output parameter and the association identifier, the method further includes: when the first output parameter satisfies a first preset condition and the association identifier satisfies a second preset condition, executing the step of obtaining a first expected result of the target interface from the database according to the association identifier.

[0089] The first preset condition may be: the value is not empty; the second preset condition may also be: the value is not empty.

[0090] That is, in actual implementation, since it is necessary to obtain the first preset result based on the association identifier when testing the target interface, and to verify the first output parameter based on the obtained first preset result, after obtaining the first output parameter and the association identifier in step S201, it is necessary to first determine whether the two are empty. If either of the two is empty, since the subsequent verification conditions cannot be performed when either of the two is empty, in this case, the result test process can be directly terminated without executing subsequent steps.

[0091] It should be noted that, in actual implementation, the first preset condition and the second preset condition may also be set according to the output parameters of the target interface and the actual situation of the associated identifier. For example, when the output parameter of the target interface is a text type or an image type, the first preset condition may also be: checking whether the type of the first output parameter is a text type or an image type; when the associated identifier is a non-negative integer, the second preset condition may also be, for example, whether the value is greater than or equal to 0. No special limitation is made here.

[0092] See also Figure 3 , which is a schematic block diagram of the interface testing method provided by the embodiment of the present disclosure. Figure 3 , the interface testing method provided by the embodiment of the present disclosure is schematically illustrated.

[0093] Among them, Figure 3In the example, the target interface is a speech synthesis interface TTS. The input parameter of the TTS interface can be any piece of text. The output parameter of the TTS interface can include fields such as "synstatus", "synaudio" and "syntime", where "synstatus" is the synthesis result, which is used to indicate whether the synthesis process is successful. "Synaudio" is the synthesized speech, which is the speech data obtained after the text in the input parameter is synthesized. "Syntime" is the synthesis time, which can be the generation time of the speech. Of course, this is only for illustrative purposes and is not specifically limited here. In addition, Figure 3 In the example, the automation platform is the metersphere platform, the automation script used for the automated test of the tts interface is the automation script script1 generated in the metersphere platform, and the database is the mysql database as an example for explanation.

[0094] like Figure 3 As shown, step S301 is to generate an automation script for testing a target interface.

[0095] The automation script script1 can be generated in the metersphere platform and used to test the target interface, namely the tts interface.

[0096] The automation script script1 is provided with the association identifier id1 corresponding to the target interface, and the target field not involved in the verification in the output parameter of the target interface can also be set fixedly or by passing in parameters, for example, the target field can be set to the "syntime" field.

[0097] Step S302, running the automation script.

[0098] That is, the target interface is called by running the automation script script1.

[0099] Step S303, obtaining the output parameter and the associated identifier of the target interface, and determining the target field of the target interface;

[0100] As described above, when the target interface is a TTS interface, its output parameter outpara1 may include the values ​​of fields such as "synstatus", "synaudio" and "syntime", for example, it may be in the form of {"success", wav01, "20xx-x-x-day-xx-hour-xx-minute-xx-second"}; the associated identifier id1 may be used at least to obtain the expected result corresponding to the target interface in the MySQL database, and the target field "syntime" and outpara1 may also be stored in the MySQL database as needed.

[0101] Step S304, calling the verification interface to obtain the test result of the target interface.

[0102] Specifically, considering that the verification logic is often universal when testing different interfaces, in order to improve coding efficiency, in the disclosed embodiment, after the automated script calls the interface to obtain the output parameters of the interface, the output parameters and the associated identifier and target field corresponding to the interface can be used as input parameters of the universal verification interface, and the verification interface performs the processing in S202-S203 mentioned above in the disclosed embodiment.

[0103] Specifically, Figure 3 As shown, the check interface may be a rescheck interface, and its input parameters may include outpara1, id1, and "syntime".

[0104] After the input parameters are automatically passed to the verification interface, the following steps can be performed in the verification interface:

[0105] Step S305, determining whether the output parameter is empty and whether the associated identifier is empty;

[0106] That is, the first preset condition and the second preset condition may both be: whether the value is empty.

[0107] Specifically, the verification interface can first verify the input parameters to check whether outpara1 and id1 are both empty. If both are empty, step S306 can be executed to end the verification process. In this case, the automation script can receive the verification information "Verification failed, input parameter is empty" returned by the verification interface and set the test result to a test exception.

[0108] If outpara1 and id1 are not empty, execute step S307 to obtain the expected result.

[0109] That is, if the input parameters are not empty, the expected result result1 of the TTS interface can be obtained from the MySQL database based on id1.

[0110] After obtaining the expected result, execute step S308 to determine whether the expected result is empty;

[0111] If the expected result is empty, execute step S309 to update the expected result; if the expected result is not empty, execute step S310.

[0112] That is, if the expected result of the TTS interface to be tested is not stored in the current MySQL database, in order to improve the test efficiency, the tester does not need to manually set the expected result. Instead, the verification interface referenced by the automation script automatically calls the update interface, and updates the expected result of the TTS interface in MySQL to the value of its current actual output parameter outpara1 according to the associated identifier id1; of course, after setting the expected result, since the expected result and the current outpara1 are often matched, there is no need to verify the two, and the current test process can be ended directly.

[0113] In addition, when the expected result is not empty, the reason why the target interface, that is, the outpara1 of the tts interface is also considered to be stored in the database, for example, stored in the "actual output parameter" field, is to facilitate the test personnel to perform test backtracking; in addition, the target field, that is, the "syntime" field that does not participate in the verification, can also be stored in the database to facilitate the test personnel to perform test backtracking (not shown in the figure).

[0114] Step S310, verifying the output parameters based on the expected results to obtain the test results.

[0115] That is, when the expected result result1 stored in MySQL is not empty, for example, it is {"success", wavxx, "20xx-x-x-day-xx-hour-xx-minute-xx-second"}, you can check whether result1 matches outpara1 to determine whether the test passes.

[0116] Since the input parameters of the verification interface include the target field "syntime", the value of the target field in result1 and outpara1 can be removed to obtain result2: {"success", wavxx}, and outpara2: {"success", wav01}; then, the test result is determined based on result2 and outpara2, for example, by determining whether result2 and outpara2 match.

[0117] It should be noted that, for synstatus, since its value is fixed, that is, either the character string "success" used to indicate successful synthesis, or the character string "fail" used to indicate failed synthesis, therefore, a direct comparison can be made to determine whether the two match; and for wavxx and wav01 in "synaudio", since the two are audio data, it is not convenient to directly compare them, therefore, it can be considered to extract the audio features of the two, and determine whether the two match based on the similarity between the audio features of the two, and no special limitation is made here.

[0118] After step S310, it can also be determined whether the test result is a passed test (not shown in the figure). If the test result is a passed test, a prompt message indicating that the assertion is passed can be generated in the automated script in an assertion manner; if the test result is a test exception, step S311 is executed to determine whether it is a bug; if it is a bug, it means that the expected result is correct, and step S301 can be executed again after the bug is fixed; if it is not a bug, it means that there is an error in the expected result stored in MySQL. In this case, step S312 can be executed to update the expected result according to the associated identifier and output parameters.

[0119] It should be noted that Figure 3 The figure is used to schematically illustrate the interface testing method of the embodiment of the present disclosure. In actual implementation, the target interface may also be any other business interface, for example, it may be a product information acquisition interface, a user login interface, etc., which is not specifically limited here. In addition, when the interface is tested based on the method of the embodiment of the present disclosure, the automation platform may be a metersphere platform, or it may be set as needed, which is not specifically limited here.

[0120] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.

[0121] In addition, the present disclosure also provides an interface testing device, an electronic device, and a computer-readable storage medium, all of which can be used to implement any interface testing method provided by the present disclosure. The corresponding technical solutions and descriptions are referred to the corresponding records in the method part and will not be repeated here.

[0122] Figure 4 A block diagram of an interface testing device provided in an embodiment of the present disclosure.

[0123] Reference Figure 4, an embodiment of the present disclosure provides an interface testing device, the interface testing device 400 includes: an acquisition unit 401 and a verification unit 402.

[0124] The acquisition unit 401 is used to acquire the first output parameter and the associated identifier of the target interface to be tested;

[0125] The acquisition unit 401 is further configured to acquire a first expected result of the target interface from the database according to the association identifier;

[0126] The verification unit 402 is used to verify the first output parameter according to the first expected result to obtain a test result of the target interface.

[0127] In some embodiments, when the verification unit 402 verifies the first output parameter according to the first expected result to obtain the test result of the target interface, it can be used to:

[0128] The first expected result is compared with the first output parameter to determine whether they match, and a test result is determined.

[0129] In some embodiments, the apparatus further includes a determination unit, which may be used to: determine a target field in the first output parameter that does not participate in the verification; in this implementation manner, when comparing whether the first expected result matches the first output parameter and determining the test result, the verification unit 402 may be used to:

[0130] The value of the target field in the first output parameter is removed to obtain a second output parameter, and the value of the target field in the first expected result is removed to obtain a second expected result;

[0131] A test result is determined according to the second expected result and the second output parameter.

[0132] In some embodiments, when the verification unit 402 determines the test result according to the second expected result and the second output parameter, it can be used to:

[0133] Determine whether the first value of the first field in the second expected result matches the second value of the first field in the second output parameter. If the first value and the second value do not match, set the test result to test exception; otherwise, set the test result to test pass.

[0134] In some embodiments, the interface testing device may further include a first judgment unit, which may be used to: when the test result is a test abnormality, determine whether the first expected result is correct; when the first expected result is incorrect, update the first expected result according to the first output parameter and the associated identifier; when the first expected result is correct, generate and store a first prompt information, and the first prompt information includes the test result.

[0135] In some embodiments, the interface testing device may further include a second judgment unit, which may be used to: judge whether the first expected result is a preset value; when the first expected result is a preset value, update the first expected result in the database according to the first output parameter and the associated identifier; send a first control message to the verification unit 402, and the first control message is used to instruct the verification unit 402 to stop executing the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface; when the first expected result is not a preset value, send a second control message to the verification unit 402, and the second control message is used to instruct the verification unit 402 to execute the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface.

[0136] It can be seen that, based on the interface testing device provided by the embodiment of the present disclosure, by changing the expected result of the interface from being fixedly set in the automation script to being extracted from the automation script, such as the assertion script, and then being independently stored in the database, on the one hand, this makes it possible to not manually set the first expected result of the target interface in the automation script when the target interface needs to be automatically tested, but to obtain the first expected result of the target interface from the database according to the association identifier of the target interface after obtaining the first output parameter of the target interface, so as to verify the first output parameter based on the first expected result and obtain the test result; on the other hand, since the first expected result of the target interface is independently stored in the database, this makes it possible to update its value without manually modifying multiple automation scripts using the expected result, but only to update the value of the first expected result stored in the database. In this way, the business logic changes of the target interface can be responded to, the first expected result of the target interface can be quickly maintained, and the target interface can be tested based on the first expected result after the rapid update, thereby improving the testing efficiency.

[0137] Each module in the above interface test device can be implemented in whole or in part by software, hardware and their combination. Each module can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.

[0138] Figure 5 A block diagram of an electronic device provided in an embodiment of the present disclosure.

[0139] Reference Figure 5An embodiment of the present disclosure provides an electronic device, which includes: at least one processor 501; at least one memory 502, and one or more I / O interfaces 503 connected between the processor 501 and the memory 502; wherein the memory 502 stores one or more computer programs that can be executed by the at least one processor 501, and the one or more computer programs are executed by the at least one processor 501 so that the at least one processor 501 can execute the above-mentioned interface testing method.

[0140] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0141] The embodiment of the present disclosure also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the above-mentioned interface testing method when executed by a processor. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.

[0142] The embodiment of the present disclosure also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned interface testing method.

[0143] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).

[0144] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.

[0145] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0146] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0147] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.

[0148] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0149] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0150] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0151] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0152] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present disclosure as set forth in the appended claims.

Claims

1. An interface testing method, characterized in that: include: Obtaining a first output parameter and an associated identifier of a target interface to be tested; According to the association identifier, obtaining a first expected result of the target interface from a database; The first output parameter is verified according to the first expected result to obtain a test result of the target interface.

2. The method according to claim 1, characterized in that The verifying the first output parameter according to the first expected result to obtain the test result of the target interface includes: The first expected result is compared with the first output parameter to determine whether they match, and the test result is determined.

3. The method according to claim 2, characterized in that Before comparing whether the first expected result matches the first output parameter and determining the test result, the method further includes: Determine a target field in the first output parameter that does not participate in the verification; The comparing whether the first expected result matches the first output parameter to determine the test result includes: Removing the value of the target field in the first output parameter to obtain a second output parameter, and removing the value of the target field in the first expected result to obtain a second expected result; The test result is determined according to the second expected result and the second output parameter.

4. The method according to claim 3, characterized in that The step of determining the test result according to the second expected result and the second output parameter includes: Determine whether the first value of the first field in the second expected result matches the second value of the first field in the second output parameter; if the first value and the second value do not match, set the test result to a test exception; otherwise, set the test result to a test pass.

5. The method according to claim 1, characterized in that When the test result is a test abnormality, the method further includes: Determining whether the first expected result is correct; If the first expected result is incorrect, updating the first expected result according to the first output parameter and the association identifier; When the first expected result is correct, first prompt information is generated and stored, where the first prompt information includes the test result.

6. The method according to claim 1, characterized in that After acquiring the first output parameter and the association identifier, the method further includes: When the first output parameter satisfies a first preset condition and the association identifier satisfies a second preset condition, the step of acquiring a first expected result of the target interface from a database according to the association identifier is performed.

7. The method according to claim 1, characterized in that Before the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface, the method further includes: Determining whether the first expected result is a preset value; In the case where the first expected result is the preset value, updating the first expected result in the database according to the first output parameter and the association identifier; stopping the step of verifying the first output parameter according to the first expected result to obtain the test result of the target interface; In a case where the first expected result is not the preset value, the step of verifying the first output parameter according to the first expected result to obtain a test result of the target interface is performed.

8. An interface testing device, characterized in that: include: An acquisition unit, used for acquiring a first output parameter and an associated identifier of a target interface to be tested; The acquisition unit is further used to acquire the first expected result of the target interface from the database according to the association identifier; A verification unit is used to verify the first output parameter according to the first expected result to obtain a test result of the target interface.

9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs executable by the at least one processor, and the one or more computer programs are executed by the at least one processor so that the at least one processor can perform the interface testing method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the interface testing method according to any one of claims 1 to 7.

11. A computer program product, characterized in that It includes computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the interface testing method as described in any one of claims 1 to 7.