Test script generation method, terminal device and storage medium

By automatically generating interface test data and scripts, the problems of insufficient data coverage and complex script development in interface automation testing are solved, and efficient automation testing is achieved.

CN113886232BActive Publication Date: 2025-09-09CHINA MERCHANTS BANK
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111148399.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-28
Publication Date
2025-09-09
Estimated Expiration
2041-09-28

AI Technical Summary

Technical Problem

In the existing technology, interface automated test data generation has insufficient coverage, manual preparation work is large and error-prone, and automated script development and maintenance work is large and requires high professionalism, resulting in low efficiency of automated testing.

Method used

This paper provides an interface test data generation method, which automatically generates interface test data by parsing interface definition information, including general types, security test data and business test data, and generates RF combined with Python automated test scripts based on these data.

Benefits of technology

It realizes the automatic generation of test data, covers common inspection types, reduces the technical ability requirements of testers, reduces the overhead of manual design and maintenance of test scripts, and improves the efficiency of interface automation testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113886232B_ABST
    Figure CN113886232B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for generating interface test data and test scripts, a terminal device, and a storage medium. The test data generation method comprises: receiving an interface test data generation instruction; obtaining interface definition information according to the interface test data generation instruction; parsing the interface definition information, and generating corresponding interface test data according to the parsing result, wherein the interface test data at least includes relevant data of conventional types of interface test inspections; and further, based on the interface test data, generating an automated test script combining RF and Python. The present invention significantly reduces the overhead of manually designing test data, writing and maintaining test scripts, improves the efficiency of interface automated testing, and solves the problem that the test data automatically generated by current tools and technologies cannot fully cover common inspection types such as business function inspections, interface field inspections, and security tests; and solves the problem that the manual development and maintenance of automated test scripts is labor-intensive and requires high professionalism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of testing technology, and in particular to a test script generation method, terminal equipment and storage medium. Background Art

[0002] As software scale and complexity continue to increase, and iteration speeds accelerate, fully manual testing can no longer meet the testing needs of large applications. Consequently, more and more companies are adopting automated testing technologies. Interface automated testing plays a key role in software automated testing due to its ease of implementation, significant effectiveness, and high cost-effectiveness. However, the implementation of interface automated testing faces the following challenges:

[0003] The first is test data generation: Automated test data generation offers two options: manual preparation and automated generation. Manual test data preparation is labor-intensive and error-prone. When interface message fields are numerous, manual data preparation can be very stressful. While some existing technologies and tools offer automated test data generation capabilities, they still suffer from insufficient coverage or low efficiency. For the interface under test, comprehensive test data must cover business functions, various interface field exceptions, and common security testing types. Current automated test data generation tools struggle to meet all of these requirements.

[0004] The second is script development and maintenance: Script development and maintenance is one of the main expenses in automated testing. Although scripts can be automatically generated through recording and playback tools, the workload and threshold of manual debugging are still very high. Currently, most automation implementation solutions still rely on manual writing and maintenance of automation scripts, which not only places high demands on the development capabilities of testers, but also increases the workload of automated testing. If the cost of developing and maintaining scripts is too high, it is likely that carrying out automated testing will not be worth the effort. Summary of the Invention

[0005] The main purpose of the present invention is to provide an interface test data and test script generation method, terminal equipment and storage medium, aiming to solve the problems that the current automatically generated test data cannot fully cover common inspection types and the test script overhead is too high, thereby improving test efficiency and reducing test costs.

[0006] To achieve the above object, the present invention provides a method for generating interface test data, the method comprising the following steps:

[0007] Receive interface test data generation instructions;

[0008] Generate instructions according to the interface test data to obtain interface definition information;

[0009] The interface definition information is parsed, and corresponding interface test data is generated according to a parsing result of the interface definition information. The interface test data at least includes relevant data of a conventional type of interface test inspection.

[0010] Optionally, the interface test data includes interface inspection test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information includes:

[0011] Parsing the interface definition information to obtain message field attribute information specified in the interface definition;

[0012] Generate interface inspection test data that meets the requirements based on the message field attribute information specified in the interface definition.

[0013] Optionally, the step of generating interface inspection test data that meets the requirements according to the message field attribute information specified in the interface definition includes:

[0014] Based on one or more attribute information of the message field specified in the interface definition, such as length, type, legality, and necessity, interface inspection test data is generated for normal situations that meet the requirements and various abnormal situations that violate the definition. The interface inspection test data includes one or more of: length check data, type check data, legal character check data, required field check data, and time format check data.

[0015] Optionally, the interface test data includes security test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information includes:

[0016] Parsing the interface definition information to obtain each field in the interface request message;

[0017] Traverse each field in the interface request message, replace the field value of each field with pre-configured data in turn, or generate data of corresponding type for each field to obtain corresponding security test data, wherein the security test data includes: one or more of cross-site scripting attack data, xpath injection data, sql injection data, fuzzy test data, boundary test data, and type test data.

[0018] Optionally, the step of traversing each field in the interface request message and replacing the field value of each field with pre-configured data in sequence, or generating data of a corresponding type for each field to obtain corresponding security test data includes:

[0019] If cross-site scripting attack data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 90 lines of pre-configured JavaScript code in turn to obtain cross-site scripting attack data;

[0020] If xpath injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used xpath injection attack data in turn to obtain xpath injection data;

[0021] If sql injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used SQL injection attack data in turn to obtain sql injection data;

