CN111522741A - Interface test code generation method and device, electronic equipment and readable storage medium - Google Patents

Interface test code generation method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN111522741A
CN111522741A CN202010289964.8A CN202010289964A CN111522741A CN 111522741 A CN111522741 A CN 111522741A CN 202010289964 A CN202010289964 A CN 202010289964A CN 111522741 A CN111522741 A CN 111522741A
Authority
CN
China
Prior art keywords
test
code
interface
test case
interface test
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
CN202010289964.8A
Other languages
Chinese (zh)
Other versions
CN111522741B (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 QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and 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 QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202010289964.8A priority Critical patent/CN111522741B/en
Publication of CN111522741A publication Critical patent/CN111522741A/en
Application granted granted Critical
Publication of CN111522741B publication Critical patent/CN111522741B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming

Landscapes

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

Abstract

The invention provides an interface test code generation method, an interface test code generation device, electronic equipment and a readable storage medium, wherein the interface test code generation method comprises the following steps: acquiring a test case text of an object to be tested; the test case text comprises an interface test case of an object to be tested; searching a test frame code template matched with the interface test case and a method code template related to the interface test case from the template file; generating an interface test code of an interface test case based on a preset rule; the interface test code comprises a test framework code and a method code; the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain a test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code. The embodiment of the invention can reduce the generation and maintenance cost of the interface test code.

Description

Interface test code generation method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for generating an interface test code, an electronic device, and a readable storage medium.
Background
At present, when generating an interface test code, a test case text is generally required to be repeatedly written, then the interface test code is manually written based on the written test case text, and the interface test code generation process is time-consuming and labor-consuming.
Moreover, different testers have different coding styles, and irregular coding causes poor readability and maintainability of the interface test code at the later stage, and the problem of code redundancy may occur.
Therefore, the generation and maintenance of the interface test code in the prior art have the problem of higher cost.
Disclosure of Invention
The embodiment of the invention provides an interface test code generation method and device, electronic equipment and a readable storage medium, and aims to solve the problem that the cost is high in generation and maintenance of an interface test code in the prior art.
In a first aspect, an embodiment of the present invention provides an interface test code generation method, where the method includes:
acquiring a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file;
generating an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
In a second aspect, an embodiment of the present invention further provides an interface test code generating apparatus, where the apparatus includes:
the acquisition module is used for acquiring a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
the first searching module is used for searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file;
the generating module is used for generating an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
In a third aspect, an embodiment of the present invention further provides an electronic device, which includes a processor, a memory, and a computer program stored on the memory and executable on the processor, where the computer program, when executed by the processor, implements the steps of the interface test code generation method.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the interface test code generation method are implemented.
In the embodiment of the invention, a test case text of an object to be tested is obtained; the test case text comprises an interface test case of the object to be tested; searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file; generating an interface test code of the interface test case based on a preset rule; wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code; the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code. Therefore, the test case text can be automatically analyzed, and the interface test code of the interface test case can be generated, so that the problems of code non-specification and code redundancy of a tester can be solved, the readability and maintainability of the interface test code are improved, and the generation and maintenance cost of the interface test code can be reduced.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive exercise.
FIG. 1 is a flowchart of an interface test code generation method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an interface test code generation application provided by an embodiment of the present invention;
FIG. 3 is a block diagram of an interface test code generation apparatus according to an embodiment of the present invention;
FIG. 4 is a second block diagram of an interface test code generation apparatus according to an embodiment of the present invention;
FIG. 5 is a third block diagram of an interface test code generation apparatus according to an embodiment of the present invention;
FIG. 6 is a fourth block diagram of an interface test code generation apparatus according to an embodiment of the present invention;
fig. 7 is a block diagram of an electronic device provided in the practice of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
First, a method for generating an interface test code according to an embodiment of the present invention is described.
It should be noted that the interface test code generation method provided by the embodiment of the present invention may be applied to an electronic device, where the electronic device may be a terminal device, and is configured to automatically generate an interface test code of an interface test case in a test case file based on a test case file of an object to be tested, so as to achieve the purpose of reducing the generation and maintenance costs of the interface test code.
Referring to fig. 1, fig. 1 is a flowchart of an interface test code generation method provided by an embodiment of the present invention, and as shown in fig. 1, the method includes the following steps:
step 101, obtaining a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
102, searching a test frame code template matched with the interface test case and a method code template associated with the interface test case from a template file;
103, generating an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
In step 101, the object to be tested may be an item, a module of a certain item, a function of a certain module, or only an interface of a certain function, which is not specifically limited herein.
The test case text can be understood as an information carrier which is stored with an interface test case of an object to be tested and exists in a text format; the format of the test case text may be any text format, such as an Excel format.
The test case text of the object to be tested can be obtained in two ways, and the first way can directly obtain the uploaded test case text.
And the second method can automatically generate test case texts based on the input interface test case related information. Specifically, a visual platform may be provided, and testers may fill in relevant information of the interface test case on the visual platform, such as a case name, a case level, a precondition, a verification condition, a test step, test data, a test environment selection, and the like. And after completing filling and clicking for saving, automatically generating a test case text.
Taking a test case text in an Excel format as an example, a rule can be formulated to automatically generate the test case text, for example, the name of the Excel text can correspond to the name of a module, a page in the Excel text can correspond to one function of the module, each column of the page in the Excel text corresponds to a test field of an interface test case corresponding to the function, and each line can correspond to the test field content of an interface test case. Correspondingly, the interface test cases can be automatically divided according to the modules, functions and case identifications, and different interface test cases are stored in fixed Sheet pages of different Excel tables, or stored in different Sheet pages of the same Excel table, or stored in the same Sheet page of the same Excel table.
That is to say, for the object to be tested, the number of the test case texts of the object to be tested may be 1, or may be multiple, and the number of the interface test cases in each test case text may also be 1, or may be multiple, and the specific number may be determined based on the type and scale of the object to be tested, which is not specifically limited herein.
For example, the type of the object to be tested is a module, which includes two functions, each function has two interfaces to be tested, and then a test case text can be generated, the test case text includes two pages, and each page can include a plurality of interface test cases.
The following describes the test case text and each test field in the interface test case in detail.
Excel name: and corresponding to the module name, and generating a path of the test framework code template and the method code template.
Sheet page name: and corresponding to the function name, generating a test frame code template path and a file path of a generation method code template.
And (3) case identification: the interface test case main key is generated by adding the interface Uniform Resource Identifier (URI) and the test level serial number of the interface test case, and is used as a first test parameter to replace a variable parameter which is a case name in the test frame code template.
Interface URI: and the URI of the storage interface is used for generating a case identifier and generating a folder name stored in the test frame code template.
Precondition: the main key name of the rule base is stored, the function is to generate a precondition method in the method to be tested, the corresponding configuration rule can be found in the rule base according to the main key, and then the logic data of the specific data structure is generated.
Testing points and testing steps: the test content of the test case text is stored, and the two test fields are not used in the interface test code generation process, so that a tester can know the effect of the test case text.
And (4) checking conditions: the main key name of the rule base is stored, the method is used for generating a verification condition method in the method to be tested, the corresponding configuration rule can be found in the rule base according to the main key, and then logic data for verifying the correctness of the interface result is generated.
An assertion condition: the content to be checked is stored, which may be the interface specific test field, or the number of data, etc. The method is used for generating the assertion condition in the method to be tested, and the logic of specific assertion can be generated according to the content of the test field.
And (3) testing grade: and storing the level of the interface test case, and matching the test frame code template in the template file according to the test field.
Whether it is monitorable and whether it has been monitored: and fields are reserved, and the connection between the test case of the expansion interface and the monitoring system is realized.
Whether automation is possible: and storing whether the test case text can generate a code template, wherein the test field is a judgment condition for generating the code template.
Generating an automation state: and storing whether the test case text generates the code template or not, wherein the test field is a judgment condition for generating the code template, and the states of the test case text are divided into non-generated automation, generated automation and updating automation.
The online environment may run: storing whether the test case text can be used for generating the on-line environment interface test code or not, wherein the test field is a judgment condition for generating the on-line environment interface test code,
uniform Resource Locator (URL): and storing the interface URL of the test environment of the test case text, wherein the URL is used for analyzing the parameter structure of the test environment of the interface and acquiring a returned result of the interface.
URL _ Online: and storing the URL of the online environment of the test case text, wherein the URL is used for analyzing the parameter structure of the online environment of the interface and acquiring a returned result of the interface.
Interface types are as follows: and storing the interface types of the test case texts, wherein the interface types can be divided into get and post, and the test frame code template can be matched in the template file according to the test fields.
Body: if the interface type is post, the test field needs to be filled in.
Body _ online: if the interface type is post and the online environment is runnable, the test field needs to be filled in.
The writer: the test case text editor is mainly used for storing test case texts and is used for generating comments in the interface test codes, so that a person in charge of the test case text is easy to find.
Case describes: the method mainly stores the description of the test case text, has the function of generating annotations in the interface test code, and is easy to understand the interface test code.
In step 102, according to different test levels and different interface types of the interface test cases, the test frame code templates of the interface test cases are different, and the method to be tested associated with the interface test cases are also different, and correspondingly, the method code templates associated with the interface test cases are also different.
The test frame template can be understood as a main program template of the interface test, the method code template associated with the interface test case can be understood as a subprogram template of the interface test, and when the test frame template runs, the main program of the interface test can call the subprogram of the interface test so as to execute the interface test.
The template file may be a file with extension name yml in the computer programming language Python, which stores the code template in the form of key values and contents. The key value can be the name of interface type information and test grade information assembly, or can also be the name of a method to be tested associated with an interface test case, a character string in a hypertext markup language html format is stored in the content, the content of the character string is a normalized code template, an uncertain part in the code template is occupied by a variable parameter, and the template file supports parameterization, multi-environment operation and flow scene assembly.
The specific implementation of step 102 may be to traverse all Excel tables, circularly read the interface test cases in each Sheet page in the Excel tables, and respectively search the test frame template matched with each interface test case and the method code template associated with the interface test case from the template file. Based on the test grade information, the interface type information and the name of the method to be tested of the interface test case, a test frame code template matched with the interface test case and a method code template related to the interface test case can be searched from a template file.
In step 103, a first variable parameter in the test frame code template may be replaced with a first test parameter associated with the first variable parameter in the interface test case to generate a test frame code based on the test frame code template, and a second variable parameter in the method code template may be replaced with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code from the method code template, and finally obtain the interface test code.
The first test parameter and the second test parameter can be obtained from an interface test case, and the first test parameter can include at least one item of case identification, name of a method to be tested, uniform resource locator information and the like. The second test parameter may include at least one of first logic data generated based on a configuration rule corresponding to the precondition, second logic data generated based on a configuration rule corresponding to the verification condition, expected result information of the interface test, a use case identifier, uniform resource locator information, and the like. In the following examples, each of them will be described in detail.
It should be noted that the method to be tested can be obtained according to the test level in the interface test case, the test level of the interface test case can be divided into two types, the first type can be used for testing whether the interface is available and is defined as a P0 level, and the second type can be used for testing whether the returned result of the interface is correct and is defined as a P1 level. The testing method related to the interface test case of the P0 level comprises a P0 method, and the testing method related to the interface test case of the P1 level comprises a precondition method, a check condition method and an assertion condition method, wherein the precondition method corresponds to a test field which is preconditioned in the interface test case, the check condition method corresponds to a test field which is a check condition in the interface test case, and the assertion condition method corresponds to a test field which is an assertion condition in the interface test case.
The P0 method mainly stores the availability logic of the check interface, and the precondition method mainly realizes the data construction logic of the test code of the interface; the check condition method is mainly a preparation logic for checking the correctness of the result returned by the interface; the assertion condition method is mainly used for verifying and comparing the interface return result with the return result in the verification condition so as to assert whether the return result is correct or not.
In the embodiment, a test case text of an object to be tested is obtained; the test case text comprises an interface test case of the object to be tested; searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file; generating an interface test code of the interface test case based on a preset rule; wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code; the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code. Therefore, the test case text can be automatically analyzed, and the interface test code of the interface test case can be generated, so that the problems of code non-specification and code redundancy of a tester can be solved, the readability and maintainability of the interface test code are improved, and the generation and maintenance cost of the interface test code can be reduced.
And moreover, a visual platform for generating the test case text can be provided, and the test case text can be automatically generated by inputting the relevant information of the test case through the interface, so that the problem of repeated maintenance of the test case text can be solved, and the working efficiency of testers is improved.
Optionally, based on the first embodiment, the method 102 specifically includes:
acquiring target information associated with the interface test case, wherein the target information comprises interface type information, test grade information and a name of a method to be tested;
searching a test frame code template corresponding to the first key value and a method code template corresponding to the second key value in the template file;
the first key value comprises the interface type information and the test grade information; the second key value comprises the name of the method to be tested.
The test case text can be analyzed to obtain the target information associated with the interface test case. Specifically, the interface test case may be obtained from a test case text based on a case identifier, and the content of the interface test case with the test field as the interface type is obtained, so as to obtain the interface type information.
And obtaining the content of the test field in the interface test case as the test level, thereby obtaining the test level information. Further, based on the obtained test grade information, determining the name of the method to be tested associated with the interface test case.
The first key value may be a key value generated by assembling the interface type information and the test level information, and may only include the interface type information and the test level information, and may also include other information, which is not specifically limited herein.
In this embodiment, target information associated with the interface test case is obtained by analyzing the test case text, so that the test frame code template and the method code template can be obtained from the template file based on the target information.
Optionally, to implement the specification storage of the interface test code, based on the first embodiment, before the step 103, the method further includes:
storing the test frame code template into a first folder corresponding to the test frame code template according to a first storage path, and storing the method code template into a second folder corresponding to the method code template according to a second storage path;
the first storage path is generated in a first preset path based on the name of the test case text and the page name of the interface test case in the test case text, and the name of the first folder is determined based on a case identifier associated with the interface test case;
the second storage path is generated in a second preset path based on the name of the test case text, and the name of the second folder is determined based on the page of the test case text.
After the test framework code templates and method code templates are obtained, folder paths for storing interface test codes may be generated. Specifically, each folder path may be generated according to an Excel name, a Sheet name, and an interface URI in the test case text, and includes TestCase, i.e., a storage path of the test frame code template, a storage path of the P0 method code template, a storage path of the precondition method code template, a storage path of the check condition method code template, and a storage path of the assertion condition method code template.
The TestCase is uniformly stored under a path, namely a first preset path, such as/case, other parts are called by specific cases and are placed under a common directory, namely a second preset path, such as/common. Then the memory path for the P0 method code template may be/common/P0 _ method/, the memory path for the preconditioned method code template may be/common/PreConditon/, and so on.
In order to facilitate management of the interface test code, the storage path of the test frame code template, namely the first storage path, is comprehensively considered according to the Excel name and the Sheet name, the path of the interface URI is used as a folder name, and one interface URI is used as a folder for storing the test frame code template. For example, an interface test case is stored in a Sheet1 page under an Excel1 table, and the path of the interface URI is path1, then the storage path of the test framework code template of the interface test case may be/case/Excel 1/Sheet1/test _ path1.py, which may call a precondition method, a check condition method, an assertion condition method, and a P0 method under a public directory.
The specific implementation of the interface test case associated to the method to be tested is stored in the common directory common, and in order to avoid too many folders, the folder name can be named by the name of the Sheet page. For example, the storage path of the P0 method code template is/common/P0 _ method/excel1/sheet1_ P0_ method, the storage path of the precondition method code template is/common/precondidon/pre _ sheet1.py, the storage path of the check condition method code template is/common/verifycodidon/verify _ sheet1.py, and the storage path of the assertion condition method code template is/common/assertotcontion/assertsheet 1. py.
Therefore, the interface test codes of each interface test case all have storage paths belonging to the interface test case, so that the disorder of the interface test codes can be avoided, the interface test codes are kept to be stored neatly, the interface test codes of the interface test cases in the test case text are generated efficiently, the time cost of rear-end testers is saved, and meanwhile, a good basic call is also laid for continuous integration and accurate test.
The specific implementation process of this embodiment is as follows:
and reading an Excel table where the interface test case is located to obtain an Excel name, a Sheet name and an interface URI.
Determining whether a first folder under a first storage path exists or not according to the Excel name and the Sheet name as the storage paths and the interface URI as the folder name; and determining whether a second folder under a second storage path exists or not according to the Excel name as the storage path and the Sheet name as the folder name.
If the storage path and the folder exist, the storage path and the folder do not need to be regenerated.
If the first folder under the first storage path does not exist, the first storage path and the first folder are generated under the first preset path, and the _ init _. py file is generated under the first storage path.
If the second folder under the second storage path does not exist, the corresponding storage path and folder can be generated according to the method to be tested associated with the interface test case. For example, if the to-be-tested method associated with the interface test case is the P0 method, a storage path and a folder of a P0 method code template are generated; if the to-be-tested method associated with the interface test case is a precondition method, a check condition method and an assertion condition method, respectively generating a storage path and a folder of a precondition method code template, checking the storage path and the folder of the precondition method code template, asserting the storage path and the folder of the precondition method code template, and simultaneously generating an _ init _.
After generating each folder path of the interface test code, storing the test frame code template into a first folder corresponding to the test frame code template according to a first storage path, and storing the method code template into a second folder corresponding to the method code template according to a second storage path.
Further, when the test framework code template and the method code template are stored, corresponding storage operation needs to be executed according to the test field for determining whether the interface test case is automatable or not and the test field for generating the automation state.
Under the condition that the interface test case can be automated, a test frame code template matched with the interface test case and a method code template related to the interface test case can be automatically searched from a template file. Under the condition that the interface test case can not be automated, a test frame code template matched with the interface test case can not be searched from the template file.
The automatic generation states of the interface test case can include three states, namely, the automatic generation state and the automatic updating state, which respectively represent the code template which is not generated, the code template which is generated and the code template which is updated.
Specifically, whether the interface test case can be automated or not and whether automation is generated or not is determined, and under the condition that the interface test case cannot be automated or the interface test case is generated and automated, a method code template is searched from a template file based on the name of the method to be tested. And under the condition that the interface test case can be automated and automation is not generated, searching a test frame code template from the template file according to the first key value, and searching a method code template from the template file according to the second key value.
And then, judging whether the interface test code file under the corresponding storage path exists according to the case identifier of the interface test case. And if the test frame code template does not exist, directly storing the test frame code template into a first folder under a first storage path, and storing the method code template into a second folder under a second storage path. If the test frame code template exists, the test frame code template is subjected to replacement updating, and the updating method code template is replaced.
Optionally, after the test frame code template is stored into the first folder corresponding to the test frame code template according to the first storage path and the method code template is stored into the second folder corresponding to the method code template according to the second storage path, the method further includes:
under the condition that the target field content in the interface test case is not a preset value, setting the target field content to be the preset value; when the target field content is the preset value, the fact that the test frame code template exists in the first folder is represented, and the method code template exists in the second folder is represented.
In this embodiment, the target field may be a test field in the interface test case for generating an automation state. After the test frame code template and the method code template are stored, setting the content of the target field to be 'true', representing that the test frame code template exists in the first folder and the method code template exists in the second folder. Therefore, after the interface test is carried out again next time, the code templates of the first folder and the second folder are replaced and updated.
After the test frame code template and the method code template are generated, the content in the interface test case is read, and the variable parameters in the test frame code template and the method code template are replaced by the corresponding test parameters in the interface test case. Different code templates have different implementation functions, and variable parameters contained in the code templates are different.
Optionally, the first test parameter includes at least one of:
identifying a use case;
the name of the method to be tested;
uniform resource locator information.
Optionally, the second test parameter includes at least one of:
generating first logic data based on a configuration rule corresponding to a precondition;
second logic data generated based on the configuration rule corresponding to the verification condition;
expected result information of the interface test;
identifying a use case;
uniform resource locator information.
Uniform resource locator information may include Body and authCookie information, among other information.
And if the method to be tested associated with the interface test case is the P0 method, the second test parameters comprise case identification and uniform resource locator information. If the to-be-tested method associated with the interface test case is a precondition method, a check condition method and an assertion condition method, the second test parameter comprises first logic data generated based on a configuration rule corresponding to the precondition, second logic data generated based on the configuration rule corresponding to the check condition and expected result information of the interface test.
Optionally, the configuration rule corresponding to the precondition and the configuration rule corresponding to the verification condition may be obtained from a preset rule base, the configuration rule in the rule base may be modified, checked and maintained in the visualization platform, the configuration rule is stored in the database, and the database and the related operations depending on the third party (for example, the interface) are stored.
If the to-be-tested method associated with the interface test case comprises a method corresponding to the precondition and a method corresponding to the verification condition;
according to the first embodiment, before the step 103, the method further includes:
and searching a configuration rule corresponding to the precondition in a preset rule base based on a third key value of the precondition, and searching the configuration rule corresponding to the check condition in the preset rule base based on a fourth key value corresponding to the check condition.
The third key value corresponding to the precondition may be the test field content of the precondition in the interface test case, and the fourth key value corresponding to the verification condition may be the test field content of the verification condition in the interface test case.
Therefore, the rule base is maintained through the visual platform, and the configuration rule corresponding to the precondition and the configuration rule corresponding to the check condition are searched in the rule base, so that the correctness of the result returned by the multi-scene and multi-latitude check interface can be realized, and the robustness of the interface is ensured.
It should be noted that, various optional implementations described in the embodiments of the present invention may be implemented in combination with each other or implemented separately, and the embodiments of the present invention are not limited thereto.
In order to better understand the whole process, the following describes in detail the interface test code generation method provided by the embodiment of the present invention with an interface test case of a P1 level as an application scenario. The method comprises the following specific steps:
referring to fig. 2, fig. 2 is a schematic diagram of an interface test code generation application provided in an embodiment of the present invention, and as shown in fig. 2, a visualization platform, a test case text, a rule base, a template file, and an interface test code are required in an interface test code generation process.
Specifically, firstly, a tester can fill in relevant information of an interface test case on a visualization platform, such as a case name, a case level, a precondition, a verification condition, a test step, test data, a test environment selection, and the like. After filling and clicking storage are completed, a test case text is automatically generated, the test case text is an Excel Sheet, and a Sheet page under the Excel Sheet comprises a P1-level interface test case.
Then, analyzing the test case text, and determining whether a first folder under a first storage path exists or not according to the Excel name and the Sheet name as the storage paths and the interface URI as the folder name; and determining whether a second folder under a second storage path exists or not according to the Excel name as the storage path and the Sheet name as the folder name.
If the storage path and the folder exist, the storage path and the folder do not need to be regenerated.
If the first folder under the first storage path does not exist, the first storage path and the first folder are generated under the first preset path, and the _ init _. py file is generated under the first storage path.
If the second folder in the second storage path does not exist, respectively generating a storage path and a folder of the precondition method code template, checking the storage path and the folder of the condition method code template, asserting the storage path and the folder of the condition method code template, and simultaneously generating an _ init _.
And then, determining whether the interface test case can be automated and whether the automation is generated, and searching a method code template from a template file based on the name of the method to be tested under the condition that the interface test case cannot be automated or the automation is generated.
And under the condition that the interface test case can be automated and automation is not generated, searching a test frame code template from the template file according to the first key value, and searching a method code template from the template file according to the second key value.
And then, judging whether the interface test code file under the corresponding storage path exists according to the case identifier of the interface test case. And if the test frame code template does not exist, directly storing the test frame code template into a first folder under a first storage path, and storing the method code template into a second folder under a second storage path. If the test frame code template exists, the test frame code template is subjected to replacement updating, and the updating method code template is replaced.
Then, first test parameters such as case identification, method name to be tested, uniform resource locator information and the like are obtained from the interface test case. And respectively acquiring second test parameters such as first logic data generated based on the configuration rule corresponding to the precondition, second logic data generated based on the configuration rule corresponding to the verification condition, expected result information of the interface test and the like from the interface test case and the rule base. Specifically, based on the third key value corresponding to the precondition, the configuration rule corresponding to the precondition is searched in a rule base, and based on the fourth key value corresponding to the check condition, the configuration rule corresponding to the check condition is searched in the rule base.
The configuration rules of the rule base can be added, deleted, checked and maintained in the visualization platform.
Finally, replacing the first variable parameter in the test frame code template with the first test parameter associated with the first variable parameter in the interface test case to obtain a test frame code in the interface test code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code in the interface test code.
The following describes an interface test code generation apparatus provided in an embodiment of the present invention.
Referring to fig. 3, fig. 3 is one of the structural diagrams of the interface test code generation apparatus according to the embodiment of the present invention, which can implement the details of the interface test code generation method and achieve the same effect. As shown in fig. 3, the interface test code generation apparatus 300 includes:
an obtaining module 301, configured to obtain a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
a first searching module 302, configured to search, from a template file, a test frame code template that matches the interface test case and a method code template associated with the interface test case;
a generating module 303, configured to generate an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
Optionally, the first search module 302 is specifically configured to obtain target information associated with the interface test case, where the target information includes interface type information, test level information, and a name of a method to be tested; searching a test frame code template corresponding to the first key value and a method code template corresponding to the second key value in the template file; the first key value comprises the interface type information and the test grade information; the second key value comprises the name of the method to be tested.
Optionally, fig. 4 is a second structural diagram of the interface test code generation apparatus according to the second embodiment of the present invention, and referring to fig. 4, based on the embodiment of the apparatus shown in fig. 3, the interface test code generation apparatus 300 further includes:
a storage module 304, configured to store the test frame code template into a first folder corresponding to the test frame code template according to a first storage path, and store the method code template into a second folder corresponding to the method code template according to a second storage path;
the first storage path is generated in a first preset path based on the name of the test case text and the page name of the interface test case in the test case text, and the name of the first folder is determined based on a case identifier associated with the interface test case;
the second storage path is generated in a second preset path based on the name of the test case text, and the name of the second folder is determined based on the page of the test case text.
Optionally, fig. 5 is a third structural diagram of an interface test code generation apparatus according to an embodiment of the present invention, and referring to fig. 5, based on the embodiment of the apparatus shown in fig. 4, the interface test code generation apparatus 200 further includes:
a setting module 305, configured to set a target field content in the interface test case to a preset value if the target field content is not the preset value; when the target field content is the preset value, the fact that the test frame code template exists in the first folder is represented, and the method code template exists in the second folder is represented.
Optionally, the first test parameter includes at least one of:
identifying a use case;
the name of the method to be tested;
uniform resource locator information.
Optionally, the second test parameter includes at least one of:
generating first logic data based on a configuration rule corresponding to a precondition;
second logic data generated based on the configuration rule corresponding to the verification condition;
expected result information of the interface test;
identifying a use case;
uniform resource locator information.
Optionally, fig. 6 is a fourth of the structure diagram of the interface test code generation apparatus according to the embodiment of the present invention, and referring to fig. 6, based on the embodiment of the apparatus shown in fig. 3, the interface test code generation apparatus 300 further includes:
a second searching module 306, configured to search, based on a third key value corresponding to the precondition, for a configuration rule corresponding to the precondition in a preset rule base, and search, based on a fourth key value corresponding to the check condition, for a configuration rule corresponding to the check condition in the preset rule base.
The interface test code generation apparatus 300 can implement each process implemented by the electronic device in the above-described interface test code generation method embodiment, and can achieve the same technical effect, and for avoiding repetition, details are not described here again.
Referring to fig. 7, fig. 7 is a structural diagram of an electronic device provided in the implementation of the present invention, where the electronic device shown in fig. 7 includes: a processor 701, a memory 702 and a computer program stored on the memory 702 and executable on the processor, the various components in the electronic device being coupled together by a bus interface 703, the computer program when executed by the processor 701 implementing the steps of:
acquiring a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file;
generating an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
Optionally, the processor 701 is specifically configured to:
acquiring target information associated with the interface test case, wherein the target information comprises interface type information, test grade information and a name of a method to be tested;
searching a test frame code template corresponding to the first key value and a method code template corresponding to the second key value in the template file;
the first key value comprises the interface type information and the test grade information; the second key value comprises the name of the method to be tested.
Optionally, the processor 701 is further configured to:
storing the test frame code template into a first folder corresponding to the test frame code template according to a first storage path, and storing the method code template into a second folder corresponding to the method code template according to a second storage path;
the first storage path is generated in a first preset path based on the name of the test case text and the page name of the interface test case in the test case text, and the name of the first folder is determined based on a case identifier associated with the interface test case;
the second storage path is generated in a second preset path based on the name of the test case text, and the name of the second folder is determined based on the page of the test case text.
Optionally, the processor 701 is further configured to:
under the condition that the target field content in the interface test case is not a preset value, setting the target field content to be the preset value; when the target field content is the preset value, the fact that the test frame code template exists in the first folder is represented, and the method code template exists in the second folder is represented.
Optionally, the first test parameter includes at least one of:
identifying a use case;
the name of the method to be tested;
uniform resource locator information.
Optionally, the second test parameter includes at least one of:
generating first logic data based on a configuration rule corresponding to a precondition;
second logic data generated based on the configuration rule corresponding to the verification condition;
expected result information of the interface test;
identifying a use case;
uniform resource locator information.
Optionally, if the to-be-tested method associated with the interface test case includes a method corresponding to the precondition and a method corresponding to the verification condition;
the processor 701 is further configured to:
and searching a configuration rule corresponding to the precondition in a preset rule base based on a third key value corresponding to the precondition, and searching the configuration rule corresponding to the check condition in the preset rule base based on a fourth key value corresponding to the check condition.
Preferably, an embodiment of the present invention further provides an electronic device, which includes a processor, a memory, and a computer program that is stored in the memory and can be run on the processor, and when the computer program is executed by the processor, the computer program implements each process of the interface test code generation method according to any of the above method embodiments, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here.
An embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program implements each process of the interface test code generation method, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here. The computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a U disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. An interface test code generation method, the method comprising:
acquiring a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file;
generating an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
2. The method of claim 1, wherein the searching for the test framework code template matching the interface test case and the method code template associated with the interface test case from the template file comprises:
acquiring target information associated with the interface test case, wherein the target information comprises interface type information, test grade information and a name of a method to be tested;
searching a test frame code template corresponding to the first key value and a method code template corresponding to the second key value in the template file;
the first key value comprises the interface type information and the test grade information; the second key value comprises the name of the method to be tested.
3. The method of claim 1, wherein before generating the interface test code of the interface test case based on the preset rule, the method further comprises:
storing the test frame code template into a first folder corresponding to the test frame code template according to a first storage path, and storing the method code template into a second folder corresponding to the method code template according to a second storage path;
the first storage path is generated in a first preset path based on the name of the test case text and the page name of the interface test case in the test case text, and the name of the first folder is determined based on a case identifier associated with the interface test case;
the second storage path is generated in a second preset path based on the name of the test case text, and the name of the second folder is determined based on the page of the test case text.
4. The method of claim 3, wherein after storing the test frame code template into a first folder corresponding to the test frame code template according to a first storage path and storing the method code template into a second folder corresponding to the method code template according to a second storage path, the method further comprises:
under the condition that the target field content in the interface test case is not a preset value, setting the target field content to be the preset value; when the target field content is the preset value, the fact that the test frame code template exists in the first folder is represented, and the method code template exists in the second folder is represented.
5. The method of claim 1, wherein the first test parameter comprises at least one of:
identifying a use case;
the name of the method to be tested;
uniform resource locator information.
6. The method of claim 1, wherein the second test parameter comprises at least one of:
generating first logic data based on a configuration rule corresponding to a precondition;
second logic data generated based on the configuration rule corresponding to the verification condition;
expected result information of the interface test;
identifying a use case;
uniform resource locator information.
7. The method according to claim 6, wherein if the method to be tested associated with the interface test case includes a method corresponding to the precondition and a method corresponding to the check condition;
before generating the interface test code of the interface test case based on the preset rule, the method further includes:
and searching a configuration rule corresponding to the precondition in a preset rule base based on a third key value corresponding to the precondition, and searching the configuration rule corresponding to the check condition in the preset rule base based on a fourth key value corresponding to the check condition.
8. An interface test code generation apparatus, the apparatus comprising:
the acquisition module is used for acquiring a test case text of an object to be tested; the test case text comprises an interface test case of the object to be tested;
the first searching module is used for searching a test frame code template matched with the interface test case and a method code template related to the interface test case from a template file;
the generating module is used for generating an interface test code of the interface test case based on a preset rule;
wherein the interface test code comprises test framework code and method code, the method code for driving the test framework code;
the preset rules include: replacing a first variable parameter in the test frame code template with a first test parameter associated with the first variable parameter in the interface test case to obtain the test frame code; and replacing the second variable parameter in the method code template with a second test parameter associated with the second variable parameter in the interface test case to obtain the method code.
9. An electronic device comprising a processor, a memory, and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the interface test code generation method of any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the interface test code generation method according to any one of claims 1 to 7.
CN202010289964.8A 2020-04-14 2020-04-14 Interface test code generation method and device, electronic equipment and readable storage medium Active CN111522741B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010289964.8A CN111522741B (en) 2020-04-14 2020-04-14 Interface test code generation method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010289964.8A CN111522741B (en) 2020-04-14 2020-04-14 Interface test code generation method and device, electronic equipment and readable storage medium

Publications (2)

Publication Number Publication Date
CN111522741A true CN111522741A (en) 2020-08-11
CN111522741B CN111522741B (en) 2023-11-14

Family

ID=71902767

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010289964.8A Active CN111522741B (en) 2020-04-14 2020-04-14 Interface test code generation method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN111522741B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112527630A (en) * 2020-11-18 2021-03-19 平安消费金融有限公司 Test case generation method and device, computer equipment and storage medium
CN113064828A (en) * 2021-04-13 2021-07-02 广州骏伯网络科技有限公司 Automatic testing method and device, computer equipment and storage medium
CN113535570A (en) * 2021-07-23 2021-10-22 北京奇艺世纪科技有限公司 Test case processing method and device and electronic equipment
CN113590407A (en) * 2021-09-29 2021-11-02 云账户技术(天津)有限公司 Interface testing method and device
CN113778889A (en) * 2021-09-16 2021-12-10 行云智网络科技(北京)有限公司 Dynamic parameter setting method and system for automatic test

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030014734A1 (en) * 2001-05-03 2003-01-16 Alan Hartman Technique using persistent foci for finite state machine based software test generation
US20060064178A1 (en) * 2004-09-07 2006-03-23 The Boeing Company System, method and computer program product for developing a system-of-systems architecture model
CN108415832A (en) * 2018-02-07 2018-08-17 平安科技(深圳)有限公司 Automatic interface testing method, device, equipment and storage medium
CN108595342A (en) * 2018-05-14 2018-09-28 杭州有赞科技有限公司 Unit test method and device
CN110309071A (en) * 2019-06-27 2019-10-08 杭州数梦工场科技有限公司 Test the generation method and module, test method and system of code

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030014734A1 (en) * 2001-05-03 2003-01-16 Alan Hartman Technique using persistent foci for finite state machine based software test generation
US20060064178A1 (en) * 2004-09-07 2006-03-23 The Boeing Company System, method and computer program product for developing a system-of-systems architecture model
CN108415832A (en) * 2018-02-07 2018-08-17 平安科技(深圳)有限公司 Automatic interface testing method, device, equipment and storage medium
CN108595342A (en) * 2018-05-14 2018-09-28 杭州有赞科技有限公司 Unit test method and device
CN110309071A (en) * 2019-06-27 2019-10-08 杭州数梦工场科技有限公司 Test the generation method and module, test method and system of code

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112527630A (en) * 2020-11-18 2021-03-19 平安消费金融有限公司 Test case generation method and device, computer equipment and storage medium
CN112527630B (en) * 2020-11-18 2023-07-07 平安消费金融有限公司 Test case generation method, device, computer equipment and storage medium
CN113064828A (en) * 2021-04-13 2021-07-02 广州骏伯网络科技有限公司 Automatic testing method and device, computer equipment and storage medium
CN113535570A (en) * 2021-07-23 2021-10-22 北京奇艺世纪科技有限公司 Test case processing method and device and electronic equipment
CN113535570B (en) * 2021-07-23 2023-08-25 北京奇艺世纪科技有限公司 Processing method and device for test cases and electronic equipment
CN113778889A (en) * 2021-09-16 2021-12-10 行云智网络科技(北京)有限公司 Dynamic parameter setting method and system for automatic test
CN113590407A (en) * 2021-09-29 2021-11-02 云账户技术(天津)有限公司 Interface testing method and device
CN113590407B (en) * 2021-09-29 2021-11-30 云账户技术(天津)有限公司 Interface testing method and device

Also Published As

Publication number Publication date
CN111522741B (en) 2023-11-14

Similar Documents

Publication Publication Date Title
CN111522741B (en) Interface test code generation method and device, electronic equipment and readable storage medium
CN107665171B (en) Automatic regression testing method and device
CN112327808A (en) Automobile fault diagnosis method and system and automobile fault diagnosis instrument
CN108628748B (en) Automatic test management method and automatic test management system
CN109710508A (en) Test method, test device, test equipment and computer readable storage medium
CN112597028A (en) Method and device for displaying case test result and readable storage medium
CN109947637A (en) Webpage compatibility automated test method, device, equipment and medium
CN114116496A (en) Automatic testing method, device, equipment and medium
CN111966580A (en) Automatic testing method, device, equipment and storage medium based on artificial intelligence
CN113505078B (en) Configuration file updating method, device, equipment and storage medium
CN111680463A (en) File checking method and device
CN113342692B (en) Automatic test case generation method and device, electronic equipment and storage medium
CN110908907A (en) Web page testing method, device, equipment and storage medium
CN108388796B (en) Dynamic domain name verification method, system, computer device and storage medium
CN117421217A (en) Automatic software function test method, system, terminal and medium
CN110688823A (en) XML file verification method and device
CN114238733A (en) Key information extraction method and device, computer storage medium and electronic equipment
CN112748950B (en) Software code examination method and device
CN113377645B (en) Method and system for testing illegal character input on WEB site page
CN109800155B (en) Method and device for testing QTE interlocking application software based on Probe
CN104572429A (en) Page testing method and device for collective elements
CN110569199B (en) Automatic bill testing method and device
CN112487269B (en) Method and device for detecting automation script of crawler
CN112948244B (en) Method, device and equipment for industrial internet information model test
CN109639520B (en) Computer-aided test method for network communication of reactor protection system

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