CN116795701A - Method and device for generating universal test case of interface program - Google Patents

Method and device for generating universal test case of interface program Download PDF

Info

Publication number
CN116795701A
CN116795701A CN202310744411.0A CN202310744411A CN116795701A CN 116795701 A CN116795701 A CN 116795701A CN 202310744411 A CN202310744411 A CN 202310744411A CN 116795701 A CN116795701 A CN 116795701A
Authority
CN
China
Prior art keywords
template
test
test template
generating
code
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.)
Pending
Application number
CN202310744411.0A
Other languages
Chinese (zh)
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.)
Jingdong Technology Information Technology Co Ltd
Original Assignee
Jingdong Technology 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 Jingdong Technology Information Technology Co Ltd filed Critical Jingdong Technology Information Technology Co Ltd
Priority to CN202310744411.0A priority Critical patent/CN116795701A/en
Publication of CN116795701A publication Critical patent/CN116795701A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a device for generating a universal test case of an interface program, and relates to the technical field of big data. The specific implementation mode of the method comprises the following steps: acquiring a development code package of an interface program; scanning the development code package, and detecting a preset interface entrance; carding a calling link under a preset interface inlet, determining attribute information of each method included in the calling link, and generating an integrated test template and a unit test template; extracting keywords to be tested according to a preset tag library, and constructing a universal test template; and distributing input parameters which are consistent with the parameter types of the input parameters for each method in the template codes of the universal test template to obtain the universal test case. The implementation mode can meet the full-function test requirement of the development code in any scene, so that the positioning front-end of the abnormal fault can be exposed, the automatic test performance of the interface program is improved, the test and development cost is reduced, the test and development efficiency is improved, and the operation safety of the platform is improved.

Description

Method and device for generating universal test case of interface program
Technical Field
The present invention relates to the field of big data technologies, and in particular, to a method and an apparatus for generating a universal test case of an interface program.
Background
The operation of the platform interface needs to develop, test, repair, online and other processes on each module, and the currently commonly used test frame comprises an automatic test frame and a unit test frame, wherein the automatic test frame is used for testing the whole logic, and the unit test frame is used for testing the logic of a single module.
In the existing automatic test process, a research and development personnel is required to write a script, set a network interaction protocol, request parameters and the like under an automatic test framework, and after the tester performs the whole test, the tester judges whether the interface can be normally called according to a state code returned by the interface; in the existing unit test process, a research and development personnel is required to write a script under a unit test framework, and after the tester executes the unit test of the smallest module, the tester determines whether the module can normally operate according to the test result.
In the process of implementing the present invention, the inventor finds that at least the following problems exist in the prior art:
on one hand, the automatic test cannot find out the tiny hidden faults of the module unit, so that hidden danger is brought to the operation of the platform; on the other hand, once an abnormal fault is found, the test progress is blocked, and a tester and a research and development personnel communicate fault details, a reproduction method and retest, so that the test cost is increased, the repair cost in the test period is far higher than that in the development period, and the development and test efficiency are influenced. On one hand, the unit test needs to be independently developed when the unit test is externally adjusted, so that the development cost is higher; on the other hand, the function of the module needs to be verified by repeatedly adjusting the test parameters, and the parameter adjusting cost for covering all the modules is too high due to the large number of the modules, so that the automation performance of the test is low.
Disclosure of Invention
In view of this, an embodiment of the present invention provides a method and an apparatus for generating a generic test case of an interface program, which can comb an open code, generate a template code of an integrated test template and a unit test template according to a sub-link after splitting each call link and a minimum method unit of each call link, match keywords in the template code according to a preset tag library, revise the template code by using a special processing policy corresponding to the keywords, obtain the generic test case, and combine with input data to generate the generic test case, thereby satisfying the full-function test requirement of a development code in any scenario, so that the positioning front-end of an abnormal fault can be exposed, the automatic test performance of the interface program is improved, the test and development costs are reduced, the test and development efficiency is improved, and the security of platform operation is improved.
To achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a method for generating a generic test case of an interface program, including:
acquiring development code packages of the interface programs;
scanning the development code package, and detecting a preset interface entrance;
carding a calling link under the preset interface entrance, determining attribute information of each method included under the calling link, and generating an integrated test template and a unit test template;
Extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template;
and distributing input parameters which are consistent with parameter types of the input parameters of the method to each method in the template codes of the universal test template, and obtaining the universal test case of the interface program.
Optionally, the extracting the keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template includes:
detecting whether the keywords to be detected which are the same as the keywords of the tag library exist in the template codes of the integrated test template and/or the unit test template according to the tag library;
and under the condition that the keyword to be tested exists in the template codes, revising the template codes of the integrated test template and/or the unit test template according to a special processing strategy corresponding to the keyword to be tested in the tag library, and generating the template codes of the universal test template.
Optionally, the keyword to be tested includes a remote call identifier; revising the template codes of the integrated test template and/or the unit test template according to a special processing strategy corresponding to the keyword to be tested in the tag library, wherein the revising comprises the following steps:
And under the condition that the entering parameters of the main method or the sub-method in the template code are the exiting parameters of the remote calling method, modifying the entering parameters of the main method or the sub-method into simulation parameters with the same parameter types as the exiting parameters of the remote calling method, and generating the test code of the universal test template.
Optionally, the keyword to be tested further comprises a transaction annotation identifier and a distributed lock identifier; revising the template codes of the integrated test template and/or the unit test template according to a special processing strategy corresponding to the keyword to be tested in the tag library, wherein the revising comprises the following steps:
under the condition that the keyword to be detected is a transaction annotation identifier, adding a plurality of codes of forward transactions and reverse transactions corresponding to the transaction annotation identifier into the template code; or alternatively, the process may be performed,
and adding concurrent test notes corresponding to the distributed lock identifier in the template code under the condition that the keyword to be tested is the distributed lock identifier.
Optionally, under the condition that no keyword to be tested exists in the template codes of the integrated test template and/or the unit test template, adding a code of a boundary value checking strategy according to the parameter types of the parameter entering of the main method and/or the sub method in the template codes of the integrated test template and/or the unit test template, and obtaining the test code of the universal test template.
Optionally, the generating the integrated test template includes:
splitting the calling link according to the context dependency relationship of the calling link under the preset interface entrance;
and extracting the method names, the method paths, the input parameters and/or the output parameters of the main method and the sub method included in each sub calling link after splitting, and respectively generating the template codes of the integrated test templates of each sub calling link.
Optionally, the generating unit tests a template, including:
analyzing the context dependency relationship of a calling link under the preset interface entrance, and positioning one or more minimum unit methods of the calling link;
and generating template codes of the unit test templates of the calling link according to the method names, the method paths, the input parameters and/or the output parameters of the minimum unit method.
According to still another aspect of the embodiment of the present invention, there is provided an apparatus for generating a generic test case of an interface program, including:
the acquisition module is used for acquiring development code packages of the interface programs;
the detection module is used for scanning the development code packet and detecting a preset interface entrance;
The generation module is used for carding a calling link under the preset interface entrance, determining attribute information of each method included under the calling link, and generating an integrated test template and a unit test template;
the generating module is also used for extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library to construct a universal test template;
and the combination module is used for distributing input parameters which are consistent with parameter types of the input parameters of the method to each method in the template code of the universal test template, so as to obtain the universal test case of the interface program.
According to another aspect of an embodiment of the present invention, there is provided an electronic device for generating a generic test case of an interface program, including:
one or more processors;
storage means 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 are enabled to realize the method for generating the universal test case of the interface program.
According to still another aspect of the embodiment of the present invention, there is provided a computer readable medium having stored thereon a computer program which when executed by a processor implements a method for generating a generic test case of an interface program provided by the present invention.
One embodiment of the above invention has the following advantages or benefits: because the scanning development code package is adopted, a preset interface entry is detected, a calling link under the preset interface entry is carded, the calling link is split into a plurality of sub-calling links, and the corresponding byte code file is utilized to generate an integrated test template; generating a unit test template by calling a byte code file corresponding to a minimum method unit of a link; searching keywords to be tested in the integrated test template or the unit test template according to the pre-constructed tag library, and revising template codes of the integrated test template or the unit test template through a special processing strategy corresponding to the keywords to be tested to obtain a general test template; the input parameters with the same parameter types as the parameters of the input parameters of each method are distributed to the universal test template to obtain the technical means of the universal test case of the interface program, so that the hidden fault of automation test is overcome, and hidden danger is brought to the platform operation; the test cost is high, and the development and test efficiency is low; the unit test development cost is higher, the parameter adjustment cost of all modules is too high, and the automatic performance of the test is low, so that the technical effects of meeting the full-function test requirement of development codes under any scene, exposing the positioning front of abnormal faults, improving the automatic test performance of an interface program, reducing the test and development cost, improving the test and development efficiency and improving the safety of platform operation are achieved.
Further effects of the above-described non-conventional alternatives are 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 the main flow of a method for generating a generic test case of an interface program according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of the main flow of a method of generating an integrated test template according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main flow of a method of generating unit test templates according to an embodiment of the invention;
FIG. 4 is a schematic diagram of the main flow of a method for generating a generic test template according to an embodiment of the invention;
FIG. 5 is a schematic diagram of the main modules of a generating device of a generic test case of an interface program according to an embodiment of the present invention;
FIG. 6 illustrates an exemplary system architecture diagram of a method for generating a generic test case of an interface program or a device for generating a generic test case of an interface program suitable for application to an embodiment of the present invention;
fig. 7 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered 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.
It should be noted that, in the technical solution of the present disclosure, the related aspects of collecting, updating, analyzing, processing, using, transmitting, storing, etc. of the personal information of the user all conform to the rules of the related laws and regulations, and are used for legal purposes without violating the public order colloquial. Necessary measures are taken for the personal information of the user, illegal access to the personal information data of the user is prevented, and the personal information security, network security and national security of the user are maintained.
Spring frame: a lightweight open source framework in the Java EE programming field realizes the instantiation of the bottom class and the management of the life cycle through the Bean factor of the core. Throughout the framework, various types of functions are abstracted into individual beans, including dynamic loading and facet programming. Spring is comprehensive and modular, has a hierarchical architecture, and can be selected from any isolated part to keep the architecture stable, thereby facilitating the writing of code that is easy to test.
jdk: java Development Kit, a software development kit in the Java language.
MOCK parameters: and a dynamic variable which is artificially simulated in the test process so as to ensure the normal implementation of the test logic.
jdk: java Development Kit, a software development kit in the Java language.
proxy: proxy software or proxy servers may also be considered a network access mode.
RPC: remote Procedure Call, remote procedure call.
Web Service: is a remote invocation technique across programming languages and across operating system platforms.
Transaction consistency: one functional module includes multiple operations, all of which succeed or fail together.
Boundary: the boundary values of the program logic, such as the maximum and minimum values of the integer type.
When in the development stage, the developer can immediately repair when finding the abnormal fault, because the existing automatic test is usually executed after the program development is completed, the repair and test cost is increased, the repair and test efficiency is low, the development efficiency in the development stage cannot be improved, moreover, an automatic test framework (such as a Jmeter) pays attention to the whole logic, the subtle logic which is not executed in the partial test process cannot be found, the hidden abnormal fault is easy to generate, and hidden trouble is brought to the normal operation after the online. On the one hand, when the unit test is externally adjusted, independent development is needed, for example, when the method a calls the method b, if the method b is an external RPC (Remote Procedure Call Protocol, namely remote call) method and the unit test cannot be adjusted locally, an additional MOCK modification is needed to be carried out on the RPC method by using a unit test framework (for example, a Junit), so that the link call of the method a and the method b can be realized, the degree of automation is low, and the development cost is higher; on the other hand, the test cases of the unit test need to repeatedly adjust different test data to verify the functions of the modules, the unit test generally has higher requirements on the test coverage rate of the modules, and repeated parameter adjustment work leads to low automation performance of the unit test.
By the method for generating the universal test case of the interface program, abnormal faults of the interface program are positioned in advance to a development stage, and as a researcher can directly repair the faults, particularly make up the functional defects of the interface program, the integrity and the accuracy of the interface program are improved higher, the testing and the online time of the interface program are shortened, and the testing efficiency and the running stability of a platform are improved.
FIG. 1 is a schematic diagram of the main flow of a method for generating a generic test case of an interface program according to an embodiment of the present invention, as shown in FIG. 1, the method for generating a generic test case of an interface program of the present invention includes the following steps:
in the embodiment of the invention, the method for generating the universal test case of the interface program can be executed through the Spring framework to generate the universal test template of the interface program, and in the subsequent use process, the abnormal fault preposition of the interface program can be exposed, so that the test cost is reduced, and the test efficiency is improved.
Step S101, acquiring development code packages of the interface programs.
In the embodiment of the invention, the development code packages of the interface program under different scenes are acquired, and the scenes can be selectively set according to actual needs, such as a ordering scene, a second killing scene, a payment scene, a purchasing scene and the like. The development code may be in any programming language, such as C language, C++, C#, java, PHP, and the like. Wherein the code package is developed in a compressed package format, such as rar, zip, etc.
Step S102, scanning the development code package, and detecting a preset interface entry.
In the embodiment of the invention, the Spring framework can compile the development code package by utilizing the Java command, and convert the development code package into the compiled code package so as to facilitate the identification, reading and use of the computer.
Further, an interface program is started, a Spring framework uses an interceptor to scan the compiled code packet, and a preset interface entry in the compiled code packet is detected. The preset interface entry may be selectively set as required, for example, the preset interface entry is a jeff interface, and a byte code file beginning with "Class" in a compiled code packet is pre-agreed to be a jeff interface, so that the Spring framework may detect, by using an interceptor, a Class byte code file registered in the jeff interface as the preset interface entry in a packet scanning manner.
In the embodiment of the invention, the interceptor can be a jdk self-carried proxy, invocation-handler mode, and the interceptor is utilized to carry out method enhancement on Class in the compiled code packet to obtain a corresponding Class byte code file.
Further, the byte code file corresponding to the preset interface entry may be stored in a preset memory or cache, so as to facilitate later reading and utilization, for example, the Class byte code file may be stored in the memory or cache, so as to facilitate later reading and use.
Step S103, carding the call link under the preset interface entry, determining attribute information of each method included under the call link, and generating an integrated test template and a unit test template.
In the embodiment of the invention, after detecting a preset interface entry, a Spring framework utilizes a getStackTrace () method provided by jdk to comb a call link in a byte code file corresponding to the preset interface entry, extracts method information of a main method (or called an entry method or class), a sub-method and other methods included in the call link, including a method name, a method path, a parameter entering and/or a parameter exiting and the like, and is used for generating an integrated test template and a unit test template, and as shown in fig. 2, the method for generating the integrated test template comprises the following steps:
step S201, splitting the call link according to the context dependency relationship of the call link under the preset interface entry.
In the embodiment of the invention, the context dependency relationship refers to the dependency relationship between each main method and each sub-method in the code paragraph, and the calling link is split into a plurality of sub-calling links by analyzing the context dependency relationship of the calling link under the preset interface entry, for example, the calling link of the interface program is A- > B- > C- > D, and the split sub-calling link comprises A- > B- > C- > D, B- > C- > D, C- > D.
Step S202, extracting the method names, the method paths, the input parameters and/or the output parameters of the main method and the sub method included in each sub calling link after splitting, and respectively generating the template codes of the integrated test templates of each sub calling link.
In the embodiment of the invention, according to the attribute information of each method included in each split sub-call link, the corresponding byte codes are extracted from the compiled code packet, and the template codes of the integrated test templates of each sub-call link are generated. Wherein the template code is generated by the Spring framework based on the extracted byte code.
Further, in the case where the call link includes only one main method and one sub-method, the split sub-call link is equivalent to the call link.
In the embodiment of the present invention, as shown in fig. 3, the method for generating the unit test template of the present invention includes the following steps:
step S301, analyzing a context dependency relationship of a call link under the preset interface entry, and locating one or more minimum unit methods of the call link.
In the embodiment of the invention, through presetting the context dependency relationship of the call links under the interface entrance, each method included in the call links is analyzed, and one or more minimum unit methods included in each call link are determined, for example, the call links of the interface program are A- > B- > C- > D, and the minimum unit method is D.
Step S302, generating template codes of the unit test templates of the calling link according to the method names, the method paths, the input parameters and/or the output parameters of the minimum unit method.
In the embodiment of the invention, according to the attribute information of each minimum unit method of each calling link, the corresponding byte codes are extracted from the compiled code packet, and the template codes of the unit test templates of each minimum unit method included in the calling link are generated.
In the embodiment of the invention, the integrated test template of the interface program can be generated by the method for generating the integrated test template and the unit test template, scanning the development code package, locating the preset interface entrance therein and carding the attribute information of the main method and the sub method of each calling link under the preset interface entrance, so that the integrated test template of the interface program can be generated by splitting the calling link into the sub calling links and utilizing the attribute information of the method of the sub calling links, and the unit test template of the interface program can be generated by locating the minimum unit method of the calling link and utilizing the attribute information of the minimum unit method, namely, the development code package can be directly analyzed to generate the corresponding test template without writing by a developer one by one, thereby reducing the manpower and time cost of the test and improving the test efficiency.
It should be noted that, the whole logic of the interface program includes a plurality of modules, which can be understood as including one or more sub-methods under one main method, and the same sub-method can be called by different main methods between different interface programs, but there is usually no calling relationship between the main methods. For example, the order placing interface and the purchase adding interface both comprise an article quantity calculating module, namely, the method for calculating the quantity of the articles can be used by the order placing interface or the purchase adding interface.
Further, the main method and the sub method are only examples, and in the actual development stage, the call links can be selectively set after being carded according to the content of the actual development code.
Step S104, extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template.
In the embodiment of the present invention, a keyword requiring special processing and a corresponding special processing policy are stored in a tag library, where the keyword includes a remote call identifier (for example, an identifier of an RPC method, a Web Service method, etc.), a transaction annotation identifier (for example, an @ transaction annotation), a distributed lock identifier (for example, a lock_name), etc., and the corresponding special processing policy includes a lock parameter adjustment policy, a transaction consistency policy, a concurrency test policy, a boundary value check policy, etc., as shown in fig. 4, the method for generating a universal test template of the present invention includes the following steps:
And S401, detecting the template codes of the integrated test templates and the template codes of the unit test templates according to the tag library.
Step S402, determining whether the template code has the same keywords to be tested as the keywords of the tag library, and if so, turning to step S403; if not, go to step S404.
In the embodiment of the invention, the Spring framework respectively detects the template code of the integrated test template and the template code of the unit test template, and determines whether the to-be-tested keywords which are the same as the keywords in the tag library exist in the call link corresponding to the template code.
And step S403, revising the template codes of the integrated test template and the template codes of the unit test template according to the special processing strategy corresponding to the keyword to be tested, and generating the template codes of the universal test template.
In the embodiment of the invention, under the condition that the keywords to be tested exist in the template codes of the integrated test template and the template codes of the unit test template, the template codes of the integrated test template and/or the template codes of the unit test template are revised according to the special processing strategy corresponding to the keywords to be tested in the tag library, so that the template codes of the general test template are generated.
Step S4031, when it is detected that the keyword to be tested in the template code of the integrated test template and/or the unit test template is a remote call identifier, revising the template code of the integrated test template and/or the unit test template by using the mock parameter adjustment strategy to generate a universal test template.
In the embodiment of the invention, the mock call strategy is used for realizing environment isolation and shielding external call. The revising the template codes of the integrated test template and/or the unit test template by utilizing the mock parameter adjustment strategy comprises the following steps:
and under the condition that the entering parameters of the main method or the sub-method in the template code are the exiting parameters of the remote calling method, modifying the entering parameters of the main method or the sub-method into simulation parameters with the same parameter types as the exiting parameters of the remote calling method, and generating the test code of the universal test template. For example, when the Spring framework detects that the RPC method is contained in the calling link of the template code of the integrated test template and/or the unit test template, external calling is shielded, MOCK simulation is performed according to the parameter type of the returned object of the RPC method, and simulation parameters are generated as the parameters of the main method or the sub-method for calling the RPC method in the calling link, so that the external calling is shielded, and the integration test or the unit test is ensured to have no stuck point caused by environment isolation.
Step S4032, when it is detected that the keywords to be tested in the template codes of the integrated test template and/or the unit test template are transaction annotation identifiers, revising the template codes of the integrated test template and/or the unit test template by using a transaction consistency policy, and generating a universal test template.
In the embodiment of the invention, the transaction consistency policy is used for ensuring the consistency of node values of the same node positions of a plurality of transaction nodes. The revising of the template code of the integrated test template and/or the unit test template by utilizing the transaction consistency policy comprises the following steps:
and adding a plurality of codes of forward transactions and reverse transactions corresponding to the transaction annotation identification into the template codes to obtain the test codes of the universal test template. For example, when the Spring framework detects that a transaction annotation identifier appears in a call link of a template code of an integrated test template and/or a unit test template, a plurality of forward transactions and reverse transactions are added in the template code, and in the execution process of a subsequent test case, whether node values at the same node positions of a plurality of transaction nodes have transaction consistency is judged according to the execution results of the forward transactions and the reverse transactions (for example, the execution results of the reverse transactions should be throwing exceptions).
Step S4033, when it is detected that the keyword to be tested in the template code of the integrated test template and/or the unit test template is the distributed lock identifier, revising the template code of the integrated test template and/or the unit test template by using the concurrency test policy, and generating a universal test template.
In the embodiment of the invention, the concurrency test strategy is used for concurrency test of the distributed tasks, and indicates whether the corresponding main method and/or sub-method meets the requirement of multi-user concurrency use. The revising the template codes of the integrated test template and/or the unit test template by utilizing the concurrency test strategy comprises the following steps:
and adding concurrent test notes corresponding to the distributed lock identifiers in the template codes to obtain the test codes of the universal test templates. For example, when the Spring framework detects that the distributed lock identifier appears in the calling link of the template code of the integrated test template and/or the unit test template, the possibility that the corresponding main method and/or sub-method exists in concurrency is indicated, and the corresponding main method and/or sub-method is annotated with concurrency test, so that in the test process, the interface program tests the corresponding main method and/or sub-method in concurrency.
And step S404, adding a code of a boundary value checking strategy according to the parameter types of the main method and/or the sub method in the template codes of the integrated test template and/or the unit test template, and generating the template code of the special test template.
In the embodiment of the invention, under the condition that no keyword to be detected exists in the template code, a boundary value checking strategy which is the same as the parameter type of the input parameter or the output parameter of the method is added for each method in the template code of the integrated test template and/or the unit test template, so that the test code of the universal test template is obtained. For example, when the Spring framework detects that the keyword to be tested does not exist in the calling link of the template code of the integrated test template and/or the unit test template, the corresponding parameter entering boundary VALUE is generated according to the parameter type of the parameter entering of the main method and/or the sub-method in the calling link being INTEGER (INTEGRE), and the parameter entering boundary VALUE can be maximum VALUE (MAX_VALUE) or minimum VALUE (MIN_VALUE).
In the embodiment of the invention, the template codes with special processing strategies in the integrated test template and the unit test template are revised by the generation method of the universal test template, and special conditions such as external adjustment, transaction consistency and concurrent test are independently revised to obtain the perfect universal test template, so that the test requirement of development codes of interface programs in any scene can be met, research and development personnel are liberated, the test efficiency is improved, and the test cost is reduced.
Step S105, input parameters which are consistent with parameter types of the input parameters of the method are distributed for each method in the template codes of the universal test template, and the universal test case of the interface program is obtained.
In the embodiment of the invention, corresponding input parameters are distributed for each main method and/or sub-method according to the parameter types of the input parameters of each main method and/or sub-method in the template codes of the general test template, and the input parameters and the template codes of the general test template are combined to obtain the general test case of the interface program.
In the embodiment of the invention, the development code package of each interface program is obtained; scanning the development code package, and detecting a preset interface entrance; carding a calling link under the preset interface entrance, determining attribute information of each method included under the calling link, and generating an integrated test template and a unit test template; extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template; the method comprises the steps of distributing input parameters which are consistent with parameter types of the input parameters of the method for each method in template codes of a general test template, obtaining general test cases of an interface program and the like, carding the developed codes, generating template codes of an integrated test template and a unit test template according to sub-links after splitting each calling link and minimum method units of each calling link, matching keywords in the template codes according to a preset tag library, revising the template codes by utilizing special processing strategies corresponding to the keywords to obtain the general test cases, combining the general test cases with input data to generate the general test cases, meeting the full-function test requirements of development codes under any scene, thereby exposing the positioning front of abnormal faults, improving the automatic test performance of the interface program, reducing test and development cost, improving test and development efficiency, and improving the operation safety of a platform.
Fig. 5 is a schematic diagram of main modules of a device for generating a generic test case of an interface program according to an embodiment of the present invention, and as shown in fig. 5, a device 500 for generating a generic test case of an interface program according to the present invention includes:
an obtaining module 501, configured to obtain a development code package of each of the interface programs.
And the detection module 502 is configured to scan the development code packet and detect a preset interface entry.
And the generating module 503 is configured to comb a call link under the preset interface entry, determine attribute information of each method included under the call link, and generate an integrated test template and a unit test template.
The generating module 503 is further configured to extract the keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and construct a universal test template.
And the combination module 504 is configured to allocate, to each method in the template code of the universal test template, an input parameter that matches the parameter type of the parameter of the input parameter of the method, so as to obtain a universal test case of the interface program.
In the embodiment of the invention, the full-function test requirement of the development code under any scene can be met through the modules such as the acquisition module, the detection module, the generation module and the combination module, so that the positioning front of the abnormal fault can be exposed, the automatic test performance of the interface program is improved, the test and development cost is reduced, the test and development efficiency is improved, and the running safety of the platform is improved.
Fig. 6 shows an exemplary system architecture diagram of a generating method of a general-purpose test case of an interface program or a generating apparatus of a general-purpose test case of an interface program, which is suitable for application to an embodiment of the present invention, as shown in fig. 6, the exemplary system architecture of a generating method of a general-purpose test case of an interface program or a generating apparatus of a general-purpose test case of an interface program, of an embodiment of the present invention, includes:
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 is used as a medium to provide communication links between the terminal devices 601, 602, 603 and the server 605. The network 604 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 605 via the network 604 using the terminal devices 601, 602, 603 to receive or send messages, etc. Various communication client applications, such as a test case class application, a shopping class application, a web browser application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc., may be installed on the terminal devices 601, 602, 603.
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server providing support for a test case type website browsed by a user using the terminal devices 601, 602, 603. The background management server may analyze and process the received data such as the development code of the interface program, and may feed back the processing result (the general test case of the interface program) to the terminal devices 601, 602, 603.
It should be noted that, the method for generating the universal test case of the interface program provided in the embodiment of the present invention is generally executed by the server 605, and accordingly, the device for generating the universal test case of the interface program 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.
Fig. 7 is a schematic structural diagram of a computer system suitable for use in implementing a terminal device or a server according to an embodiment of the present invention, and as shown in fig. 7, a computer system 700 of a terminal device or a server according to an embodiment of the present invention includes:
a Central Processing Unit (CPU) 701, which can execute various appropriate actions and processes according to 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 RAM703, various programs and data required for the operation of the system 700 are also stored. The CPU701, ROM702, and RAM703 are connected to each other through 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 section 706 including a keyboard, a mouse, and the like; an output portion 707 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 708 including a hard disk or 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. The 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 therefrom is mounted into the storage section 708 as necessary.
In particular, according to embodiments of the present disclosure, the processes described above with reference to 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 shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 709, and/or installed from the removable medium 711. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 701.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any 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 context of this document, 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, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. 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 flowcharts 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 involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: the processor comprises an acquisition module, a detection module, a generation module and a combination module. The names of these modules do not limit the module itself in some cases, for example, a combination module may also be described as "a module that assigns input parameters corresponding to parameter types of the parameters of the method to each method in the template code of the generic test template, and obtains a generic test case of the interface program".
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 present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: acquiring development code packages of the interface programs; scanning the development code package, and detecting a preset interface entrance; carding a calling link under the preset interface entrance, determining attribute information of each method included under the calling link, and generating an integrated test template and a unit test template; extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template; and distributing input parameters which are consistent with parameter types of the input parameters of the method to each method in the template codes of the universal test template, and obtaining the universal test case of the interface program.
According to the technical scheme of the embodiment of the invention, the characteristics of the automatic test framework and the unit test framework are combined, the method under the calling link is classified by analyzing the development codes, the calling link is split to construct an integrated test template, the minimum method unit is positioned to construct the unit test template, and the universal test template of the interface program is generated after revising by utilizing a special processing strategy according to the keywords in the template codes, so that abnormal faults can be exposed in the development period in advance, the automatic efficiency of the test is ensured, the interface online flow is shortened, the influence of interface development on the platform is reduced, and the safe operation of the platform is ensured.
Further, in the development stage, the method for generating the universal test case of the interface program directly generates and executes the universal test case of each interface program to be on-line, thereby exposing and leading the abnormal faults of the interface program to the development stage, the research and development personnel can immediately revise the abnormal faults without subsequent complex processes such as communication, reproduction, retesting and the like, greatly reducing the test cost and the development cost of the test case, directly realizing the integrated test and the full coverage of the unit test without repeatedly developing the test case of each unit module, having strong automatic execution capability and positioning any tiny abnormal faults at the same time, and ensuring the stability and the safety of the interface program.
Or the method for generating the universal test case of the interface program can be applied to other stages such as a test stage and the like, and the universal test case can be selected according to the requirement.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (10)

1. A method for generating a generic test case for an interface program, comprising:
acquiring development code packages of the interface programs;
scanning the development code package, and detecting a preset interface entrance;
carding a calling link under the preset interface entrance, determining attribute information of each method included under the calling link, and generating an integrated test template and a unit test template;
extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template;
and distributing input parameters which are consistent with parameter types of the input parameters of the method to each method in the template codes of the universal test template, and obtaining the universal test case of the interface program.
2. The method according to claim 1, wherein the extracting the keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library, and constructing a universal test template, includes:
detecting whether the keywords to be detected which are the same as the keywords of the tag library exist in the template codes of the integrated test template and/or the unit test template according to the tag library;
And under the condition that the keyword to be tested exists in the template codes, revising the template codes of the integrated test template and/or the unit test template according to a special processing strategy corresponding to the keyword to be tested in the tag library, and generating the template codes of the universal test template.
3. The method of claim 2, wherein the keyword to be tested comprises a remote call identifier; revising the template codes of the integrated test template and/or the unit test template according to a special processing strategy corresponding to the keyword to be tested in the tag library, wherein the revising comprises the following steps:
and under the condition that the entering parameters of the main method or the sub-method in the template code are the exiting parameters of the remote calling method, modifying the entering parameters of the main method or the sub-method into simulation parameters with the same parameter types as the exiting parameters of the remote calling method, and generating the test code of the universal test template.
4. The method of claim 2, wherein the key to be tested further comprises a transaction annotation identifier and a distributed lock identifier; revising the template codes of the integrated test template and/or the unit test template according to a special processing strategy corresponding to the keyword to be tested in the tag library, wherein the revising comprises the following steps:
Under the condition that the keyword to be detected is a transaction annotation identifier, adding a plurality of codes of forward transactions and reverse transactions corresponding to the transaction annotation identifier into the template code; or alternatively, the process may be performed,
and adding concurrent test notes corresponding to the distributed lock identifier in the template code under the condition that the keyword to be tested is the distributed lock identifier.
5. The method according to claim 2, wherein in the case that no keyword to be tested exists in the template code of the integrated test template and/or the unit test template, adding a code of a boundary value checking strategy according to the parameter type of the parameter of the main method and/or the sub method in the template code of the integrated test template and/or the unit test template, so as to obtain the test code of the universal test template.
6. The method of claim 1, wherein the generating an integrated test template comprises:
splitting the calling link according to the context dependency relationship of the calling link under the preset interface entrance;
and extracting the method names, the method paths, the input parameters and/or the output parameters of the main method and the sub method included in each sub calling link after splitting, and respectively generating the template codes of the integrated test templates of each sub calling link.
7. The method of claim 6, wherein the generating unit tests a template, comprising:
analyzing the context dependency relationship of a calling link under the preset interface entrance, and positioning one or more minimum unit methods of the calling link;
and generating template codes of the unit test templates of the calling link according to the method names, the method paths, the input parameters and/or the output parameters of the minimum unit method.
8. A device for generating a generic test case of an interface program, comprising:
the acquisition module is used for acquiring development code packages of the interface programs;
the detection module is used for scanning the development code packet and detecting a preset interface entrance;
the generation module is used for carding a calling link under the preset interface entrance, determining attribute information of each method included under the calling link, and generating an integrated test template and a unit test template;
the generating module is also used for extracting keywords to be tested in the integrated test template and/or the unit test template according to a preset tag library to construct a universal test template;
and the combination module is used for distributing input parameters which are consistent with parameter types of the input parameters of the method to each method in the template code of the universal test template, so as to obtain the universal test case of the interface program.
9. An electronic device for generating a generic test case for an interface program, comprising:
one or more processors;
storage means for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-7.
10. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-7.
CN202310744411.0A 2023-06-21 2023-06-21 Method and device for generating universal test case of interface program Pending CN116795701A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310744411.0A CN116795701A (en) 2023-06-21 2023-06-21 Method and device for generating universal test case of interface program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310744411.0A CN116795701A (en) 2023-06-21 2023-06-21 Method and device for generating universal test case of interface program

Publications (1)

Publication Number Publication Date
CN116795701A true CN116795701A (en) 2023-09-22

Family

ID=88049143

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310744411.0A Pending CN116795701A (en) 2023-06-21 2023-06-21 Method and device for generating universal test case of interface program

Country Status (1)

Country Link
CN (1) CN116795701A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117992358A (en) * 2024-04-03 2024-05-07 湖南天河国云科技有限公司 Intelligent contract crossing test method and device based on block chain

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117992358A (en) * 2024-04-03 2024-05-07 湖南天河国云科技有限公司 Intelligent contract crossing test method and device based on block chain

Similar Documents

Publication Publication Date Title
CN112104709B (en) Intelligent contract processing method, device, medium and electronic equipment
CN112187558B (en) Data verification method and device and electronic equipment
CN110633200A (en) Method and device for testing intelligent contracts
CN110858172A (en) Automatic test code generation method and device
CN113032244B (en) Interface test method, device, computer system and computer readable storage medium
CN110865889A (en) Method and apparatus for transferring events between components
CN109977012B (en) Joint debugging test method, device, equipment and computer readable storage medium of system
CN116795701A (en) Method and device for generating universal test case of interface program
CN111260336B (en) Service checking method, device and equipment based on rule engine
CN111782526A (en) Interface testing method and device, electronic equipment and storage medium
CN113778897A (en) Automatic test method, device, equipment and storage medium of interface
CN112561690A (en) Method, system, equipment and storage medium for testing credit card staging service interface
CN116483888A (en) Program evaluation method and device, electronic equipment and computer readable storage medium
CN113297081B (en) Execution method and device of continuous integrated pipeline
CN113609014A (en) Interface field checking method and device, storage medium and electronic equipment
CN113360365B (en) Flow test method and flow test system
CN114356745A (en) Software testing method and device, electronic equipment and computer readable storage medium
CN113608996B (en) Mirror image compiling test method, system, device and readable storage medium
CN117992359B (en) Method and device for observing service software and electronic equipment
CN112965910B (en) Automatic regression testing method and device, electronic equipment and storage medium
CN110825438B (en) Method and device for simulating data processing of artificial intelligence chip
CN117435464A (en) Software testing method and device, electronic equipment and computer readable storage medium
CN113190453A (en) User interface testing method, device, server and medium
CN117992359A (en) Method and device for observing service software and electronic equipment
CN113326188A (en) Browser testing method and device

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