[0022] If fuzzy test data is generated, each field in the interface request message is traversed, and random data of a random length is generated for each field in the interface request message to obtain fuzzy test data;

[0023] If boundary test data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with four pre-configured groups of null values, all blank characters, special symbols, and extremely long character strings to obtain boundary test data;

[0024] If type test data is generated, each field in the interface request message is traversed, and a random Boolean value, a string value, and a numerical value are generated for each field in turn to obtain type test data.

[0025] Optionally, the interface test data includes: business test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information includes:

[0026] Parsing the interface definition information to obtain message field attribute information specified in the interface definition;

[0027] Generate a corresponding service test data template according to the message field attribute information specified in the interface definition;

[0028] Filling the predefined data generation rules into the business test data template to obtain a business test data template file;

[0029] Parse the business test data template file to generate corresponding interface test data.

[0030] Optionally, the method further includes:

[0031] Based on the interface test data, generate an automated test script combining RF and Python, specifically including:

[0032] Based on the interface test data, test cases and business keywords are generated at the RF layer, and componentized message sending methods, configuration files, and message processing classes are generated at the Python layer. The test cases include one or more of business test cases, interface inspection cases, and security test cases.

[0033] In addition, an embodiment of the present invention further provides a test script generation method, the method comprising:

[0034] Acquire interface test data, where the interface test data is generated based on the interface definition information, and the interface test data at least includes relevant data of a conventional type of interface test inspection;

[0035] Based on the interface test data, an automated test script combining RF and Python is generated.

[0036] Optionally, the step of generating an RF combined with Python automated test script based on the interface test data includes:

[0037] Based on the interface test data, test cases and business keywords are generated at the RF layer, and componentized message sending methods, configuration files, and message processing classes are generated at the Python layer. The test cases include one or more of business test cases, interface inspection cases, and security test cases.

[0038] In addition, an embodiment of the present invention also proposes a terminal device, which includes: a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the computer program is executed by the processor, it implements the interface test data generation method as described above, or the test script generation method as described above.

[0039] In addition, an embodiment of the present invention further proposes a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by the processor, it implements the interface test data generation method described above, or the test script generation method described above.

[0040] The interface test data and test script generation method, terminal device and storage medium proposed in the embodiment of the present invention receive interface test data generation instructions; obtain interface definition information according to the interface test data generation instructions; parse the interface definition information, and generate corresponding interface test data according to the parsing result of the interface definition information, wherein the interface test data at least includes relevant data of conventional types of interface test inspection; further, based on the interface test data, an RF combined with Python automated test script can be generated. In the embodiment of the present invention, test data is automatically generated, repetitive work is automatically completed, and testers only need to focus on business logic sorting; data coverage is comprehensive and can cover common interface test inspection types; automated test scripts are automatically generated, reducing the technical ability requirements for personnel carrying out automated testing, thereby significantly reducing the overhead of manually designing test data, writing and maintaining test scripts, and improving the efficiency of interface automated testing. It solves the problem that the test data automatically generated by current tools and technologies cannot fully cover common inspection types such as business function inspection, interface field inspection, and security testing; and solves the problem that the manual development and maintenance of automated test scripts is labor-intensive and requires high professionalism. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 This is a schematic diagram of the functional modules of the terminal device to which the interface test data generating device of the present invention belongs;

[0042] Figure 2 This is a flow chart of an embodiment of a method for generating interface test data according to the present invention;

[0043] Figure 3 A schematic diagram of a process for generating test data and test scripts according to an interface definition in an embodiment of the present invention;

[0044] Figure 4 A detailed flow chart for automatically generating service test data according to interface definitions in an embodiment of the present invention;

[0045] Figure 5 、 Figure 6 and Figure 7 They are schematic diagrams of the styles of three service test data templates in the embodiments of the present invention;

[0046] Figure 8 This is a flow chart of an embodiment of a test script generation method of the present invention;

[0047] Figure 9 A schematic diagram of the execution logic of the test script automatically generated by an embodiment of the present invention;

[0048] Figure 10 The present invention is an embodiment of the present invention and generates a flowchart of an interface inspection case script for an interface.

[0049] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0051] The main solution of the embodiment of the present invention is: by receiving interface test data to generate instructions; according to the interface test data generation instructions, obtain interface definition information; parse the interface definition information, and generate corresponding interface test data according to the parsing result of the interface definition information, the interface test data at least includes relevant data of conventional types of interface test inspection; further, based on the interface test data, an automated test script combining RF and Python can be generated. In the embodiment of the present invention, test data is automatically generated, repetitive work is automatically completed, and testers only need to focus on business logic sorting; data coverage is comprehensive and can cover common interface test inspection types; automated test scripts are automatically generated, reducing the technical ability requirements for personnel conducting automated testing, thereby greatly reducing the overhead of manually designing test data, writing and maintaining test scripts, and improving the efficiency of interface automated testing, solving the problem that the test data automatically generated by current tools and technologies cannot fully cover common inspection types such as business function inspection, interface field inspection, and security testing; solving the problem that the manual development and maintenance of automated test scripts is labor-intensive and requires high professionalism.

[0052] The main technical terms involved in the embodiments of the present invention are:

[0053] Test data: Test data is used to test a certain function of the software. For example, a piece of data is used by administrators to test the website function.

[0054] In a data-driven framework, test data and test scripts are separated. In many testing scenarios, it is necessary to test the same function or feature multiple times using different test data.

[0055] Test data can be imported into the test script as parameters from external data files in the form of Excel, CSV, SQL, etc.

[0056] For example, in a web page security checkpoint, test data needs to be generated: the input data has not been effectively controlled and verified. The attribute parameters involved may include: data type (string, integer, real number, etc.), allowed character set, minimum and maximum length, whether empty input is allowed, whether the parameter is required, whether repetition is allowed, numerical range, specific value (enumeration type), specific pattern (regular expression), etc.

[0057] Test case: A test case is a specific set of input data, operations or various environment settings, and expected results provided to the system under test to implement the test.

[0058] Test script: A test script is a script written for automated testing. The writing of the test script must correspond to the corresponding test case.

[0059] A test script generally refers to a series of instructions for a specific test, which can be executed by an automated testing tool. To improve the maintainability and reusability of test scripts, they must be structured before execution. Some operations may occur in multiple test procedures, so the objectives of these operations should be purposefully defined so that their implementation can be reused. Test scripts are computer-readable instructions that automate the execution of a test procedure (or portion of a test procedure). They can be created (recorded), automatically generated using an automated testing tool, or programmed using a programming language.

[0060] XPath, which stands for XML Path Language, is a language used to determine the location of a part in an XML document.

[0061] SQL, Structured Query Language, is a special-purpose programming language. It is a database query and programming language used to access data and query, update and manage relational database systems. It is also the extension of database script files.

[0062] Python is a widely used interpreted, high-level, general-purpose computer programming language. Created by Guido van Rossum of the Netherlands Institute for Mathematical and Computer Science Research, Python's first version was released in 1991. It is the successor to ABC and can be considered a LISP dialect using traditional infix expressions. Python provides efficient high-level data structures and enables simple and effective object-oriented programming.

[0063] RF (Robot Framework) is a functional automation testing framework written in Python. It offers excellent scalability, supports keyword-driven testing, can simultaneously test multiple types of clients or interfaces, and enables distributed test execution. It is primarily used for acceptance testing with numerous rounds and acceptance-test-driven development.

[0064] The embodiments of the present invention take into account that, currently, during the implementation of interface automation, the workload of purely manual test data preparation for automated test data generation is enormous and prone to errors. When interface message fields are numerous, the manual data preparation process can be very stressful. While some existing technologies and tools have automated test data generation capabilities, they still suffer from insufficient coverage and require significant manual effort. For the interface under test, comprehensive test data must cover business functions, various interface field exceptions, and common security test types. Current automated test data generation tools struggle to meet all of these requirements. Furthermore, while script development and maintenance can be automated using recording and playback tools, the workload and threshold for manual debugging remain high. Most current automation implementations still rely on manual script writing and maintenance. This not only places high demands on testers' development capabilities but also increases the workload for automated testing. If the overhead of script development and maintenance is excessive, automated testing may be counterproductive.

[0065] Based on this, an embodiment of the present invention provides a solution that can realize the automatic generation of test data and test scripts, reduce the technical requirements of testers for conducting automated testing, significantly reduce the overhead of manually designing test data, writing and maintaining test scripts, and improve the efficiency of interface automated testing.

[0066] Specifically, refer to Figure 1 , Figure 1 This is a schematic diagram of the functional modules of a terminal device to which the interface test data generation device of the present invention belongs. The interface test data generation device can be a device independent of the terminal device and can be hosted on the terminal device or system in the form of hardware or software. The terminal device can be a smart mobile terminal such as a mobile phone or tablet computer, or a network device such as a fixed terminal or server.

[0067] In this embodiment, the terminal device to which the interface test data generating apparatus belongs includes at least an output module 110 , a processor 120 , a memory 130 and a communication module 140 .

[0068] The memory 130 stores an operating system and an interface test data generation program; the output module 110 can be a display screen, a speaker, etc. The communication module 140 can include a WIFI module, a mobile communication module, and a Bluetooth module, etc., and communicates with external devices or servers through the communication module 140.

[0069] As an embodiment, the interface test data generation program in the memory 130 implements the following steps when executed by the processor:

[0070] Receive interface test data generation instructions;

[0071] Generate instructions according to the interface test data to obtain interface definition information;

[0072] The interface definition information is parsed, and corresponding interface test data is generated according to a parsing result of the interface definition information. The interface test data at least includes relevant data of a conventional type of interface test inspection.

[0073] Furthermore, when the interface test data generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0074] Parsing the interface definition information to obtain message field attribute information specified in the interface definition;

[0075] Generate interface inspection test data that meets the requirements based on the message field attribute information specified in the interface definition.

[0076] Furthermore, when the interface test data generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0077] Based on one or more attribute information of the message field specified in the interface definition, such as length, type, legality, and necessity, interface inspection test data is generated for normal situations that meet the requirements and various abnormal situations that violate the definition. The interface inspection test data includes one or more of: length check data, type check data, legal character check data, required field check data, and time format check data.

[0078] Furthermore, when the interface test data generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0079] Parsing the interface definition information to obtain each field in the interface request message;

[0080] Traverse each field in the interface request message, replace the field value of each field with pre-configured data in turn, or generate data of corresponding type for each field to obtain corresponding security test data, wherein the security test data includes: one or more of cross-site scripting attack data, xpath injection data, sql injection data, fuzzy test data, boundary test data, and type test data.

[0081] Furthermore, when the interface test data generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0082] If cross-site scripting attack data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 90 lines of pre-configured JavaScript code in turn to obtain cross-site scripting attack data;

[0083] If xpath injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used xpath injection attack data in turn to obtain xpath injection data;

[0084] If sql injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used SQL injection attack data in turn to obtain sql injection data;

[0085] If fuzzy test data is generated, each field in the interface request message is traversed, and random data of a random length is generated for each field in the interface request message to obtain fuzzy test data;

[0086] If boundary test data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with four pre-configured groups of null values, all blank characters, special symbols, and extremely long character strings to obtain boundary test data;

[0087] If type test data is generated, each field in the interface request message is traversed, and a random Boolean value, a string value, and a numerical value are generated for each field in turn to obtain type test data.

[0088] Furthermore, when the interface test data generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0089] Parsing the interface definition information to obtain message field attribute information specified in the interface definition;

[0090] Generate a corresponding service test data template according to the message field attribute information specified in the interface definition;

[0091] Filling the predefined data generation rules into the business test data template to obtain a business test data template file;

[0092] Parse the business test data template file to generate corresponding interface test data.

[0093] Furthermore, when the interface test data generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0094] Based on the interface test data, generate an automated test script combining RF and Python, specifically including:

[0095] Based on the interface test data, test cases and business keywords are generated at the RF layer, and componentized message sending methods, configuration files, and message processing classes are generated at the Python layer. The test cases include one or more of business test cases, interface inspection cases, and security test cases.

[0096] As another embodiment, when the test script generation program in the memory 130 is executed by the processor, the following steps are implemented:

[0097] Acquire interface test data, where the interface test data is generated based on the interface definition information, and the interface test data at least includes relevant data of a conventional type of interface test inspection;

[0098] Based on the interface test data, an automated test script combining RF and Python is generated.

[0099] Furthermore, when the test script generation program in the memory 130 is executed by the processor, the following steps are also implemented:

[0100] Based on the interface test data, test cases and business keywords are generated at the RF layer, and componentized message sending methods, configuration files, and message processing classes are generated at the Python layer. The test cases include one or more of business test cases, interface inspection cases, and security test cases.

[0101] This embodiment receives an interface test data generation instruction through the above scheme; obtains interface definition information according to the interface test data generation instruction; parses the interface definition information, and generates corresponding interface test data according to the parsing result of the interface definition information, wherein the interface test data at least includes relevant data of conventional types of interface test inspection; further, based on the interface test data, an automated test script combining RF and Python can be generated. In the embodiment of the present invention, test data is automatically generated, repetitive work is automatically completed, and testers only need to focus on business logic sorting; data coverage is comprehensive and can cover common interface test inspection types; automated test scripts are automatically generated, reducing the technical ability requirements for personnel conducting automated testing, thereby greatly reducing the overhead of manually designing test data, writing and maintaining test scripts, improving the efficiency of interface automated testing, and solving the problem that the test data automatically generated by current tools and technologies cannot fully cover common inspection types such as business function inspection, interface field inspection, and security testing; and solving the problem that the manual development and maintenance of automated test scripts is labor-intensive and requires high professionalism.

[0102] Based on the above terminal device architecture but not limited to the above architecture, an embodiment of the method of the present invention is proposed.

[0103] Reference Figure 2 , Figure 2 This is a flow chart of the first embodiment of the method for generating interface test data according to the present invention.

[0104] like Figure 2 As shown, an embodiment of the present invention proposes a method for generating interface test data, the method comprising the following steps:

[0105] Step S101, receiving an interface test data generation instruction;

[0106] The execution subject of the method of this embodiment may be an interface test data generating device, which may be integrated into a test system to generate test data, wherein the test system is used to test the tested system, device or software using the test data.

[0107] In this embodiment, a user interface for operation by a tester may be provided in the test system. The tester may perform operations in the user interface to trigger an interface test data generation instruction.

[0108] Step S102, generating an instruction according to the interface test data to obtain interface definition information;

[0109] After receiving the interface test data generation instruction, the interface test data generation device obtains the interface definition information according to the interface test data generation instruction.

[0110] In this embodiment, in order to solve the problem that the test data automatically generated by current testing tools and technologies cannot fully cover common inspection types such as business function inspection, interface field inspection, and security testing, interface testing is pre-configured with interface definition information, which includes: message field attribute information in the interface request message specified by the interface definition, such as the message field, field length, type, whether it is required, precision, time format and other information.

[0111] Step S103 , parsing the interface definition information, and generating corresponding interface test data according to the parsing result of the interface definition information, wherein the interface test data at least includes relevant data of a conventional type of interface test inspection.

[0112] The interface test data generating device parses the interface definition information to obtain information such as message fields, field length, type, necessity, precision, time format, etc., and generates corresponding interface test data based on the parsing results.

[0113] This embodiment can automatically generate interface inspection test data, security test data, and business test data according to the interface definition, etc., which are related to conventional types of interface test inspection. Figure 3 shown.

[0114] Therefore, through the above solution, the automatic generation of test data can be achieved, thereby reducing the technical requirements for testers in conducting automated testing, greatly reducing the overhead of manually designing test data, and improving the efficiency of interface automated testing.

[0115] The following describes in detail the process of automatically generating interface inspection test data, automatically generating security test data, and automatically generating business test data:

[0116] Specifically, as an embodiment, the interface test data includes: interface inspection test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information may include:

[0117] First, the interface definition information is parsed to obtain the message field attribute information specified in the interface definition;

[0118] Generate interface inspection test data that meets the requirements based on the message field attribute information specified in the interface definition.

[0119] Specifically, based on one or more attribute information of the length, type, legality, and necessity of the message field specified in the interface definition, interface inspection test data for normal situations that meet the requirements and various abnormal situations that violate the definition are generated. The interface inspection test data includes: one or more of length check data, type check data, legal character check data, required field check data, and time format check data.

[0120] More specifically, the detailed implementation process of automatically generating interface inspection test data according to the interface definition in this embodiment can be exemplified as follows:

[0121] Interface check test data is generated based on the field length, type, and whether it is required as specified in the interface definition, covering normal situations that meet the requirements and various abnormal situations that violate the definition. Interface check test data generation specifically includes length check data generation; type check data generation; legal character check data generation; required field check data generation; and time format check data generation. Among them:

[0122] When generating length check data, the data generated all meet the type and character validity requirements. Only the length of the value is adjusted to generate three sets of test data with a length less than 1, a length exactly, and a length greater than 1.

[0123] When generating type data, the maximum length required by the interface definition is taken to generate two sets of data: legal type and illegal type.

[0124] The legal character check data generation is mainly targeted at string type fields. The maximum length required by the interface definition is taken to generate two sets of data: one containing only legal characters and the other containing illegal characters. Fields that can accept any character do not contain illegal data, so only one set of legal data covering all types of characters is generated.

[0125] The required field check data generation only generates a null value data, usually an empty string;

[0126] Time format check data generation is only for fields representing time or date. Given a time format, two sets of data are generated: one that meets the format and the other that does not meet the format.

[0127] Thus, through the above process, it is possible to automatically generate interface inspection test data according to the interface definition.

[0128] As another embodiment, the interface test data includes security test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information may include:

[0129] Parsing the interface definition information to obtain each field in the interface request message;

[0130] Traverse each field in the interface request message, replace the field value of each field with pre-configured data in turn, or generate data of corresponding type for each field to obtain corresponding security test data, wherein the security test data includes: one or more of cross-site scripting attack data, xpath injection data, sql injection data, fuzzy test data, boundary test data, and type test data.

[0131] In a specific implementation, if cross-site scripting attack data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 90 lines of pre-configured JavaScript code in turn to obtain the cross-site scripting attack data;

[0132] If xpath injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used xpath injection attack data in turn to obtain xpath injection data;

[0133] If sql injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used SQL injection attack data in turn to obtain sql injection data;

[0134] If fuzzy test data is generated, each field in the interface request message is traversed, and random data of a random length is generated for each field in the interface request message to obtain fuzzy test data;

[0135] If boundary test data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with four pre-configured groups of null values, all blank characters, special symbols, and extremely long character strings to obtain boundary test data;

[0136] If type test data is generated, each field in the interface request message is traversed, and a random Boolean value, a string value, and a numerical value are generated for each field in turn to obtain type test data.

[0137] More specifically, the detailed implementation process of automatically generating security test data according to the interface definition in this embodiment can be exemplified as follows:

[0138] Security test data is used to test whether the interface has common security risks. Since designing security test data requires a basic grasp of information security-related knowledge and an understanding of common attack types, principles, and data characteristics, it undoubtedly increases the learning cost and workload for testers. In order to facilitate testers to quickly carry out interface security testing, the security test data automatically generated by the embodiment of the present invention can cover six common security test types, including cross-site scripting attacks, xpath injections, sql injections, fuzz testing, boundary testing, and type testing, so that testers can automatically obtain more comprehensive security test data without the need for a security testing foundation. Security test data generation specifically includes cross-site scripting attack data generation; xpath injection data generation; sql injection data generation; fuzz test data generation; boundary test data generation; and type test data generation. Among them:

[0139] When generating cross-site scripting attack data, 90 lines of JavaScript code are preset. When generating test data, each field in the interface request message is traversed and the field value is replaced with these 90 sets of code in turn to obtain test data.

[0140] When generating XPath injection data, 10 sets of common XPath injection attack data are preset. When generating test data, each field in the interface request message is traversed and the field value is replaced with these 10 sets of data in turn to obtain test data.

[0141] When generating SQL injection data, 14 sets of commonly used SQL injection attack data are preset. When generating test data, each field in the interface request message is traversed and the field value is replaced with these 14 sets of data in turn to obtain test data.

[0142] When generating fuzzy test data, the method used is to generate a random data of random length for each field in the message to obtain test data;

[0143] When generating boundary test data, four sets of data are preset: empty values, all whitespace characters, special symbols, and extremely long character strings. When generating test data, each field in the interface request message is traversed and the field values ​​are replaced with these four sets of data in turn to obtain test data.

[0144] When generating type test data, the method used is to traverse each field in the interface request message, and generate various types of test data such as random Boolean values, string values, numerical values, etc. for this field in turn, so as to obtain the test data for the type test.

[0145] Through the above process, it is possible to automatically generate security test data according to the interface definition.

[0146] As another embodiment, the interface test data includes: business test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information may include:

[0147] Parsing the interface definition information to obtain message field attribute information specified in the interface definition;

[0148] Generate a corresponding service test data template according to the message field attribute information specified in the interface definition;

[0149] Filling the predefined data generation rules into the business test data template to obtain a business test data template file;

[0150] Parse the business test data template file to generate corresponding interface test data.

[0151] More specifically, the detailed implementation process of automatically generating business test data according to the interface definition in this embodiment can be exemplified as follows:

[0152] The detailed flow chart of this embodiment for automatically generating business test data based on interface definition is as follows: Figure 4 As shown, it specifically includes business test data template generation and business test data generation.

[0153] First, create an Excel file based on the type, precision, time format and other information of all fields in the interface definition, and write three sheets of single field replacement strategy template, combined replacement strategy template and PICT strategy template respectively. The styles of the three templates are as follows: Figure 5 、 Figure 6 and Figure 7 As shown, the field name, field type, and field format columns are automatically filled in.

[0154] Then, the tester fills in the data generation rules in the template file. The tester can choose whether to use single field replacement, combination replacement or PICT strategy according to the actual business data needs.

[0155] In this embodiment, automatically generating service test data specifically includes parsing a single-field replacement policy template to generate data, parsing a combination replacement policy template to generate data, and parsing a PICT policy template to generate data.

[0156] To facilitate testers in expressing data generation rules, this embodiment provides a syntax for expressing data generation rules. This syntax supports expressing logic such as interval ranges, enumeration values, non-logical, custom Python code, and regular expressions. Test data that meets these rules is generated based on the specified field type (text, numeric, time, list), default value (optional), generation rule, and combination strategy (traversal, random, etc.). Each time data is generated for a field, the value of one field is replaced with each set of data, while the default values ​​of the remaining fields are retained.

[0157] When parsing a single-field replacement policy template, the template is read line by line. The expression in the value range column is parsed according to predefined syntax rules, and one or more data items are generated based on the selected combination strategy. For example, if the combination strategy is random, one value is randomly selected from all candidate values ​​in the value range as test data. If the combination strategy is traversal, a data item is generated for each candidate value in the value range.

[0158] The combined replacement strategy targets situations where multiple fields have corresponding relationships. In this strategy, the values ​​of multiple fields are replaced simultaneously. When generating data, the value columns are parsed one by one, and the fields with values ​​in the same column are replaced simultaneously, while the remaining fields retain their default values. When parsing the combined replacement strategy template, all cells in each value column that are not empty are analyzed. These values ​​and corresponding fields are considered to need to be replaced simultaneously, and a set of data is generated for each value column.

[0159] The PICT strategy leverages the concept of pairwise analysis to batch-generate multi-field value combinations by permuting and combining candidate values ​​for multiple given fields, combining them with tester-specified combination requirements and expected value determination rules. The present invention implements the parsing of PICT strategy templates based on Microsoft's PICT tool. Fields and their candidate values ​​can be entered into the template, and combinations can be restricted by entering data filtering expressions. Expected values ​​corresponding to the data can also be set, facilitating result checking during automated testing.

[0160] In this embodiment, in order to automatically generate test data covering business function tests and generate test data with business significance, a business test data template is designed, which is divided into a single field replacement strategy template, a combination replacement strategy template, and a PICT strategy template, which are respectively suitable for test data generation scenarios such as field replacement one by one, multiple field combination replacement, and field value permutation and combination; in order to automatically generate various normal and abnormal test scenarios covering interface fields, the embodiment of the present invention parses the interface definition and generates test data covering length check, type check, required field check, legal character check, time format check, etc. according to information such as field length, type, required or not, and enumeration value range; in order to automatically generate test data covering common security test types, the embodiment of the present invention uses randomly generated or preset malicious test data to traverse each field in the message and batch generate test data covering cross-site scripting attacks, xpath injection, sql injection, fuzz testing, boundary testing, type testing, etc.

[0161] Therefore, through the above solution, test data is automatically generated and repetitive work is automatically completed, and testers only need to focus on business logic sorting; the data coverage is comprehensive and can cover common interface test inspection types such as interface inspection test data, security test data, and business test data, thereby greatly reducing the overhead of manually designing test data, improving the efficiency of interface automation testing, and solving the problem that the test data automatically generated by current tools and technologies cannot fully cover common inspection types such as business function inspection, interface field inspection, and security testing.

[0162] Furthermore, if Figure 3 As shown, the method of the embodiment of the present invention may further include:

[0163] Based on the interface test data, generate an automated test script combining RF and Python, specifically including:

[0164] Based on the interface test data, test cases and business keywords are generated at the RF layer, and componentized message sending methods, configuration files, and message processing classes are generated at the Python layer. The test cases include one or more of business test cases, interface inspection cases, and security test cases.

[0165] The specific solution for generating test scripts in this embodiment can be found in Figure 8 The embodiment shown.

[0166] In this embodiment, the automatic generation of test data and test scripts can be achieved, thereby reducing the technical requirements for testers in conducting automated testing, significantly reducing the overhead of manually designing test data, writing and maintaining test scripts, and improving the efficiency of interface automated testing.

[0167] Furthermore, if Figure 8 As shown, an embodiment of the present invention further provides a test script generation method, the method comprising:

[0168] Step S201: Acquire interface test data, where the interface test data is generated based on interface definition information and includes at least relevant data of a conventional type of interface test inspection;

[0169] Step S202: Generate an automated test script combining RF and Python based on the interface test data.

[0170] The step of generating an RF-combined Python automated test script based on the interface test data may include:

[0171] Based on the interface test data, test cases and business keywords are generated at the RF layer, and componentized message sending methods, configuration files, and message processing classes are generated at the Python layer. The test cases include one or more of business test cases, interface inspection cases, and security test cases.

[0172] The following is a detailed description of the solution for automatically generating executable test scripts:

[0173] This embodiment can automatically generate executable test scripts, specifically, it can automatically generate RobotFramework (hereinafter referred to as RF) combined with Python automated test scripts, which, together with the test data automatically generated by the above embodiment, can be directly used to carry out data-driven automated testing.

[0174] like Figure 9 As shown, Figure 9 This is the execution logic for the automatically generated test script in this embodiment. The script is divided into an RF layer and a Python layer. The RF layer primarily generates test cases and business keywords. The test cases use automatically generated business keywords as driver templates, primarily completing message sending and checking the expected response results. Message sending is accomplished using a componentized, encapsulated sending method. To ensure compatibility with multiple communication protocols, such as TCP, HTTP, and message queues, and to simplify script maintenance, the message sending method in this embodiment is encapsulated as a low-level component, compatible with message sending across a variety of common protocols and message types.

[0175] This embodiment automatically generates executable test scripts, specifically including business test case scripts, interface check case scripts, and security test case scripts. The generated test scripts are data-driven and include both RF layer scripts and Python layer scripts. The generated data-driven business keywords vary based on the characteristics of different test types.

[0176] Among them, for the business test case script, the business test data is generated according to the data generation rules filled in by the tester in the data generation template file. The template file contains the expected value corresponding to the filled-in data, so when generating the test case, the expected result of the case can be known. Therefore, the generated business keyword will use the expected value as one of the parameters, and complete the sending of the message and the judgment of whether the expected value is correct in the keyword.

[0177] For the interface check case script, unlike the business test, the interface check test data is parsed and generated from the interface definition. When the data is generated, although it is known whether the data violates the requirements in the definition, it is impossible to judge the specific error return code and error message of the data during actual execution, so the generated test data cannot be directly checked for results. Therefore, the business keywords generated by the method of this embodiment are divided into two types: those without verification and those with verification. The keywords without verification only complete the message sending and do not check the results, but write the message return code and error message into an Excel file for record. The business keywords with verification are consistent with the business keywords used in the business test, that is, the expected value is used as a parameter and the correctness of the result is checked after the message is sent.

[0178] like Figure 10 As shown, Figure 10 This is a flowchart of an interface-generated interface inspection case script for this embodiment. When the interface inspection script is initially generated, the driver template used in the case file is a keyword without verification. The tester needs to execute the automatically generated interface inspection case set, which will result in an Excel file that records each case and the actual execution results. The tester manually checks the data and return results in the Excel file. If there are no errors, an automatically generated secondary generation case is executed, which combines the test data with the execution results in Excel to generate a test case set with expected values. The case after secondary generation is now a complete test case with inspection capabilities.

[0179] For security test case scripts, during security testing, we do not focus on the return code and error message in the response message, but rather on whether these malicious test data will trigger security issues. Therefore, the business keywords generated for security testing do not check the return code and error message after the message is sent. Instead, they check whether there is any sensitive information leakage in the response message and the automatically generated data for detecting cross-site scripting attacks. If so, it is considered a security risk.

[0180] In this embodiment, the test script automatic generation method is compatible with business testing, interface inspection, and security testing, and can generate corresponding test scripts for different tests, especially for interface inspections that cannot predict expected values. If there are no expected values, the script has no verification capability. The embodiment of the present invention proposes a secondary generation scheme for interface inspections. By automatically recording the actual expected values ​​and backfilling them into the test cases, the workload of testers to fill in the expected values ​​one by one is effectively reduced. Testers only need to check in the record table whether the actual values ​​obtained from the test data are consistent with the product design.

[0181] As can be seen from the above, this embodiment of the present invention generates automated test scripts using RF and Python based on interface test data, solving the problem of manual development and maintenance of automated test scripts, which is labor-intensive and requires high professional expertise. The automatically generated test scripts utilize a data-driven, configurable, and componentized approach, decoupling test data from test code and separating test scripts from underlying processing. This eliminates the need for testers to understand the underlying detailed processing logic, significantly reducing the overhead of manually writing and maintaining test scripts and improving the efficiency of automated interface testing.

[0182] Compared with the existing technology, in the embodiment of the present invention, test data is automatically generated, repetitive work is automatically completed, and testers only need to focus on business logic sorting; data coverage is comprehensive and can cover common interface test inspection types; automated test scripts are automatically generated, reducing the technical ability requirements for personnel conducting automated testing; the automatically generated test scripts use data-driven, configured, componentized and other methods to decouple test data from test code and separate test scripts from underlying processing. Testers do not need to understand the specific underlying sending processing logic, and maintenance costs are greatly reduced. In this solution, the automatic generation of test data and test scripts can be achieved, thereby reducing the technical ability requirements for testers in conducting automated testing, significantly reducing the overhead of manually designing test data, writing and maintaining test scripts, and improving the efficiency of interface automated testing.

[0183] In addition, an embodiment of the present invention also proposes a terminal device, which includes: a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the computer program is executed by the processor, it implements the interface test data generation method described in the above embodiment, or the test script generation method described in the above embodiment.

[0184] In addition, an embodiment of the present invention also proposes a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by the processor, the interface test data generation method as described in the above embodiment is implemented, or the test script generation method as described in the above embodiment is implemented.

[0185] The interface test data and test script generation method, terminal device, and storage medium proposed in the embodiments of the present invention receive interface test data and generate instructions; obtain interface definition information based on the interface test data and generate instructions; parse the interface definition information and, based on the parsing results of the interface definition information, generate corresponding interface test data, wherein the interface test data includes at least relevant data of common interface test inspection types; and further, based on the interface test data, generate RF-combined Python automated test scripts. The embodiments of the present invention solve the problem that the test data automatically generated by current tools and technologies cannot fully cover common inspection types such as business function inspection, interface field inspection, and security testing; and solve the problem that manual development and maintenance of automated test scripts is labor-intensive and requires high professional skills. Compared with the existing technology, the embodiments of the present invention automatically generate test data and automatically complete repetitive work, so testers only need to focus on business logic sorting; the data coverage is comprehensive and can cover common interface test inspection types; the automated test script is automatically generated, reducing the technical requirements for personnel conducting automated testing; the automatically generated test script adopts data-driven, configuration-based, and component-based methods to decouple test data from test code and separate test scripts from underlying processing. Testers do not need to understand the specific underlying sending and processing logic, significantly reducing maintenance costs. In this solution, test data and test scripts can be automatically generated, thereby reducing the technical requirements for testers to carry out automated testing, significantly reducing the overhead of manually designing test data, writing and maintaining test scripts, and improving the efficiency of interface automated testing.

[0186] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.

[0187] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0188] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium as above (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for enabling a recommendation effect evaluation system (which can be a mobile phone, computer, server, controlled terminal, or network device, etc.) to execute the method of each embodiment of the present invention.

[0189] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A test script generation method, characterized in that: The method comprises the following steps: Receive interface test data generation instructions; Generate instructions according to the interface test data to obtain interface definition information; Parsing the interface definition information, and generating corresponding interface test data based on the parsing result of the interface definition information, wherein the interface test data includes at least relevant data of a conventional type of interface test inspection; wherein the relevant data of a conventional type of interface test inspection includes at least interface inspection test data, security test data, and service test data; The step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information includes: parsing the interface definition information to obtain each field in the interface request message; traversing each field in the interface request message and replacing the field value of each field with pre-configured data in turn, or generating data of a corresponding type for each field to obtain corresponding security test data, wherein the security test data includes: one or more of cross-site scripting attack data, xpath injection data, sql injection data, fuzzy test data, boundary test data, and type test data; Based on the interface test data, an automated test script combining RF and Python is generated, specifically including: based on the interface test data, generating test cases and business keywords at the RF layer, and generating a componentized message sending method, configuration file, and message processing class at the Python layer. The test cases include: one or more of business test cases, interface inspection cases, and security test cases; the automated test script adopts a data-driven approach, including RF layer scripts and Python layer scripts; wherein the test case adopts a drive template constructed based on the automatically generated business keywords.

2. The method according to claim 1, characterized in that The interface test data includes: interface inspection test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information includes: Parsing the interface definition information to obtain message field attribute information specified in the interface definition; Generate interface inspection test data that meets the requirements based on the message field attribute information specified in the interface definition.

3. The method according to claim 2, characterized in that The step of generating interface inspection test data that meets the requirements according to the message field attribute information specified in the interface definition includes: Based on one or more attribute information of the message field specified in the interface definition, such as length, type, legality, and necessity, interface inspection test data is generated for normal situations that meet the requirements and various abnormal situations that violate the definition. The interface inspection test data includes one or more of: length check data, type check data, legal character check data, required field check data, and time format check data.

4. The method according to claim 1, wherein The step of traversing each field in the interface request message and replacing the field value of each field with pre-configured data in sequence, or generating data of a corresponding type for each field to obtain corresponding security test data includes: If cross-site scripting attack data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 90 lines of pre-configured JavaScript code in turn to obtain cross-site scripting attack data; If XML path language xpath injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used xpath injection attack data in turn to obtain xpath injection data; If sql injection data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with 14 sets of pre-configured commonly used sql injection attack data in turn to obtain sql injection data; If fuzzy test data is generated, each field in the interface request message is traversed, and random data of a random length is generated for each field in the interface request message to obtain fuzzy test data; If boundary test data is generated, each field in the interface request message is traversed, and the field value of each field is replaced with four pre-configured groups of null values, all blank characters, special symbols, and extremely long character strings to obtain boundary test data; If type test data is generated, each field in the interface request message is traversed, and a random Boolean value, a string value, and a numerical value are generated for each field in turn to obtain type test data.

5. The method according to claim 1, wherein The interface test data includes: business test data, and the step of parsing the interface definition information and generating corresponding interface test data according to the parsing result of the interface definition information includes: Parsing the interface definition information to obtain message field attribute information specified in the interface definition; Generate a corresponding service test data template according to the message field attribute information specified in the interface definition; Filling the predefined data generation rules into the business test data template to obtain a business test data template file; Parse the business test data template file to generate corresponding interface test data.

6. A terminal device, characterized in that: The terminal device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the test script generating method according to any one of claims 1 to 5 when executed by the processor.

7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the test script generating method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • API automated testing method and system based on data driving

    CN108897687A

  • Automatic hierarchical test method, device and system based on case classification

    CN109947642A

  • Test case generation method and device, equipment and storage medium

    CN110750442A

  • Test data generation method and system, corresponding equipment and storage medium

    CN112199302A