CN113760745A - Method and device for generating interface automation test case - Google Patents

Method and device for generating interface automation test case Download PDF

Info

Publication number
CN113760745A
CN113760745A CN202110548400.6A CN202110548400A CN113760745A CN 113760745 A CN113760745 A CN 113760745A CN 202110548400 A CN202110548400 A CN 202110548400A CN 113760745 A CN113760745 A CN 113760745A
Authority
CN
China
Prior art keywords
input parameter
parameter
interface
code
test case
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110548400.6A
Other languages
Chinese (zh)
Other versions
CN113760745B (en
Inventor
阳巍巍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202110548400.6A priority Critical patent/CN113760745B/en
Publication of CN113760745A publication Critical patent/CN113760745A/en
Application granted granted Critical
Publication of CN113760745B publication Critical patent/CN113760745B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明实施例公开了一种接口自动化测试用例生成方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:通过代码扫描的方式确定接口代码发生变化的目标接口;基于JAVA反射机制确定所述目标接口的入参变更类型;根据所述入参变更类型,更新所述目标接口的测试用例。本发明实施例提供的方法通过扫描接口代码确定代码变化的接口,并利用JAVA反射机制确定入参变更类型,从而更新测试用例。该方法能够在接口的入参发生变化时,及时自动更新接口的自动化测试用例,降低了手动维护测试用例覆盖不全带来的风险,提高了接口自动化测试用例的生成效率,进而提高接口的测试效率。

Figure 202110548400

The embodiment of the invention discloses a method and a device for generating an automatic test case of an interface, and relates to the technical field of computers. A specific implementation of the method includes: determining the target interface whose interface code changes by means of code scanning; determining the input parameter change type of the target interface based on the JAVA reflection mechanism; updating the target according to the input parameter change type Test cases for the interface. The method provided by the embodiment of the present invention determines the interface of the code change by scanning the interface code, and uses the JAVA reflection mechanism to determine the input parameter change type, so as to update the test case. The method can automatically update the automatic test case of the interface in time when the input parameters of the interface change, reduce the risk of incomplete coverage of the manual maintenance test case, improve the generation efficiency of the automatic test case of the interface, and then improve the test efficiency of the interface .

Figure 202110548400

Description

Interface automation test case generation method and device
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for generating an interface automation test case.
Background
In the process of the interface automatic test, when the input parameter of the interface is modified, the interface automatic test case also needs to be correspondingly modified or updated so as to ensure the correctness of the interface test.
At present, the mode of modifying or updating the interface automation use case is generally manually maintained, for example, the modified information is obtained through the interface automation use case execution failure report, and related personnel are required to investigate the reason of the interface automation use case support failure; or the related personnel inform the personnel interface access parameters of the maintenance interface automation use case to be modified, and the interface automation use case maintenance is required.
However, manual maintenance of the interface automation use case may result in untimely update of the use case and risk of incomplete coverage of the use case.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for generating an interface automation test case, which can automatically update the interface automation test case in time when an interface entry parameter changes.
In order to achieve the above object, according to an aspect of the embodiments of the present invention, there is provided an interface automation test case generation method, including:
determining a target interface with changed interface codes in a code scanning mode;
determining an ingress change type of the target interface based on a JAVA reflection mechanism;
and updating the test case of the target interface according to the entry change type.
Optionally, the type of participation alteration includes at least one of: adding parameters, deleting parameters and changing parameters.
Optionally, determining a target interface with an interface code changed by means of code scanning includes:
scanning an interface within the range of an interface to be scanned to obtain a code of the interface at the current moment;
judging whether the code of the interface at the current moment is changed relative to the code of the interface at the previous moment;
and if so, determining the interface with the changed code as the target interface.
Optionally, the determining the type of the ingress change of the target interface based on the JAVA reflection mechanism includes:
traversing the business method name of the target interface in the code at the current moment:
acquiring each first input parameter in a code of the service method at the current moment;
judging whether the access parameter of the service method in the code at the last moment comprises the first input parameter; if so, acquiring a first parameter value of the first input parameter in the code at the current moment and a second parameter value of the first input parameter in the code at the last moment, judging whether the first parameter value and the second parameter value are the same, if so, determining that the first input parameter is not changed, and if not, determining that the parameter-entering change type of the first input parameter is a change parameter; otherwise, determining the parameter entering change type of the first input parameter as a newly added parameter;
acquiring each second input parameter in the code of the service method at the last moment, and judging whether the access parameter of the service method in the code at the current moment comprises the second input parameter; if not, determining that the parameter entering change type of the second input parameter is a deletion parameter.
Optionally, the method further comprises:
before judging whether the access parameters of the business method in the code at the last moment comprise the first input parameters, determining the access parameters with the first input parameters as basic types; if the first input parameter is not a reference of a basic type, splitting the first input parameter into a plurality of references of basic types;
before judging whether the access parameters of the business method in the code at the current moment comprise the second input parameters, determining the access parameters of which the second input parameters are basic types; if the second input parameter is not a reference of a basic type, splitting the second input parameter into a plurality of references of basic types.
Optionally, updating the test case of the target interface according to the type of the access change includes:
traversing each business method of the target interface, and updating the test case of the target interface aiming at each input parameter in the business method in the following modes:
when the parameter entering change type of the input parameter is a new parameter, adding the input parameter in each test case of the target interface, and/or adding the test case corresponding to the input parameter in the test case set of the target interface;
when the parameter entering change type of the input parameters is a deletion parameter, deleting the input parameters in each test case of the target interface;
and when the parameter entering change type of the input parameter is a change parameter, changing the numerical value of the input parameter in each test case of the target interface.
Optionally, when the type of the input parameter change is a delete parameter, after deleting the input parameter in each test case of the target interface, the method further includes:
judging whether the updated test case set has repeated test cases;
and if so, deleting the repeated test cases in the updated test case set.
An embodiment of the present invention further provides an interface automation test case generation apparatus, including:
the first determining module is used for determining a target interface with changed interface codes in a code scanning mode;
the second determination module is used for determining the type of the input parameter change of the target interface based on a JAVA reflection mechanism;
and the case updating module is used for updating the test case of the target interface according to the access parameter changing type.
An embodiment of the present invention further provides an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the interface automation test case generation method of the embodiment of the invention.
The embodiment of the invention also provides a computer readable medium, wherein a computer program is stored on the computer readable medium, and when the computer program is executed by a processor, the method for generating the interface automatic test case is realized.
One embodiment of the above invention has the following advantages or benefits: determining a target interface with changed codes in a code scanning mode, analyzing the codes of the target interface based on a JAVA reflection mechanism, determining the entry change type of the target interface, and updating the test case of the target interface according to the entry change type. The embodiment of the invention can automatically update the test case of the interface in time when the interface input parameters are changed so as to ensure the correctness of the interface test.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of a main flow of an interface automation test case generation method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a main flow of another interface automated test case generation method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a main flow of another interface automated test case generation method according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a main flow of still another interface automation test case generation method according to the embodiment of the invention;
FIG. 5 is a schematic diagram of main modules of an interface automation test case generation apparatus according to an embodiment of the present invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 7 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
At present, interface automation is realized and maintained by using technical means such as Test ng (Test Next Generation, open source automation testing framework), Jenkins (a continuous integration tool developed based on Java) and the like. When the input parameters of the interface change, the automatic interface test case cannot be automatically updated in time to verify the correctness of the interface, so that an automatic interface test case generation method is needed, so that the automatic interface test case can be automatically updated in time when the input parameters of the interface change.
Fig. 1 is a method for generating an interface automation test case according to an embodiment of the present invention, as shown in fig. 1, the method includes the following steps:
step S101: and determining a target interface with a changed interface code by a code scanning mode.
In the embodiment of the present invention, the code scanning may be performed by scanning the code of the interface within a preset time interval, that is, scanning the interface code periodically, so as to determine the target interface with the changed interface code.
In an alternative embodiment, as shown in fig. 2, step S101 includes the following steps:
step S201: scanning an interface within the range of an interface to be scanned to acquire a code of the interface at the current moment;
step S202: judging whether the code of the interface at the current moment is changed relative to the code of the interface at the previous moment, if so, executing step S203, otherwise, executing step S204;
step S203: determining an interface with changed codes as a target interface;
step S204: it is determined that there is no interface for which a code change has occurred.
In the embodiment of the invention, the target interface is determined through the change of the interface code at the current moment and the previous moment, wherein the time interval between the current moment and the previous moment can be preset, and the time interval can be the interval for scanning the interface code at regular time, for example, the preset time interval can be 1 millisecond, 1 second, 10 seconds and the like, so that the interface automatic test case can be updated in time, and the test case can be verified in time and feed back problems.
In the embodiment of the invention, the range of the interface to be scanned can be an interface in the automatic interface test range, and can also be an interface of a custom scanning rule in the automatic interface test range. When an interface within the range of the interface to be scanned is scanned, a file (such as a class file) corresponding to the interface can be scanned, so that the code of the interface at the current moment can be acquired. And then comparing the code of the interface at the current moment with the code at the previous moment, if the codes are different, determining the code of the interface to be changed as a target interface, updating the automatic test case of the interface to ensure the correctness of the test of the target interface, and if the codes are the same, determining that the interface with the changed codes does not exist, and not updating the automatic test case of the interface.
In an optional implementation manner, when scanning an interface code within a range of an interface to be scanned, the scanned code of the interface is stored, the code of the interface and the scanning time may be correspondingly stored according to an identifier of the interface, and the codes at two adjacent moments at the current moment and the previous moment are compared, so that whether the code of the interface changes can be determined, to determine whether the interface is a target interface, if so, a test case of the target interface is updated, the stored code of the target interface at the previous moment is deleted, and only the code at the current moment after the test case is updated is stored.
After the target interface with the changed code is determined, in order to verify the correctness of the target interface by automatically updating the test case of the target interface, the change of the input parameter corresponding to the code change needs to be determined.
Step S102: and determining the type of the participating change of the target interface based on a JAVA reflection mechanism.
In an embodiment of the present invention, the type of the participating change includes at least one of: adding parameters, deleting parameters and changing parameters.
In an alternative embodiment, as shown in fig. 3, step S102 includes the following steps:
step S301: traversing the business method name of the target interface in the code at the current moment;
step S302: acquiring each first input parameter of a code of a service method at the current moment;
step S303: judging whether the access parameters of the business method in the code at the last moment comprise first input parameters or not; if not, go to step S304, if yes, go to step S305;
step S304: determining the parameter entering change type of the first input parameter as a newly added parameter;
step S305: acquiring a first parameter value of a first input parameter in a code at the current moment and a second parameter value in the code at the last moment;
step S306: judging whether the first parameter value and the second parameter value are the same, if so, executing step S307, otherwise, executing step S308;
step S307: determining that the parameter entering change type of the first input parameter is not a change parameter;
step S308: and determining the parameter-entering change type of the first input parameter as a change parameter.
In an optional implementation manner, before step S303, the method includes:
determining a first input parameter as a basic type of input parameter; if the first input parameter is not a reference of a base type, splitting the first input parameter into a plurality of references of base types. The input parameter of the basic type may be a parameter having one value, the input parameter of the non-basic type may be a parameter having a plurality of values, and the basic type is, for example, a data type of java. Non-base types such as data types java.lang.object, java.util.list < java.lang.integer >, java.util.list < java.lang.string >, etc.
In the embodiment of the present invention, when determining the entry change type of the target interface, it is necessary to traverse the business method name in the code of the target interface at the current time, such as an acquisition menu (getMenu), and according to the business method name, acquire each first input parameter of the code of the business method at the current time, and when determining the basic type of the first input parameter, perform the determination again, and if the first input parameter is not the basic type, it is necessary to split the first input parameter into the entries of multiple basic types, and perform the determination again. When the judgment is made, judging whether the entry parameter of the service method in the code at the previous moment comprises a first input parameter, setting the first input parameter of the service method named getMenu at the current moment as A, B and C, if the entry parameter of the service method named getMenu at the previous moment comprises A and B, judging that the entry parameter change type of the input parameter C is a new parameter if the entry parameter of the service method at the previous moment does not comprise C, and if the entry parameter of the service method named getMenu at the previous moment comprises A, B, C and D, namely the entry parameter of the service method named getMenu at the previous moment comprises the entry parameter A, B and C at the current moment, further acquiring a first parameter value and a second parameter value corresponding to the first input parameter A, B and C at the current moment and the previous moment respectively, if the first parameter values corresponding to the entry parameter A, B and C at the current moment are 9, 10 and 11 respectively, and if the second parameter values corresponding to the previous-time entry references A, B and C are the same as the first parameter values, determining that the entry-reference change type of the first input parameter is not a changed parameter, and if the second parameter values corresponding to the previous-time entry references A, B and C are 9, 12 and 11 and are different from the first parameter values, determining that the entry-reference change type of the first input parameter is a changed parameter.
In an alternative embodiment, as shown in fig. 4, step S102 further includes the following steps:
step S401: acquiring each second input parameter in the code of the service method at the last moment;
step S402: judging whether the access parameters of the business method in the code at the current moment comprise second input parameters; if not, executing step S403, if yes, executing step S404;
step S403: determining the parameter entering change type of the second input parameter as a deletion parameter;
step S404: and determining that the type of the participation change of the second input parameter is not a deletion parameter.
In the embodiment of the present invention, before step S402, the following steps are further included:
determining the second input parameter as the input parameter of the basic type; if the second input parameter is not a reference of the base type, splitting the second input parameter into a plurality of references of the base types.
After traversing the business method name of the target interface in the code at the current moment, acquiring each second input parameter of the code at the last moment of the business method, before judging the type of the change of the input parameters of the second input parameters, confirming whether each second input parameter is a basic type, and if the second input parameter is not the basic type, splitting the second input parameter into a plurality of basic types and then judging. If the second input parameters of the code of the getMenu business method at the previous moment are A, B, C and D, if the access parameters of the getMenu business method at the current moment are A, B and C, and no access parameter D is included, determining that the access parameter change type of the second input parameters is a deletion parameter, namely deleting the access parameter D from the access parameters of the business method at the current moment, and if the access parameters of the getMenu business method at the current moment are A, B, C, D and E, determining that the access parameter change type of the second input parameters is not the deletion parameter.
When the parameter entering change type of the target interface is judged based on a JAVA reflection mechanism algorithm, whether the parameter entering change type of the first input parameter is a new parameter or a changed parameter can be judged according to each first input parameter in the code at the current moment and the parameter entering comparison at the previous moment, whether the parameter entering change type of the second input parameter is a deleted parameter can be judged according to each second input parameter in the code at the previous moment and the parameter entering comparison at the current moment, and the judgment process is executed aiming at each first input parameter and each second input parameter when the judgment is carried out, so that the parameter entering change type of the target interface can be accurately determined.
Step S103: and updating the test case of the target interface according to the access parameter change type.
In an alternative embodiment, step S103 includes:
traversing each service method of the target interface, and updating the test case of the target interface by the following modes aiming at each input parameter in the service method:
when the parameter entering change type of the input parameters is a new parameter, adding the input parameters in each test case of the target interface, and/or adding the test cases corresponding to the input parameters in the test case set of the target interface;
when the parameter entering change type of the input parameter is a deletion parameter, deleting the input parameter in each test case of the target interface;
and when the parameter input change type of the input parameter is a change parameter, changing the numerical value of the input parameter in each test case of the target interface.
In the embodiment of the invention, the test case of the target interface is updated according to different parameter-entering change types of the input parameters, if the parameter-entering change type is a newly added parameter, the test case is updated according to the type of the newly added parameter, if the newly added parameter is a basic type, the input parameters can be added in the test case, default values of the input parameters are given, and corresponding test cases can also be added at the same time; and if the newly added parameters are not the basic type, adding the input parameters and the test cases in the test case set according to the service logic. If the type of the change of the input parameters is deleting parameters, deleting the input parameters in the test cases, and simultaneously deleting the test cases corresponding to the input parameters; and if the type of the input parameter change is a change parameter, changing the test case according to the value of the input parameter.
For example, after a target interface with a changed code is determined, a JAVA reflection mechanism algorithm is adopted to analyze an entry change type of the target interface to obtain a newly added parameter a and a parameter B, and as shown in table 1, the parameter a and the parameter B are judged to determine that the parameter a is a basic type and the parameter B is a non-basic type, so that the parameter a is automatically added to the automatic test case set of the target interface and a default value of the parameter a is given (for example, the type of the parameter a is String, and the default value is given as null); and performing business logic analysis based on the parameter B, automatically adding the parameter B to the target interface automation test case, and adding a corresponding test case. The business method is named as getMenu business method, parameters A and B are newly added parameters, the parameter A (childrens!) is added in each test case to be a basic type String and is assigned to be a null ("), the parameter B is not a basic type, the numerical values of B are respectively 9, 10 and 11 and can be split into three basic types, and three test cases are added in the test case set according to business logic, so that three test cases are added in the test case set of the business method getMenu, each test case comprises the parameter A and the parameter B, and the updated test case set is obtained, and is shown in Table 1.
TABLE 1
Figure BDA0003074470070000111
In an optional implementation manner, when the type of the parameter change of the input parameter is a delete parameter, after deleting the input parameter in each test case of the target interface, the method further includes:
judging whether the updated test case set has repeated test cases;
and if so, deleting the repeated test cases in the updated test case set.
In the test case set, after deleting one or more input parameters, there may be one or more duplicate test cases, in which case the duplicate test cases need to be deleted. For example, in the test case set of the target interface, there are a parameter a, a parameter B, and a parameter C, if only the value of the parameter C is different in the two test cases, and the other contents are the same, that is, in one of the test cases, the values corresponding to the parameter a, the parameter B, and the parameter C are 9, 10, and 11, respectively, and in the other test case, the values corresponding to the parameter a, the parameter B, and the parameter C are 9, 10, and 12, respectively, when the parameter-in change type of the parameter C is a delete parameter, after deleting the parameter C in the two test cases, the two test cases are the same, and therefore, the same test case needs to be removed to be duplicated to improve the accuracy and efficiency of the test.
In an implementation manner of the embodiment of the present invention, in step S101, when a target interface with changed interface codes is determined by a code scanning manner, a first number of the target interfaces is determined, after a test case of updating the target interface in step S103 is executed, a second number of the target interfaces of the updated test case is obtained, whether the second number is smaller than the first number is determined, if the second number is smaller than the first number, the step S101 is returned to re-determine the first number of the target interfaces, and steps S102 and S103 are continuously executed until the second number is equal to the first number, so that it is determined that all the test cases of the target interfaces are updated, and correctness of the interface test is ensured. For example, when step S101 is executed, the first number of target interfaces is 10, and when step S103 is executed, the second number of target interfaces of the updated test case is 8, and the second number is smaller than the first number, the process returns to re-determine that the first number of target interfaces is 2, and steps S102 and S103 are continuously executed.
The method for generating the interface automatic test case provided by the embodiment of the invention determines a target interface with a changed code in a code scanning mode, analyzes the code of the target interface based on a JAVA reflection mechanism, analyzes and judges each input parameter in the business methods in the code at the current time and the last time by traversing the business methods of the target interface so as to determine the access change type of the target interface, and automatically updates the test case of the target interface according to the access change type. The method can automatically update the test case of the interface in time in a data driving mode when the interface input parameters are changed so as to ensure the correctness of the interface test. The embodiment of the invention reduces the time for manually maintaining the test case, reduces the risk of the online problem caused by incomplete coverage of the manual maintenance test case, improves the generation efficiency of the interface automatic test case, and further improves the test efficiency of the interface.
According to another aspect of the embodiments of the present invention, as shown in fig. 5, there is provided an interface automation test case generation apparatus 500, including:
a first determining module 501, which determines a target interface with a changed interface code in a code scanning manner;
a second determining module 502, configured to determine an ingress change type of the target interface based on a JAVA reflection mechanism;
and the use case updating module 503 updates the test use case of the target interface according to the access parameter changing type.
In this embodiment of the present invention, the first determining module 501 is further configured to: scanning an interface within the range of an interface to be scanned to obtain a code of the interface at the current moment; judging whether the code of the interface at the current moment is changed relative to the code of the interface at the previous moment; and if so, determining the interface with the changed code as the target interface.
In this embodiment of the present invention, the second determining module 502 is further configured to:
traversing the business method name of the target interface in the code at the current moment;
acquiring each first input parameter of a code of a service method at the current moment; judging whether the access parameters of the business method in the code at the last moment comprise first input parameters or not; if so, acquiring a first parameter value of the first input parameter in the code at the current moment and a second parameter value in the code at the last moment, judging whether the first parameter value and the second parameter value are the same, if so, determining that the first input parameter is not changed, and if not, determining that the parameter-entering change type of the first input parameter is a change parameter; otherwise, determining the parameter entering change type of the first input parameter as a newly added parameter;
acquiring each second input parameter in the code of the service method at the last moment, and judging whether the access parameter of the service method in the code at the current moment comprises the second input parameter; if not, determining that the parameter entering change type of the second input parameter is a deletion parameter.
In this embodiment of the present invention, the second determining module 502 is further configured to: before judging whether the access parameters of the business method in the code at the last moment comprise first input parameters, determining the access parameters with the first input parameters as basic types; if the first input parameter is not the entry of the basic type, splitting the first input parameter into a plurality of entries of the basic types;
before judging whether the access parameters of the business method in the code at the current moment comprise the second input parameters, determining the access parameters with the second input parameters as basic types; if the second input parameter is not a reference of the base type, splitting the second input parameter into a plurality of references of the base types.
In this embodiment of the present invention, the use case updating module 503 is further configured to: traversing each service method of the target interface, and updating the test case of the target interface by the following modes aiming at each input parameter in the service method:
when the parameter-entering change type of the input parameters is a new parameter, adding the input parameters in each test case of the target interface, and/or adding the test cases corresponding to the input parameters in the test case set of the target interface;
when the parameter entering change type of the input parameters is a deletion parameter, deleting the input parameters in each test case of the target interface;
and when the parameter input change type of the input parameter is a change parameter, changing the numerical value of the input parameter in each test case of the target interface.
In this embodiment of the present invention, the use case updating module 503 is further configured to: when the type of the input parameter change is a delete parameter, after deleting the input parameter in each test case of the target interface, the method further comprises:
judging whether the updated test case set has repeated test cases;
and if so, deleting the repeated test cases in the updated test case set.
The interface automatic test case generation device provided by the embodiment of the invention can automatically update the test case corresponding to the interface in time when the interface input parameters change, does not need manual maintenance, and avoids the on-line risk of incomplete coverage caused by manual maintenance of the test case.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic apparatus including: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors realize the interface automation test case generation method of the embodiment of the invention.
To achieve the above object, according to a further aspect of the embodiments of the present invention, there is provided a computer readable medium, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the method for generating interface automation test cases according to the embodiments of the present invention.
Fig. 6 illustrates an exemplary system architecture 600 of an interface automated test case generation method or an interface automated test case generation apparatus to which an embodiment of the present invention may be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a server 605. The network 604 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. The terminal devices 601, 602, 603 may have installed thereon various communication client applications, such as a software testing-type application, a web browser application, a search-type application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only).
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a test server (for example only) providing support for software test class applications operated by users with the terminal devices 601, 602, 603. The test server may analyze and perform other processing on the received data such as the request for updating the test case, and feed back a processing result (for example, the updated test case — just an example) to the terminal device.
It should be noted that the interface automation test case generation method provided by the embodiment of the present invention is generally executed by the server 605, and accordingly, the interface automation test case generation apparatus is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a first determination module, a second determination module, and a use case update module. The names of these modules do not in some cases form a limitation on the modules themselves, and for example, the first determination module may also be described as a "module that determines a target interface with a changed interface code by means of code scanning".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: determining a target interface with changed interface codes in a code scanning mode; determining an input parameter change type of a target interface based on a JAVA reflection mechanism; and updating the test case of the target interface according to the access parameter change type.
According to the technical scheme of the embodiment of the invention, the target interface with the changed code is determined in a code scanning mode, the code of the target interface is analyzed based on a JAVA reflection mechanism, the entry-entry change type of the target interface is determined, and the test case of the target interface is updated according to the entry-entry change type. The embodiment of the invention can automatically update the test case of the interface in time when the interface access parameter changes so as to ensure the correctness of the interface test. The embodiment of the invention can reduce the risk of incomplete coverage of the manual maintenance test case, improve the generation efficiency of the interface automatic test case and further improve the test efficiency of the interface.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1.一种接口自动化测试用例生成方法,其特征在于,包括:1. a kind of interface automation test case generation method, is characterized in that, comprises: 通过代码扫描的方式确定接口代码发生变化的目标接口;Determine the target interface where the interface code changes by means of code scanning; 基于JAVA反射机制确定所述目标接口的入参变更类型;Determine the input parameter change type of the target interface based on the JAVA reflection mechanism; 根据所述入参变更类型,更新所述目标接口的测试用例。Update the test case of the target interface according to the input parameter change type. 2.根据权利要求1所述的方法,其特征在于,所述入参变更类型包括以下至少之一:新增参数、删除参数和更改参数。2 . The method according to claim 1 , wherein the input parameter change type includes at least one of the following: adding a parameter, deleting a parameter, and changing a parameter. 3 . 3.根据权利要求1所述的方法,其特征在于,通过代码扫描的方式确定接口代码发生变化的目标接口,包括:3. method according to claim 1, is characterized in that, the target interface that the interface code changes by the mode of code scanning, comprises: 对待扫描接口范围内的接口进行扫描,获得所述接口在当前时刻的代码;Scan the interface within the range of the interface to be scanned to obtain the code of the interface at the current moment; 判断所述接口在当前时刻的代码相对于所述接口在上一时刻的代码是否发生变化;Determine whether the code of the interface at the current moment has changed relative to the code of the interface at the previous moment; 若是,确定代码发生变化的接口为所述目标接口。If so, determine that the interface where the code is changed is the target interface. 4.根据权利要求1所述的方法,其特征在于,所述基于JAVA反射机制确定所述目标接口的入参变更类型,包括:4. The method according to claim 1, wherein the determining the input parameter change type of the target interface based on the JAVA reflection mechanism comprises: 遍历所述目标接口在当前时刻的代码中的业务方法名:Traverse the business method names in the code of the target interface at the current moment: 获取所述业务方法在当前时刻的代码中的每个第一输入参数;Obtain each first input parameter in the code of the business method at the current moment; 判断在上一时刻的代码中所述业务方法的入参是否包括所述第一输入参数;若是,则获取所述第一输入参数在当前时刻的代码中的第一参数值、以及在上一时刻的代码中的第二参数值,判断第一参数值和第二参数值是否相同,若相同,则确定所述第一输入参数未发生变化,若不同,则确定所述第一输入参数的入参变更类型为更改参数;否则,确定所述第一输入参数的入参变更类型为新增参数;Determine whether the input parameter of the business method in the code at the previous moment includes the first input parameter; if so, obtain the first parameter value of the first input parameter in the code at the current moment, and the value of the first input parameter in the code at the previous moment The second parameter value in the code at the moment, to determine whether the first parameter value and the second parameter value are the same, if they are the same, it is determined that the first input parameter has not changed; The input parameter change type is the change parameter; otherwise, it is determined that the input parameter change type of the first input parameter is a new parameter; 获取所述业务方法在上一时刻的代码中的每个第二输入参数,判断在当前时刻的代码中所述业务方法的入参是否包括所述第二输入参数;若否,则确定所述第二输入参数的入参变更类型为删除参数。Obtain each second input parameter in the code of the business method at the previous moment, and determine whether the input parameter of the business method in the code at the current moment includes the second input parameter; if not, determine the The input parameter change type of the second input parameter is delete parameter. 5.根据权利要求4所述的方法,其特征在于,所述方法还包括:5. The method according to claim 4, wherein the method further comprises: 在判断在上一时刻的代码中所述业务方法的入参是否包括所述第一输入参数之前,确定所述第一输入参数为基础类型的入参;若所述第一输入参数不是基础类型的入参,则将所述第一输入参数拆分为多个基础类型的入参;Before judging whether the input parameter of the business method in the code at the previous moment includes the first input parameter, determine that the first input parameter is the input parameter of the basic type; if the first input parameter is not the basic type The input parameter, then the first input parameter is split into a plurality of basic types of input parameters; 在判断在当前时刻的代码中所述业务方法的入参是否包括所述第二输入参数之前,确定所述第二输入参数为基础类型的入参;若所述第二输入参数不是基础类型的入参,则将所述第二输入参数拆分为多个基础类型的入参。Before judging whether the input parameter of the business method in the code at the current moment includes the second input parameter, determine that the second input parameter is the input parameter of the basic type; if the second input parameter is not of the basic type input parameters, the second input parameter is divided into input parameters of multiple basic types. 6.根据权利要求2所述的方法,其特征在于,根据所述入参变更类型,更新所述目标接口的测试用例,包括:6. The method according to claim 2, wherein, according to the input parameter change type, updating the test case of the target interface, comprising: 遍历所述目标接口的每个业务方法,针对所述业务方法中的每个输入参数,通过以下方式更新所述目标接口的测试用例:Traverse each business method of the target interface, and update the test case of the target interface for each input parameter in the business method in the following manner: 当所述输入参数的入参变更类型为新增参数时,则在所述目标接口的每条测试用例中增加所述输入参数,和/或在所述目标接口的测试用例集中增加所述输入参数对应的测试用例;When the input parameter change type of the input parameter is a newly added parameter, the input parameter is added to each test case of the target interface, and/or the input is added to the test case set of the target interface The test case corresponding to the parameter; 当所述输入参数的入参变更类型为删除参数时,删除所述目标接口的每条测试用例中的所述输入参数;When the input parameter change type of the input parameter is a deletion parameter, delete the input parameter in each test case of the target interface; 当所述输入参数的入参变更类型为更改参数时,更改所述目标接口的每条测试用例中所述输入参数的数值。When the input parameter change type of the input parameter is parameter change, the value of the input parameter in each test case of the target interface is changed. 7.根据权利要求6所述的方法,其特征在于,当所述输入参数的入参变更类型为删除参数时,在删除所述目标接口的每条测试用例中的所述输入参数之后,还包括:7. The method according to claim 6, wherein when the input parameter change type of the input parameter is a deletion parameter, after deleting the input parameter in each test case of the target interface, also include: 判断更新后的测试用例集中是否存在重复的测试用例;Determine whether there are duplicate test cases in the updated test case set; 若是,删除更新后的测试用例集中重复的测试用例。If so, delete duplicate test cases from the updated test case set. 8.一种接口自动化测试用例生成装置,其特征在于,包括:8. A device for generating an automated test case for an interface, comprising: 第一确定模块,通过代码扫描的方式确定接口代码发生变化的目标接口;The first determination module determines the target interface whose interface code changes by means of code scanning; 第二确定模块,基于JAVA反射机制确定所述目标接口的入参变更类型;The second determination module determines the input parameter change type of the target interface based on the JAVA reflection mechanism; 用例更新模块,根据所述入参变更类型,更新所述目标接口的测试用例。The use case update module updates the test case of the target interface according to the input parameter change type. 9.一种电子设备,其特征在于,包括:9. An electronic device, characterized in that, comprising: 一个或多个处理器;one or more processors; 存储装置,用于存储一个或多个程序,storage means for storing one or more programs, 当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如权利要求1-7中任一所述的方法。The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1-7. 10.一种计算机可读介质,其上存储有计算机程序,其特征在于,所述程序被处理器执行时实现如权利要求1-7中任一所述的方法。10. A computer-readable medium on which a computer program is stored, characterized in that, when the program is executed by a processor, the method according to any one of claims 1-7 is implemented.
CN202110548400.6A 2021-05-19 2021-05-19 Method and device for generating interface automation test case Active CN113760745B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110548400.6A CN113760745B (en) 2021-05-19 2021-05-19 Method and device for generating interface automation test case

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110548400.6A CN113760745B (en) 2021-05-19 2021-05-19 Method and device for generating interface automation test case

Publications (2)

Publication Number Publication Date
CN113760745A true CN113760745A (en) 2021-12-07
CN113760745B CN113760745B (en) 2025-09-19

Family

ID=78787127

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110548400.6A Active CN113760745B (en) 2021-05-19 2021-05-19 Method and device for generating interface automation test case

Country Status (1)

Country Link
CN (1) CN113760745B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115061918A (en) * 2022-06-20 2022-09-16 中国工商银行股份有限公司 Application interface test method, device, equipment and medium
CN115292159A (en) * 2022-06-29 2022-11-04 望海康信(北京)科技股份公司 Test debugging method and system, corresponding computer equipment and storage medium
CN115794638A (en) * 2022-12-02 2023-03-14 平安银行股份有限公司 Test method, system and computer equipment based on code change analysis engine
CN115904963A (en) * 2022-11-14 2023-04-04 北京商银微芯科技有限公司 Method and device for interface management
CN116257438A (en) * 2023-01-05 2023-06-13 中国电信股份有限公司 Method for updating interface test cases and related equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106250310A (en) * 2016-07-25 2016-12-21 微梦创科网络科技(中国)有限公司 A kind of method for generating test case and device
CN108509337A (en) * 2018-03-15 2018-09-07 链家网(北京)科技有限公司 The dynamic testing method and device called based on interface
CN108595342A (en) * 2018-05-14 2018-09-28 杭州有赞科技有限公司 Unit test method and device
CN109117368A (en) * 2018-07-27 2019-01-01 平安科技(深圳)有限公司 A kind of interface test method, electronic equipment and storage medium
CN110457201A (en) * 2019-06-20 2019-11-15 口碑(上海)信息技术有限公司 A kind of interface testing case generation method and device
CN111198813A (en) * 2018-11-20 2020-05-26 北京京东尚科信息技术有限公司 An interface testing method and device
CN111240967A (en) * 2020-01-03 2020-06-05 北京字节跳动网络技术有限公司 Code generation method and device
CN112100078A (en) * 2020-09-27 2020-12-18 中国建设银行股份有限公司 Method, device and equipment for generating interface test case

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106250310A (en) * 2016-07-25 2016-12-21 微梦创科网络科技(中国)有限公司 A kind of method for generating test case and device
CN108509337A (en) * 2018-03-15 2018-09-07 链家网(北京)科技有限公司 The dynamic testing method and device called based on interface
CN108595342A (en) * 2018-05-14 2018-09-28 杭州有赞科技有限公司 Unit test method and device
CN109117368A (en) * 2018-07-27 2019-01-01 平安科技(深圳)有限公司 A kind of interface test method, electronic equipment and storage medium
CN111198813A (en) * 2018-11-20 2020-05-26 北京京东尚科信息技术有限公司 An interface testing method and device
CN110457201A (en) * 2019-06-20 2019-11-15 口碑(上海)信息技术有限公司 A kind of interface testing case generation method and device
CN111240967A (en) * 2020-01-03 2020-06-05 北京字节跳动网络技术有限公司 Code generation method and device
CN112100078A (en) * 2020-09-27 2020-12-18 中国建设银行股份有限公司 Method, device and equipment for generating interface test case

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115061918A (en) * 2022-06-20 2022-09-16 中国工商银行股份有限公司 Application interface test method, device, equipment and medium
CN115292159A (en) * 2022-06-29 2022-11-04 望海康信(北京)科技股份公司 Test debugging method and system, corresponding computer equipment and storage medium
CN115904963A (en) * 2022-11-14 2023-04-04 北京商银微芯科技有限公司 Method and device for interface management
CN115794638A (en) * 2022-12-02 2023-03-14 平安银行股份有限公司 Test method, system and computer equipment based on code change analysis engine
CN116257438A (en) * 2023-01-05 2023-06-13 中国电信股份有限公司 Method for updating interface test cases and related equipment

Also Published As

Publication number Publication date
CN113760745B (en) 2025-09-19

Similar Documents

Publication Publication Date Title
CN113760745B (en) Method and device for generating interface automation test case
CN111198813A (en) An interface testing method and device
JP7481067B2 (en) Order data processing method and processing device, and computer readable medium
CN110795328A (en) Interface testing method and device
CN111984234A (en) Method and device for processing work order
CN110019158A (en) A kind of method and apparatus of monitoring data quality
CN110895603A (en) Multi-system account information integration method and device
CN114281697A (en) Method and device for generating test data
CN114282506A (en) Certificate generation method, system, electronic device and storage medium
CN114253520B (en) Interface code generation method and device
CN113076186A (en) Task processing method and device, electronic equipment and storage medium
CN113468053B (en) Application system testing method and device
CN115801873A (en) Service distribution method, system, electronic device and storage medium
CN112559233B (en) Method, device, equipment and computer readable medium for identifying fault type
CN110874316B (en) Method, device and system for scanning codes
CN113449228A (en) Page rendering method and device
CN118917784A (en) Method and device for creating work items and electronic equipment
CN115080521B (en) Information display methods, devices, electronic equipment and storage media
CN114218313B (en) Data management method, device, electronic device, storage medium and product
CN113760884B (en) A data comparison method and device
CN113761296B (en) A business processing method and device
CN113448827B (en) A method and device for processing test data
CN114189365A (en) Universal multi-tenant service authorization method and device based on field mapping
CN113220559B (en) A service interface abnormality simulation method, device, system and client
CN112882741A (en) Application management system and method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant