Test case-based testing approach

By generating test case templates and converting them into executable code, the problem of inefficient code generation of test case is solved, simplifying the testing process, reducing professional requirements, and improving generation efficiency and user experience.

CN114416547BActive Publication Date: 2025-08-19JINGWEI HIRAIN (TIANJIN) RES&DEV CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210016728.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-07
Publication Date
2025-08-19
Estimated Expiration
2042-01-07

AI Technical Summary

Technical Problem

In the prior art, the code generation of test cases is inefficient and has high professionalism requirements for testers, resulting in increased costs.

Method used

By obtaining pre-set business-related test base classes, generating test case templates, and converting test cases into executable code when the target execution times meet the preset times requirements, simplifying the test case code generation process and reducing professional requirements for testers.

Benefits of technology

It improves the generation efficiency of test case code, reduces the professional requirements for testers, simplifies the difficulty of generating test case code, and improves user experience and exhaustive testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416547B_ABST
    Figure CN114416547B_ABST
Patent Text Reader

Abstract

The present invention discloses a test method based on test cases, which includes: obtaining a pre-set test base class related to the business; generating a test case template corresponding to each base class function according to the preset use case field and function information of each base class function in the test base class; obtaining the use case field value obtained by editing the test case template, and generating a test case including the use case field and the use case field value, wherein each test case corresponds to a test case template; when the target number of executions meets the preset number requirement, all test cases are converted into executable test case code according to the order of the base class functions corresponding to the test cases in the test base class; generating a calling code for calling the preset test case execution logic, and adding the calling code to the test case code to obtain the target test case code, so as to perform a use case test based on the target test case code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a test method based on test cases. Background Art

[0002] A test case is a description of the testing tasks for a specific software product, embodying the test plan, methods, techniques, and strategies. A test case is a scientifically organized summary of software testing activities, aiming to transform them into a manageable model. It also serves as a method for quantifying testing, with different test cases being used for different software categories. Related technologies require testers to write different test codes for different test cases, placing high demands on testers' expertise, resulting in high personnel costs and low test case code generation efficiency. Summary of the Invention

[0003] The present invention provides a test case-based testing method, which can improve the generation efficiency of test case codes and reduce the professional requirements for testers.

[0004] The specific technical solutions are as follows:

[0005] In a first aspect, an embodiment of the present invention provides a test case-based testing method, the method comprising:

[0006] Get the pre-set business-related test base class;

[0007] Generate a test case template corresponding to each base class function according to the preset use case field and the function information of each base class function in the test base class, wherein the function information includes the function name and function input parameters, and the test case template includes a use case name generated based on the function name of each base class function, a business use case field generated based on the function input parameters of each base class function, and the preset use case field, and the preset use case field includes a status code and the number of executions;

[0008] Obtaining a use case field value edited based on the test case template, and generating a test case including a use case field and a use case field value, wherein each test case corresponds to a test case template;

[0009] When the target number of executions meets the preset number requirement, all test cases are converted into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class, wherein the target number of executions is the sum of the execution times of all test cases whose status codes have the preset status code values;

[0010] Generate a call code for calling a preset test case execution logic, and add the call code to the test case code to obtain a target test case code, so as to perform a case test based on the target test case code.

[0011] In one embodiment, generating a test case template corresponding to each base class function according to the preset use case field and the function information of each base class function in the test base class includes:

[0012] For the base class function to be processed in the test base class, the function name of the base class function to be processed is used as the use case name corresponding to the base class function to be processed, and the function input parameter of the base class function to be processed is used as the business use case field corresponding to the base class function to be processed. According to the preset use case field, the use case name and business use case field corresponding to the base class function to be processed, a test case template corresponding to the base class function to be processed is generated;

[0013] Alternatively, a first configuration file including a mapping relationship between a function name and a function name translation result is generated based on the function name of each base class function in the test base class, and a second configuration file including a mapping relationship between a function input parameter and a function input parameter translation result is generated based on the function input parameter of each base class function in the test base class. The translation result of the function name to be processed in the first configuration file is used as the use case name corresponding to the translation result of the function name to be processed, and the translation result of the function input parameter corresponding to the translation result of the base class function to be processed in the second configuration file is used as the business use case field corresponding to the translation result of the function name to be processed. A test case template corresponding to the translation result of the function name to be processed is generated based on the preset use case field, the use case name corresponding to the translation result of the function name to be processed, and the business use case field.

[0014] In one embodiment, obtaining a test case field value edited based on the test case template includes:

[0015] When there is no corresponding data generator for the use case field to be edited in the test case template, obtaining the use case field value of the use case field to be edited input by the user;

[0016] When the use case field to be edited in the test case template has at least one corresponding data generator, the target data generator selected by the user from the at least one data generator is obtained, and the use case field value of the use case field to be edited is automatically generated based on the target data generator.

[0017] In one embodiment, before obtaining the target data generator selected by the user from the at least one data generator, the method further includes:

[0018] Obtaining a target character combination mode, a target field minimum length, and a target field maximum length input by a user in a generator creation interface, and generating a data generator for the use case field to be edited based on the target character combination mode, the target field minimum length, and the target field maximum length, wherein the target character combination mode, the target field minimum length, and the target field maximum length are the character combination mode, the field minimum length, and the field maximum length for the use case field to be edited, respectively;

[0019] Alternatively, obtain a data generator script for the use case field to be edited that is imported by the user in the generator creation interface, and generate a data generator for the use case field to be edited based on the data generator script, wherein the data generator script includes a data generation function, and the data generation function is used to define the character combination method, minimum field length, and maximum field length of the use case field to be edited.

[0020] In one embodiment, the method further comprises:

[0021] Obtaining precondition information entered by the user on the precondition creation interface, wherein the precondition information includes a precondition name, at least one precondition step, a return parameter corresponding to each of the precondition steps, and a return parameter value corresponding to each of the precondition steps, wherein the precondition step is a step required to obtain the return parameter;

[0022] A precondition is generated based on the precondition information.

[0023] In one embodiment, after generating a first configuration file including a mapping relationship between a function name and a function name translation result according to the function name of each base class function in the test base class, the method further includes:

[0024] Generate a use case directory according to the function names and the order of the function names in the test base class;

[0025] Alternatively, a use case directory is generated according to the translation results of each function name in the first configuration file and the order of the function name translation results.

[0026] In one embodiment, after generating the use case catalog, the method further includes:

[0027] Insert the precondition name as a first-level directory into the use case directory.

[0028] In one embodiment, converting all test cases into executable test case code according to the order of base class functions corresponding to the test cases in the test base class includes: storing all test cases into a JSON file according to the order of contents of the test case directory, and converting the JSON file into executable test case code;

[0029] Before adding the calling code to the test case code to obtain the target test case code, the method also includes: if the use case directory includes a precondition name, generating a calling code for calling the precondition corresponding to the precondition name, and adding the calling code of the precondition to the test case code.

[0030] In one embodiment, after generating a test case including a use case field and a use case field value, the method further includes:

[0031] In the editing interface of the test case template, a target exhaustive module added by the user from at least one exhaustive module is obtained so that when the test case code corresponding to the test case template is executed, an exhaustive test is performed based on the target exhaustive module, wherein the exhaustive module is generated according to the exhaustive range input by the user and a preset exhaustive algorithm.

[0032] In one embodiment, the preset test case execution logic includes test case execution logic and test result judgment logic;

[0033] The test case execution logic includes: executing the corresponding test case code in the order of the base class functions in the test base class, saving the test case execution result with the status code value as the preset status code value in the preset json data body format, when the test case to be executed needs to call the target test case execution result, if the Nth execution result in the target test case execution result is a correct result, calling the Nth execution result in accordance with the calling format corresponding to the preset json data body format; if the Nth execution result in the target test case execution result is an error result, calling the N+1th execution result in the target test case execution result in accordance with the calling format corresponding to the preset json data body format, wherein the target test case execution result is all execution results of the target test case, and N is a positive integer;

[0034] The test result judgment logic includes: when a status code is defined in the test base class, determining whether the program tested by the target test case template is normal by determining whether the target status code defined in the test base class is the same as the status code set in the target test case, wherein the target status code corresponds to the target test case; when test content is defined in the test base class and the preset use case field includes a test result, when the target test result in the target test case takes a value of 1, determining whether the program tested by the target test case is normal by determining whether the test case execution result saved in a preset json data body format is the same as the test content defined in the test base class; when the target test result in the target test case takes a value of 0, determining whether the program tested by the target test case is normal by determining whether the target test content in the target test case is the same as the test content defined in the test base class.

[0035] In a second aspect, an embodiment of the present invention provides a test case-based testing device, the device comprising:

[0036] A first acquisition unit is used to acquire a preset business-related test base class;

[0037] A first generating unit is configured to generate a test case template corresponding to each base class function according to a preset use case field and function information of each base class function in the test base class, wherein the function information includes a function name and function input parameters, and the test case template includes a use case name generated based on the function name of each base class function, a business use case field generated based on the function input parameters of each base class function, and the preset use case field, wherein the preset use case field includes a status code and an execution count;

[0038] A second acquiring unit is configured to acquire a use case field value edited based on the test case template, and generate a test case including a use case field and a use case field value, wherein each test case corresponds to a test case template;

[0039] a conversion unit, configured to convert all test cases into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class, if a target execution number meets a preset number requirement, wherein the target execution number is the sum of the execution numbers of all test cases whose status codes have preset status code values;

[0040] The second generating unit is used to generate a calling code for calling the preset test case execution logic;

[0041] The adding unit is used to add the calling code to the test case code to obtain the target test case code, so as to perform a test case test based on the target test case code.

[0042] In one embodiment, the first generating unit includes: a first generating module or a second generating module.

[0043] A first generating module is configured to, for a base class function to be processed in the test base class, use the function name of the base class function to be processed as the use case name corresponding to the base class function to be processed, use the function input parameter of the base class function to be processed as the business use case field corresponding to the base class function to be processed, and generate a test case template corresponding to the base class function to be processed according to the preset use case field, the use case name and the business use case field corresponding to the base class function to be processed;

[0044] The second generation module is used to generate a first configuration file including a mapping relationship between a function name and a function name translation result according to the function name of each base class function in the test base class, generate a second configuration file including a mapping relationship between a function input parameter and a function input parameter translation result according to the function input parameter of each base class function in the test base class, use the translation result of the function name to be processed in the first configuration file as the use case name corresponding to the translation result of the function name to be processed, use the translation result of the function input parameter corresponding to the translation result of the base class function to be processed in the second configuration file as the business use case field corresponding to the translation result of the function name to be processed, and generate a test case template corresponding to the translation result of the function name to be processed according to the preset use case field, the use case name corresponding to the translation result of the function name to be processed, and the business use case field.

[0045] In one embodiment, the second acquiring unit includes:

[0046] A first acquisition module is configured to acquire a use case field value of the use case field to be edited input by a user when there is no corresponding data generator for the use case field to be edited in the test case template;

[0047] The second acquisition module is used to obtain the target data generator selected by the user from the at least one data generator when the use case field to be edited in the test case template has a corresponding at least one data generator, and automatically generate the use case field value of the use case field to be edited based on the target data generator.

[0048] In one embodiment, the apparatus further comprises:

[0049] The third generating unit is used to obtain the target character combination mode, target field minimum length and target field maximum length input by the user in the generator creation interface before obtaining the target data generator selected by the user from the at least one data generator, and generate the data generator for the use case field to be edited based on the target character combination mode, target field minimum length and target field maximum length, wherein the target character combination mode, target field minimum length and target field maximum length are the character combination mode, field minimum length and field maximum length for the use case field to be edited, respectively; or, obtain the data generator script for the use case field to be edited imported by the user in the generator creation interface, and generate the data generator for the use case field to be edited based on the data generator script, wherein the data generator script includes a data generation function, and the data generation function is used to define the character combination mode, field minimum length and field maximum length of the use case field to be edited.

[0050] In one embodiment, the apparatus further comprises:

[0051] A third acquisition unit is configured to acquire precondition information input by a user in a precondition creation interface, wherein the precondition information includes a precondition name, at least one precondition step, a return parameter corresponding to each of the precondition steps, and a return parameter value corresponding to each of the precondition steps, wherein the precondition step is a step required to acquire the return parameter;

[0052] A fourth generating unit is configured to generate a precondition based on the precondition information.

[0053] In one embodiment, the apparatus further comprises:

[0054] The fifth generation unit is used to generate a first configuration file including a mapping relationship between function names and function name translation results according to the function name of each base class function in the test base class, and then generate a use case directory according to the function names in the test base class and the order of the function names, or to generate a use case directory according to the translation results of the function names in the first configuration file and the order of the function name translation results.

[0055] In one embodiment, the apparatus further comprises:

[0056] The inserting unit is used to insert the precondition name as a first-level directory into the use case directory after the use case directory is generated.

[0057] In one embodiment, the conversion unit is configured to store all test cases in a json file according to the order of contents of the use case directory, and convert the json file into executable test case code;

[0058] The second generating unit is further configured to, before adding the calling code to the test case code to obtain the target test case code, generate a calling code for calling the precondition corresponding to the precondition name if the test case directory includes a precondition name;

[0059] The adding unit is also used to add the calling code of the precondition to the test case code.

[0060] In one embodiment, the apparatus further comprises:

[0061] The sixth generation unit is used to obtain a target exhaustive module added by the user from at least one exhaustive module in the editing interface of the test case template after generating a test case including use case fields and use case field values, so as to perform exhaustive testing based on the target exhaustive module when executing the test case code corresponding to the test case template, wherein the exhaustive module is generated according to the exhaustive range input by the user and the preset exhaustive algorithm.

[0062] In one embodiment, the preset test case execution logic includes test case execution logic and test result judgment logic;

[0063] The test case execution logic includes: executing the corresponding test case code in the order of the base class functions in the test base class, saving the test case execution result with the status code value as the preset status code value in the preset json data body format, when the test case to be executed needs to call the target test case execution result, if the Nth execution result in the target test case execution result is a correct result, calling the Nth execution result in accordance with the calling format corresponding to the preset json data body format; if the Nth execution result in the target test case execution result is an error result, calling the N+1th execution result in the target test case execution result in accordance with the calling format corresponding to the preset json data body format, wherein the target test case execution result is all execution results of the target test case, and N is a positive integer;

[0064] The test result judgment logic includes: when a status code is defined in the test base class, determining whether the program tested by the target test case template is normal by determining whether the target status code defined in the test base class is the same as the status code set in the target test case, wherein the target status code corresponds to the target test case; when test content is defined in the test base class and the preset use case field includes a test result, when the target test result in the target test case takes a value of 1, determining whether the program tested by the target test case is normal by determining whether the test case execution result saved in a preset json data body format is the same as the test content defined in the test base class; when the target test result in the target test case takes a value of 0, determining whether the program tested by the target test case is normal by determining whether the target test content in the target test case is the same as the test content defined in the test base class.

[0065] In a third aspect, an embodiment of the present invention provides a storage medium having executable instructions stored thereon, which, when executed by a processor, enables the processor to implement the method described in any one of the embodiments of the first aspect.

[0066] In a fourth aspect, an embodiment of the present invention provides an electronic device, including:

[0067] one or more processors;

[0068] a storage device for storing one or more programs,

[0069] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the embodiments of the first aspect.

[0070] From the above content, it can be seen that the test method based on test cases provided by the embodiment of the present invention can first obtain a pre-set test base class related to the business, and then generate a test case template corresponding to each base class function according to the preset use case field and the function information of each base class function in the test base class, obtain the use case field value edited based on the test case template, generate a test case including the use case field and the use case field value, and when the target execution number meets the preset number requirement, according to the order of the base class function corresponding to the test case in the test base class, convert all test cases into executable test case code, generate a call code for calling the preset test case execution logic, and add the call code to the test case code to obtain the target test case code, so as to perform a use case test based on the target test case code. It can be seen that in the entire test case code generation process, the tester only needs to write the test base class and input the use case field value without performing other programming operations, thereby simplifying the difficulty of generating the test case code, thereby improving the efficiency of generating the test case code and reducing the professional requirements for the tester.

[0071] The technical effects that can also be achieved by the embodiments of the present invention include:

[0072] 1. By generating a first configuration file and a second configuration file according to a test base class, and generating a test case template that is easier for testers to read based on the first configuration file and the second configuration file, the user experience is improved.

[0073] 2. In order to improve the efficiency of test case generation and avoid testers from performing repetitive operations, you can configure a data generator for the test case field so that the data generator can automatically generate the test case field value.

[0074] 3. By configuring preconditions, more complex test logic can be implemented simply and efficiently.

[0075] 4. By setting up an exhaustive module, testers can avoid performing repetitive exhaustive operations, thereby improving the efficiency of exhaustive testing.

[0076] Of course, it is not necessary to achieve all of the advantages described above simultaneously in order to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely some embodiments of the present invention. Those skilled in the art can derive other drawings based on these drawings without inventive effort.

[0078] Figure 1A flowchart of a test method based on a test case provided by an embodiment of the present invention;

[0079] Figure 2 An example diagram of a test case template provided by an embodiment of the present invention;

[0080] Figure 3 Another example diagram of a test case template provided by an embodiment of the present invention;

[0081] Figure 4 An example diagram of a use case directory provided by an embodiment of the present invention;

[0082] Figure 5 Another example diagram of a use case directory provided by an embodiment of the present invention;

[0083] Figure 6 A test case test platform architecture diagram provided by an embodiment of the present invention;

[0084] Figure 7 A schematic diagram of an editing precondition module provided by an embodiment of the present invention;

[0085] Figure 8 Another test case test platform architecture diagram provided by an embodiment of the present invention;

[0086] Figure 9 A diagram of another test case test platform architecture provided by an embodiment of the present invention;

[0087] Figure 10 A block diagram of a test device based on test cases provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0088] The following will provide a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0089] It should be noted that the terms "including" and "having" and any variations thereof in the embodiments of the present invention and the accompanying drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to the process, method, product, or apparatus.

[0090] Figure 1This is a flow chart of a test method based on test cases. This method can be applied to a test case test platform or to the back end of a test case test platform. When the method is applied to the test case test platform, the front end of the test case test platform can interact with the user to obtain user input data, and send the user input data to the back end for processing. When the method is applied to the back end of the test case test platform, the back end can receive the user input data sent by the front end and process the received data. The method may include the following steps:

[0091] S110: Acquire a pre-set business-related test base class.

[0092] During implementation, testers (i.e., users) can create a test project on the frontend and select a test base class file to transfer to the backend. The backend can then import the standard libraries or extension libraries required by the tester to encapsulate the program in the test base class. The test base class defines business logic variables such as user credentials and business addresses as internal keywords, and encapsulates the modification methods of these internal keywords to generate dynamic parameters. The response body, or return value, defined in the test base class includes a status code and test content:

[0093] The return value of the interface (i.e., response) already has two attributes: status code and test content, so you can simply return response in the base class function. In front-end and mobile testing, you need to define a response object that contains status code and content attributes, assign values to the two attributes of response in the base class function, and then return response. In actual testing, the status code of the interface is defined by the developer, so asserting the status code is necessary. However, in front-end and mobile testing, the developer does not define the status code. It is only added by the test system to be compatible with multi-terminal testing. Therefore, you can assign the status code value to None when defining the response object, and then only process the test content. However, you can add status codes to define whether the test element is visible, clickable, or locatable, etc., to facilitate subsequent test result analysis.

[0094] S120: Generate a test case template corresponding to each base class function according to the preset use case field and the function information of each base class function in the test base class.

[0095] Among them, the function information includes the function name and function input parameters, the test case template includes the use case name generated based on the function name of each base class function, the business use case field generated based on the function input parameters of each base class function and the preset use case field, the preset use case field includes the status code, the number of executions, and may also include the use case number, use case type, login user, test content, and test results. The use case number is used to identify the use case, and the use case type is used to indicate the type of use case. For example, the use case can be divided into business login class and business use class. The test content includes the specific content to be tested, and the test result includes true or false. The business use case field may include user name, password, role, etc.

[0096] Exemplarily, the definition of the base class function in the test base class can be as described in Text 1, wherein login and users_add are the function names of the base class function, self, username, and password are the function input parameters of the login function, and self, username, password, and role are the function input parameters of the users_add function.

[0097] Text 1

[0098]

[0099] Methods for generating test case templates include but are not limited to the following two:

[0100] (A1) Generate test case templates directly based on the test base class

[0101] For the base class function to be processed in the test base class, the function name of the base class function to be processed is used as the use case name corresponding to the base class function to be processed, and the function input parameter of the base class function to be processed is used as the business use case field corresponding to the base class function to be processed. According to the preset use case field, the use case name and business use case field corresponding to the base class function to be processed, a test case template corresponding to the base class function to be processed is generated.

[0102] As shown in Text 1, the use case name of the test case template corresponding to the first base class function can be login, and the business use case fields include self, username, and password.

[0103] (A2) First generate a configuration file based on the test base class, and then generate a test case template based on the configuration file

[0104] A first configuration file including a mapping relationship between a function name and a function name translation result is generated based on the function name of each base class function in the test base class, and a second configuration file including a mapping relationship between a function input parameter and a function input parameter translation result is generated based on the function input parameter of each base class function in the test base class. The translation result of the function name to be processed in the first configuration file is used as the use case name corresponding to the translation result of the function name to be processed, and the translation result of the function input parameter corresponding to the translation result of the base class function to be processed in the second configuration file is used as the business use case field corresponding to the translation result of the function name to be processed. A test case template corresponding to the translation result of the function name to be processed is generated based on the preset use case field, the use case name corresponding to the translation result of the function name to be processed, and the business use case field. After the first configuration file and the second configuration file are created, they can be bound to the test base class.

[0105] The function name translation result can be determined according to the translation requirements of the tester. For example, when the tester requires translation into Chinese, the function name translation result can be expressed in Chinese. The embodiment of the present invention can create configuration files compatible with different operating systems and support four formats: ini, json, yaml, and csv.

[0106] When creating the first configuration file in INI format, use the business module name as the first-level key, the Chinese abbreviation of the business under it (i.e., the translation result of the function name) as the second-level key, and the function name of the base class function as the value of the second-level key; the first configuration file in JSON format has a similar structure to the configuration file in INI format; when creating the first configuration file in YAML format, change the second-level key value in INI format to the third-level key; when creating the first configuration file in CSV format, use the first-level key as the sheet name, and write the second-level key-value pairs into the table row by row.

[0107] When creating the second configuration file, the ini format file uses the function input parameters and the translation results of the function input parameters as the second-level key-value pairs, and the first-level key name is arbitrary; the json format file directly uses the function input parameters and the translation results of the function input parameters as the first-level key-value pairs; the yaml format file splits the above key-value pairs into the first-level key and the second-level key; the csv format file writes the data in separate lines into the table.

[0108] When the test base class includes text one, the first configuration file in ini format can be shown as text two, and the second configuration file in ini format can be shown as text three. The test case templates corresponding to the two base class functions generated according to the first configuration file and the second configuration file can be shown as follows. Figure 2 and Figure 3 shown. Figure 2The test case template has a use case name of user login. The preset use case fields include use case number, use case name, login user, test result, status code, test content, and execution times. The business use case fields include user name and password. Figure 3 The test case template has the use case name "Add User". The preset use case fields include use case number, use case name, login user, test result, status code, test content and execution times. The business use case fields include user name, password and role.

[0109] Text 2

[0110]

[0111] Text Three

[0112]

[0113] In one embodiment, after generating a first configuration file including a mapping relationship between a function name and a function name translation result based on the function name of each base class function in the test base class, an embodiment of the present invention can generate a use case directory based on the function names in the test base class and the order of the function names; or generate a use case directory based on the function name translation results and the order of the function name translation results in the first configuration file. Displaying the test base class as a directory can facilitate retrieval and subsequent maintenance, and the platform supports online editing and saving. For example, the use case directory generated based on the test base class of text one can be as follows Figure 4 As shown, the use case directory generated according to the first configuration file .ini can be as follows Figure 5 As shown. Among them, Figure 4 and Figure 5 The precondition names are inserted into the use case directory of . The preconditions are detailed below.

[0114] It should be added that, Figure 6 As shown, steps S110 and S120 can be completed by the project construction module 21 in the test case test platform.

[0115] S130: Acquire the use case field values edited based on the test case template, and generate a test case including the use case fields and the use case field values.

[0116] Among them, each test case corresponds to a test case template, that is, when different use case field values are entered for the use case fields in the same test case template, different test cases can be generated, thereby achieving the effect of implementing multiple tests for the same test case template.

[0117] After the test case template is generated, the test case template can be displayed to the tester, so that the tester can select the test case template to be used, edit the test case template, input the corresponding use case field value, and generate a test case. In actual applications, some use case fields may require the input of multiple use case field values to implement testing. If manual input is time-consuming and labor-intensive, in order to improve the efficiency of obtaining use case field values, a data generator can be used for automatic generation. That is, when there is no corresponding data generator for the use case field to be edited in the test case template, the use case field value of the use case field to be edited input by the user is obtained; when there is at least one corresponding data generator for the use case field to be edited in the test case template, the target data generator selected by the user from the at least one data generator is obtained, and the use case field value of the use case field to be edited is automatically generated based on the target data generator.

[0118] The methods for generating data generators include but are not limited to the following two:

[0119] (B1) Obtain the target character combination mode, target field minimum length and target field maximum length input by the user in the generator creation interface, and generate a data generator for the use case field to be edited based on the target character combination mode, target field minimum length and target field maximum length, wherein the target character combination mode, target field minimum length and target field maximum length are respectively the character combination mode, field minimum length and field maximum length for the use case field to be edited. A data generation function name will be generated inside the data generator based on the target character combination mode, target field minimum length and target field maximum length for execution. The data generator name can be automatically generated based on the data generation function name, or named by the user. After generating this information, it can be written into the data table for search use. After generating the data generator, the addition result can be displayed to the user, for example, in the form of "data generation function (target field minimum length, target field maximum length)".

[0120] For example, the selectable character types include lowercase English, uppercase English, numbers, and some special symbols. The user can select a combination of lowercase English, uppercase English, and numbers as the target character combination. The minimum length of the target field can be set to 8, and the maximum length of the target field can be set to 15.

[0121] like Figure 6 As shown, the tester can edit in the data module 25 used to generate the data generator, enter a name (i.e., the data generator name), select characters, define the character length, and define the scope to generate the data generator. The test case testing platform will load the data generator into the use case module 22 for generating test cases, so that the user can edit the test case template to generate test cases.

[0122] (B2) obtaining a data generator script for the use case field to be edited, which is imported by the user in the generator creation interface, and generating a data generator for the use case field to be edited based on the data generator script, wherein the data generator script includes a data generation function, and the data generation function is used to define the character combination method, the minimum field length, and the maximum field length of the use case field to be edited.

[0123] In addition, after the data generator is generated, the code of the data generator will be stored in the database for execution and calling.

[0124] In ordinary manual testing, exhaustive testing is an extremely wasteful test direction in terms of manpower and material resources. Therefore, testers will use decision tables to reduce test cases while still covering most of the business logic. However, in reality, some business logic will be missed. Therefore, in order to exhaustively test the business logic without increasing the tester's workload, an embodiment of the present invention provides testers with a function for adding an exhaustive module. After generating a test case, the target exhaustive module added by the user from at least one exhaustive module is obtained in the editing interface of the test case template. When executing the test case code corresponding to the test case template, exhaustive testing is performed based on the target exhaustive module, wherein the exhaustive module is generated based on the exhaustive range input by the user and a preset exhaustive algorithm.

[0125] The preset exhaustive algorithm of the exhaustive module can be pre-written by technical personnel. Taking abnormal editing as an example, 1 editing object parameter and 6 variable parameters are specified, and the 6 variable parameters all have restrictions on length and available characters. First, edit the object to obtain the test case; then add the dynamic data test tool to the 6 variable parameters, all of which need to be legal values; fill in the algorithm processing range (i.e., the exhaustive range) with the number of executions, which is 6 here. The preset exhaustive algorithm will obtain error data based on the test tools added to the variable parameters: the length is too long and there are no illegal characters, the length is too short and there are no illegal characters, the length is legal and there are illegal characters, the length is too long and there are illegal characters, the length is too short and there are illegal characters, and empty. Calculate all possible permutations and combinations based on the number of executions, and then compare them with the number of executions in the test case of the edited object. If the number of cases is large, it will prompt that the input exhaustive range does not meet the conditions. If the conditions are met, the algorithm will construct all possible test cases, and the edited objects will be accumulated in sequence from the beginning of the filling.

[0126] An exhaustive test of a certain input or selection function may correspond to hundreds or even thousands of test cases, many of which are expected to fail. Manually setting the expectations for each test case is unrealistic. Therefore, the exhaustive module also has test result judgment logic, which can automatically generate assertions based on conditions such as the number of variable parameters, whether there are default values for variable parameters, and whether the data is legal, to adapt to different test scenarios. For example, if the set character length is 8-10 (i.e., the exhaustive range), then the status code for character lengths within the range of 8-10 is definitely 200, and the status code outside this range is definitely not 200.

[0127] In one embodiment, the test case testing platform may further define preset test case execution logic, where the preset test case execution logic includes test case calling logic and test result judgment logic.

[0128] The test case execution logic includes: executing the corresponding test case code in the order of the base class functions in the test base class, saving the test case execution result with the status code value as the preset status code value (such as 200) in the preset json data body format, and when the test case to be executed needs to call the target test case execution result, if the Nth execution result in the target test case execution result is a correct result, then calling the Nth execution result according to the calling format corresponding to the preset json data body format; if the Nth execution result in the target test case execution result is an error result, then calling the N+1th execution result in the target test case execution result according to the calling format corresponding to the preset json data body format, wherein the target test case execution result is all execution results of the target test case, and N is a positive integer.

[0129] When the first configuration file is included, the corresponding test case code can also be executed directly in the order of the contents of the first configuration file. The preset json data body format can be {case number-Nth time: {all Nth execution results in json data format}}, where Nth time refers to the Nth execution. When calling a test parameter (i.e., a case field) of the Nth execution result in the target test case execution result, the calling method can be "case number-Nth time_test parameter", and the current position of the read data in the json data can also be recorded to facilitate subsequent calls.

[0130] When multiple test cases need to call the return value of the same test case, the above test case calling logic can avoid the chain reaction caused by the failure of the previous test case execution, thereby improving the reuse of test cases.

[0131] The test result judgment logic includes: when a status code is defined in the test base class, determining whether the program tested by the target test case template is normal by determining whether the target status code defined in the test base class is the same as the status code set in the target test case, wherein the target status code corresponds to the target test case; when test content is defined in the test base class and the preset use case field includes a test result, when the target test result in the target test case takes a value of 1, determining whether the program tested by the target test case is normal by determining whether the test case execution result saved in a preset json data body format is the same as the test content defined in the test base class; when the target test result in the target test case takes a value of 0, determining whether the program tested by the target test case is normal by determining whether the target test content in the target test case is the same as the test content defined in the test base class.

[0132] When the targets to be judged are the same, it is determined that the program tested by the target test case template is normal. When the targets to be judged are different, it is determined that the program tested by the target test case template is abnormal. The targets to be judged include status code, test content, test case execution results, etc.

[0133] In one embodiment, in order to provide testers with more complex test case execution logic, especially logic with global execution requirements, the embodiment of the present invention can also set preconditions. Specifically, the test case testing platform obtains the precondition information input by the user in the precondition creation interface, wherein the precondition information includes the precondition name, at least one pre-step, the return parameter corresponding to each pre-step and the return parameter value corresponding to each pre-step, and the pre-step is the step required to obtain the return parameter; the precondition is generated based on the precondition information. After the precondition is generated, the precondition name can be inserted into the use case directory as a first-level directory to serve as an entry for calling the precondition. Of course, a first-level directory named precondition can also be generated in the use case directory in advance, and the user can link to the precondition module for generating the precondition by clicking on the first-level directory and edit it in the precondition module. It should be added that in order to improve test efficiency and simplify test logic, if the function input parameters in the test base class are set in the preconditions for easier calling and testing, the function input parameters of the test base class (such as user name, password) can be set in the preconditions. The embodiment of the present invention does not limit the function of the preconditions.

[0134] like Figure 6 and Figure 7As shown, assuming that the tester needs to complete a software upgrade task, the tester can edit the precondition module 26 used to generate the precondition, enter the precondition name, and add three precondition steps respectively. The precondition steps are add software (i.e. add the original software, the automatically generated step number is step1), add software (i.e. add the target software, the automatically generated step number is step2), and add the upgrade task (the automatically generated step number is step3). The return parameter of step1 is id (i.e. the id of the original software), and the return parameter value is step1-id; the return parameter of step2 is id (i.e. the id of the target software), and the return parameter value is step2-id; the return parameter of step3 is id (i.e. the id of the target software), and the return parameter value is step3-id. After editing, click Save to generate the precondition, where the precondition module 26 can automatically generate the creation time of the precondition. As shown Figure 6 As shown, after the precondition is generated, the precondition name can be inserted into the use case directory as a first-level directory as an entry for calling the precondition, wherein the use case directory can be generated in the project construction module 21 and imported into the use case module 22, so that the use case code construction module 23 can directly obtain the required use case directory and test cases from the use case module 22 when constructing the test case code.

[0135] S140: When the target execution times meet the preset times requirement, all test cases are converted into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class.

[0136] Among them, the target execution number is the sum of the execution times of all test cases whose status codes are preset status code values. The preset status code value can be 200, and the preset number requirement can be determined according to the actual situation. When the target execution number is greater than or equal to the preset number threshold, it is determined that the preset number requirement is met. When the target execution number is less than the preset number threshold, it is determined that the preset number requirement is not met. If the target execution number meets the preset number requirement, all test cases are converted into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class. If the target execution number does not meet the preset number requirement, it is determined that the test case creation has failed.

[0137] After the use case directory is generated, all test cases can be directly stored in a json file according to the sequence of the contents of the use case directory, and the json file can be converted into executable test case code.

[0138] S150: Generate a calling code for calling a preset test case execution logic, and add the calling code to the test case code to obtain a target test case code, so as to perform a test case test based on the target test case code.

[0139] If the test case directory includes a precondition name, a call code for calling the precondition corresponding to the precondition name is generated and added to the test case code. Since preconditions are generally global conditions, the call code for the precondition can be added to the beginning of the test case code. In addition, after obtaining the target test case code, the target test case code can be stored in a test case code library.

[0140] It should be added that, Figure 6 As shown, all test case templates, test cases, preconditions, target test case codes, and other information for a test project can be stored in a project common library. That is, the project common library includes a code library for pre-keywords (i.e., return parameters in preconditions), a code library for data generators, and a code library for test cases. Steps S140 and S150 can be completed by the test case code construction module 23 in the test case testing platform.

[0141] like Figure 6 As shown, after generating the target test case code, the tester can select the use case type in the test task adding interface of the test task construction module 24 to build the task. The back end of the test case testing platform can extract the test cases contained in the test task from the project public library and generate a temporary test file. Then execute the test file to obtain the execution result of the test case. After the construction is completed, you can click to view the test report of the task, which includes the result statistics chart of the test case and the specific test case execution status. The specific execution status includes the use case number, use case name, specific execution result, execution start time and execution end time. Failed test cases can be clicked to verify and re-executed, and the test case code file can be downloaded and obtained.

[0142] The test case-based testing method provided by the embodiment of the present invention can first obtain a pre-set test base class related to the business, then generate a test case template corresponding to each base class function based on the preset use case field and the function information of each base class function in the test base class, obtain the use case field value edited based on the test case template, generate a test case including the use case field and the use case field value, and when the target execution number meets the preset number requirement, convert all test cases into executable test case code according to the order of the base class functions corresponding to the test case in the test base class, generate a call code for calling the preset test case execution logic, and add the call code to the test case code to obtain the target test case code, so as to perform a use case test based on the target test case code. It can be seen that in the entire test case code generation process, the tester only needs to write the test base class and enter the use case field value without performing other programming operations, thereby simplifying the difficulty of test case code generation, thereby improving the efficiency of test case code generation, and reducing the professional requirements for testers. By generating a first configuration file and a second configuration file based on the test base class, and generating a test case template that is easier for testers to read based on the first configuration file and the second configuration file, the user experience is improved. To improve test case generation efficiency and avoid repetitive operations, you can configure a data generator for each test case field, allowing it to automatically generate values for the test case field. Configuring preconditions allows for simple and efficient implementation of more complex test logic. Setting up an exhaustive module prevents testers from performing repetitive exhaustive operations, thereby improving exhaustive testing efficiency.

[0143] Corresponding to the above method embodiment, the embodiment of the present invention provides a test case testing platform, covering mainstream testing functions such as web terminal testing, mobile terminal testing, stress testing, system performance testing, etc. Figure 8 As shown, the test case testing platform includes a project construction module 21, a use case module 22, a use case code construction module 23, and a test task construction module 24.

[0144] The project construction module 21 is used to construct a business-related test base class, and generate a test case template corresponding to each base class function based on the preset use case field and the function information of each base class function in the test base class, wherein the function information includes the function name and function input parameters, and the test case template includes a use case name generated based on the function name of each base class function, a business use case field generated based on the function input parameters of each base class function, and the preset use case field, and the preset use case field includes a status code and execution times.

[0145] The use case module 22 is configured to obtain the test case template constructed by the project construction module 21, obtain the use case field values edited based on the test case template, and generate a test case including the use case fields and the use case field values, wherein each test case corresponds to a test case template. The use case module 22 also includes preset test case execution logic.

[0146] The use case code construction module 23 is used to convert all test cases into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class when the target execution number meets the preset number requirement, generate a calling code for calling the preset test case execution logic, and add the calling code to the test case code to obtain the target test case code, wherein the target execution number is the sum of the execution times of all test cases whose status codes take the preset status code values.

[0147] The test task construction module 24 is used to generate a test task according to the task test requirements input by the user, obtain the test case code corresponding to the test task, generate a test file according to the obtained test case code, execute the test file to obtain and output the test case execution result.

[0148] In one embodiment, the project construction module 21 is used to, for the base class function to be processed in the test base class, use the function name of the base class function to be processed as the use case name corresponding to the base class function to be processed, use the function input parameter of the base class function to be processed as the business use case field corresponding to the base class function to be processed, and generate a test case template corresponding to the base class function to be processed according to the preset use case field, the use case name corresponding to the base class function to be processed, and the business use case field; or, generate a first configuration file including a mapping relationship between a function name and a function name translation result according to the function name of each base class function in the test base class, generate a second configuration file including a mapping relationship between a function input parameter and a function input parameter translation result according to the function input parameter of each base class function in the test base class, use the translation result of the function name to be processed in the first configuration file as the use case name corresponding to the translation result of the function name to be processed, use the translation result of the function input parameter corresponding to the translation result of the base class function to be processed in the second configuration file as the business use case field corresponding to the translation result of the function name to be processed, and generate a test case template corresponding to the translation result of the function name to be processed according to the preset use case field, the use case name corresponding to the translation result of the function name to be processed, and the business use case field.

[0149] In one embodiment, Figure 9 As shown, the test case testing platform also includes a data module 25 .

[0150] Data module 25 is used to obtain the target character combination method, target field minimum length and target field maximum length input by the user in the generator creation interface, and generate a data generator for the use case field to be edited based on the target character combination method, the target field minimum length and the target field maximum length, wherein the target character combination method, the target field minimum length and the target field maximum length are the character combination method, field minimum length and field maximum length for the use case field to be edited, respectively; or, obtain the data generator script for the use case field to be edited imported by the user in the generator creation interface, and generate a data generator for the use case field to be edited based on the data generator script, wherein the data generator script includes a data generation function, and the data generation function is used to define the character combination method, field minimum length and field maximum length of the use case field to be edited.

[0151] In one embodiment, the use case module 22 is used to obtain the use case field value of the use case field to be edited input by the user when there is no corresponding data generator for the use case field to be edited in the test case template; when the use case field to be edited in the test case template has at least one corresponding data generator, obtain the target data generator selected by the user from the at least one data generator, and automatically generate the use case field value of the use case field to be edited based on the target data generator.

[0152] In one embodiment, Figure 9 As shown, the test case testing platform also includes a precondition module 26.

[0153] The precondition module 26 is used to obtain the precondition information entered by the user in the precondition creation interface, wherein the precondition information includes the precondition name, at least one precondition step, the return parameter corresponding to each of the precondition steps, and the return parameter value corresponding to each of the precondition steps. The precondition step is the step required to obtain the return parameter, and the precondition is generated based on the precondition information.

[0154] In one embodiment, the project construction module 21 is further used to generate a first configuration file including a mapping relationship between function names and function name translation results according to the function name of each base class function in the test base class, and then generate a use case directory according to the function names and the order of function names in the test base class; or, generate a use case directory according to the translation results of each function name and the order of function name translation results in the first configuration file.

[0155] In one embodiment, the project construction module 21 is further configured to insert the precondition name as a first-level directory into the use case directory after generating the use case directory.

[0156] In one embodiment, the use case code construction module 23 is used to store all test cases in a json file according to the sequence of the contents of the use case directory, and convert the json file into executable test case code.

[0157] In one embodiment, the use case code construction module 23 is used to generate a calling code for calling the precondition corresponding to the precondition name if the use case directory includes a precondition name before adding the calling code to the test case code to obtain the target test case code, and add the calling code of the precondition to the test case code.

[0158] In one embodiment, Figure 9 As shown, the test case testing platform also includes an exhaustive testing module 27.

[0159] The exhaustive testing module 27 is used to obtain the exhaustive range input by the user and generate an exhaustive module according to the exhaustive range input by the user and a preset exhaustive algorithm.

[0160] In one embodiment, the use case module 22 is used to obtain a target exhaustive module added by the user from at least one exhaustive module in the editing interface of the test case template after generating a test case including use case fields and use case field values, so as to perform exhaustive testing based on the target exhaustive module when executing the test case code corresponding to the test case template.

[0161] In one embodiment, the preset test case execution logic includes test case execution logic and test result judgment logic; the test case execution logic includes: executing the corresponding test case code in the order of the base class functions in the test base class, and saving the test case execution result with the status code value as the preset status code value in the preset json data body format; when the test case to be executed needs to call the target test case execution result, if the Nth execution result in the target test case execution result is a correct result, then the Nth execution result is called according to the calling format corresponding to the preset json data body format; if the Nth execution result in the target test case execution result is an error result, then the N+1th execution result in the target test case execution result is called according to the calling format corresponding to the preset json data body format, wherein the target test case execution result is all execution results of the target test case, and N is a positive integer. ; The test result judgment logic includes: when a status code is defined in the test base class, determining whether the program tested by the target test case template is normal by determining whether the target status code defined in the test base class is the same as the status code set in the target test case, wherein the target status code corresponds to the target test case; when test content is defined in the test base class and the preset use case field includes a test result, when the target test result in the target test case takes a value of 1, determining whether the program tested by the target test case is normal by determining whether the test case execution result saved in the preset json data body format is the same as the test content defined in the test base class; when the target test result in the target test case takes a value of 0, determining whether the program tested by the target test case is normal by determining whether the target test content in the target test case is the same as the test content defined in the test base class.

[0162] Corresponding to the above method embodiment, the embodiment of the present invention provides a test device based on test cases, such as Figure 10 As shown, the device includes:

[0163] The first acquiring unit 31 is configured to acquire a preset service-related test base class.

[0164] The first generation unit 32 is used to generate a test case template corresponding to each base class function based on the preset use case field and the function information of each base class function in the test base class, wherein the function information includes the function name and function input parameters, and the test case template includes a use case name generated based on the function name of each base class function, a business use case field generated based on the function input parameters of each base class function, and the preset use case field, and the preset use case field includes a status code and execution times.

[0165] The second acquiring unit 33 is configured to acquire the use case field values edited based on the test case template, and generate a test case including the use case fields and the use case field values, wherein each test case corresponds to a test case template.

[0166] The conversion unit 34 is used to convert all test cases into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class when the target execution number meets the preset number requirement, wherein the target execution number is the sum of the execution times of all test cases whose status codes take the preset status code values.

[0167] The second generating unit 35 is used to generate a calling code for calling the preset test case execution logic.

[0168] The adding unit 36 is configured to add the calling code to the test case code to obtain a target test case code, so as to perform a test case test based on the target test case code.

[0169] In one embodiment, the first generating unit 32 includes: a first generating module or a second generating module.

[0170] The first generation module is used to use the function name of the base class function to be processed in the test base class as the use case name corresponding to the base class function to be processed, and the function input parameter of the base class function to be processed as the business use case field corresponding to the base class function to be processed, and generate a test case template corresponding to the base class function to be processed according to the preset use case field, the use case name and business use case field corresponding to the base class function to be processed.

[0171] The second generation module is used to generate a first configuration file including a mapping relationship between a function name and a function name translation result according to the function name of each base class function in the test base class, generate a second configuration file including a mapping relationship between a function input parameter and a function input parameter translation result according to the function input parameter of each base class function in the test base class, use the translation result of the function name to be processed in the first configuration file as the use case name corresponding to the translation result of the function name to be processed, use the translation result of the function input parameter corresponding to the translation result of the base class function to be processed in the second configuration file as the business use case field corresponding to the translation result of the function name to be processed, and generate a test case template corresponding to the translation result of the function name to be processed according to the preset use case field, the use case name corresponding to the translation result of the function name to be processed, and the business use case field.

[0172] In one embodiment, the second obtaining unit 33 includes:

[0173] The first acquisition module is used to acquire the use case field value of the use case field to be edited input by the user when there is no corresponding data generator for the use case field to be edited in the test case template.

[0174] The second acquisition module is used to obtain the target data generator selected by the user from the at least one data generator when the use case field to be edited in the test case template has a corresponding at least one data generator, and automatically generate the use case field value of the use case field to be edited based on the target data generator.

[0175] In one embodiment, the apparatus further comprises:

[0176] The third generating unit is used to obtain the target character combination mode, target field minimum length and target field maximum length input by the user in the generator creation interface before obtaining the target data generator selected by the user from the at least one data generator, and generate the data generator for the use case field to be edited based on the target character combination mode, target field minimum length and target field maximum length, wherein the target character combination mode, target field minimum length and target field maximum length are the character combination mode, field minimum length and field maximum length for the use case field to be edited, respectively; or, obtain the data generator script for the use case field to be edited imported by the user in the generator creation interface, and generate the data generator for the use case field to be edited based on the data generator script, wherein the data generator script includes a data generation function, and the data generation function is used to define the character combination mode, field minimum length and field maximum length of the use case field to be edited.

[0177] In one embodiment, the apparatus further comprises:

[0178] The third acquisition unit is used to obtain the precondition information entered by the user in the precondition creation interface, wherein the precondition information includes the precondition name, precondition steps, return parameters and the path of the return parameters, the return parameters include at least one use case field, and the precondition steps are the steps required to generate the return parameters.

[0179] A fourth generating unit is configured to generate a precondition based on the precondition information.

[0180] In one embodiment, the apparatus further comprises:

[0181] The fifth generation unit is used to generate a first configuration file including a mapping relationship between function names and function name translation results according to the function name of each base class function in the test base class, and then generate a use case directory according to the function names in the test base class and the order of the function names, or to generate a use case directory according to the translation results of the function names in the first configuration file and the order of the function name translation results.

[0182] In one embodiment, the apparatus further comprises:

[0183] The inserting unit is used to insert the precondition name as a first-level directory into the use case directory after the use case directory is generated.

[0184] In one embodiment, the conversion unit 34 is configured to store all test cases in a json file according to the sequence of contents of the use case directory, and convert the json file into executable test case code.

[0185] The second generating unit 35 is also used to generate a calling code for calling the precondition corresponding to the precondition name if the case directory includes a precondition name before adding the calling code to the test case code to obtain the target test case code.

[0186] The adding unit 36 is further configured to add the calling code of the precondition to the test case code.

[0187] In one embodiment, the apparatus further comprises:

[0188] The sixth generation unit is used to obtain a target exhaustive module added by the user from at least one exhaustive module in the editing interface of the test case template after generating a test case including use case fields and use case field values, so as to perform exhaustive testing based on the target exhaustive module when executing the test case code corresponding to the test case template, wherein the exhaustive module is generated according to the exhaustive range input by the user and the preset exhaustive algorithm.

[0189] In one embodiment, the preset test case execution logic includes test case execution logic and test result judgment logic.

[0190] The test case execution logic includes: executing the corresponding test case code in the order of the base class functions in the test base class, saving the test case execution result with the status code value as the preset status code value in the preset json data body format, and when the test case to be executed needs to call the target test case execution result, if the Nth execution result in the target test case execution result is a correct result, calling the Nth execution result in accordance with the calling format corresponding to the preset json data body format; if the Nth execution result in the target test case execution result is an error result, calling the N+1th execution result in the target test case execution result in accordance with the calling format corresponding to the preset json data body format, wherein the target test case execution result is all execution results of the target test case, and N is a positive integer.

[0191] The test result judgment logic includes: when a status code is defined in the test base class, determining whether the program tested by the target test case template is normal by determining whether the target status code defined in the test base class is the same as the status code set in the target test case, wherein the target status code corresponds to the target test case; when test content is defined in the test base class and the preset use case field includes a test result, when the target test result in the target test case takes a value of 1, determining whether the program tested by the target test case is normal by determining whether the test case execution result saved in a preset json data body format is the same as the test content defined in the test base class; when the target test result in the target test case takes a value of 0, determining whether the program tested by the target test case is normal by determining whether the target test content in the target test case is the same as the test content defined in the test base class.

[0192] Based on the above method embodiment, another embodiment of the present invention provides a storage medium having executable instructions stored thereon, which, when executed by a processor, enables the processor to implement the above method.

[0193] Based on the above method embodiment, another embodiment of the present invention provides an electronic device, including:

[0194] one or more processors;

[0195] a storage device for storing one or more programs,

[0196] When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.

[0197] The above platform and device embodiments correspond to the method embodiments and have the same technical effects as the method embodiments. For detailed descriptions, please refer to the method embodiments. The device embodiments are obtained based on the method embodiments. For detailed descriptions, please refer to the method embodiments section and will not be repeated here. Those skilled in the art will understand that the accompanying drawings are only schematic diagrams of one embodiment, and the modules or processes in the accompanying drawings are not necessarily required to implement the present invention.

[0198] Those skilled in the art will appreciate that the modules in the apparatuses of the embodiments may be distributed throughout the apparatuses of the embodiments as described in the embodiments, or may be located in one or more apparatuses different from the embodiments with corresponding modifications. The modules in the above embodiments may be combined into one module or further divided into multiple submodules.

[0199] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A test method based on test cases, characterized in that: The method comprises: Get the pre-set business-related test base class; Generate a test case template corresponding to each base class function according to the preset use case field and the function information of each base class function in the test base class, wherein the function information includes the function name and function input parameters, and the test case template includes a use case name generated based on the function name of each base class function, a business use case field generated based on the function input parameters of each base class function, and the preset use case field, and the preset use case field includes a status code and the number of executions; Obtaining a use case field value edited based on the test case template, and generating a test case including a use case field and a use case field value, wherein each test case corresponds to a test case template; When the target number of executions meets the preset number requirement, all test cases are converted into executable test case codes according to the order of the base class functions corresponding to the test cases in the test base class, wherein the target number of executions is the sum of the execution times of all test cases whose status codes have the preset status code values; Generate a call code for calling a preset test case execution logic, and add the call code to the test case code to obtain a target test case code, so as to perform a test case test based on the target test case code; Generate a test case template corresponding to each base class function according to the preset use case field and the function information of each base class function in the test base class, including: A first configuration file including a mapping relationship between a function name and a translation result of the function name is generated according to the function name of each base class function in the test base class; a second configuration file including a mapping relationship between a function input parameter and a translation result of the function input parameter is generated according to the function input parameter of each base class function in the test base class; the translation result of the function name to be processed in the first configuration file is used as the use case name corresponding to the translation result of the function name to be processed; the translation result of the function input parameter corresponding to the translation result of the function to be processed in the second configuration file is used as the business use case field corresponding to the translation result of the function name to be processed; a test case template corresponding to the translation result of the function name to be processed is generated according to the preset use case field, the use case name corresponding to the translation result of the function name to be processed, and the business use case field.

2. The method according to claim 1, characterized in that Obtain the test case field values edited based on the test case template, including: When there is no corresponding data generator for the use case field to be edited in the test case template, obtaining the use case field value of the use case field to be edited input by the user; When the use case field to be edited in the test case template has at least one corresponding data generator, the target data generator selected by the user from the at least one data generator is obtained, and the use case field value of the use case field to be edited is automatically generated based on the target data generator.

3. The method according to claim 2, characterized in that Before obtaining the target data generator selected by the user from the at least one data generator, the method further includes: Obtaining a target character combination mode, a target field minimum length, and a target field maximum length input by a user in a generator creation interface, and generating a data generator for the use case field to be edited based on the target character combination mode, the target field minimum length, and the target field maximum length, wherein the target character combination mode, the target field minimum length, and the target field maximum length are the character combination mode, the field minimum length, and the field maximum length for the use case field to be edited, respectively; Alternatively, obtain a data generator script for the use case field to be edited that is imported by the user in the generator creation interface, and generate a data generator for the use case field to be edited based on the data generator script, wherein the data generator script includes a data generation function, and the data generation function is used to define the character combination method, minimum field length, and maximum field length of the use case field to be edited.

4. The method according to claim 1, wherein The method further comprises: Obtaining precondition information entered by the user on the precondition creation interface, wherein the precondition information includes a precondition name, at least one precondition step, a return parameter corresponding to each of the precondition steps, and a return parameter value corresponding to each of the precondition steps, wherein the precondition step is a step required to obtain the return parameter; A precondition is generated based on the precondition information.

5. The method according to claim 4, characterized in that After generating a first configuration file including a mapping relationship between a function name and a function name translation result according to the function name of each base class function in the test base class, the method further includes: Generate a use case directory according to the function names and the order of the function names in the test base class; Alternatively, a use case directory is generated according to the translation results of each function name in the first configuration file and the order of the function name translation results.

6. The method according to claim 5, characterized in that After generating the use case catalog, the method further includes: Insert the precondition name as a first-level directory into the use case directory.

7. The method according to claim 6, characterized in that Convert all test cases into executable test case codes according to the order of base class functions corresponding to the test cases in the test base class, including: storing all test cases into a json file according to the order of contents of the test case directory, and converting the json file into executable test case codes; Before adding the calling code to the test case code to obtain the target test case code, the method also includes: if the use case directory includes a precondition name, generating a calling code for calling the precondition corresponding to the precondition name, and adding the calling code of the precondition to the test case code.

8. The method according to claim 1, characterized in that After generating the test case including the use case field and the use case field value, the method further includes: In the editing interface of the test case template, a target exhaustive module added by the user from at least one exhaustive module is obtained so that when the test case code corresponding to the test case template is executed, an exhaustive test is performed based on the target exhaustive module, wherein the exhaustive module is generated according to the exhaustive range input by the user and a preset exhaustive algorithm.

9. The method according to any one of claims 1 to 8, characterized in that The preset test case execution logic includes test case execution logic and test result judgment logic; The test case execution logic includes: executing the corresponding test case code in the order of the base class functions in the test base class, saving the test case execution result with the status code value as the preset status code value in the preset json data body format, when the test case to be executed needs to call the target test case execution result, if the Nth execution result in the target test case execution result is a correct result, calling the Nth execution result in accordance with the calling format corresponding to the preset json data body format; if the Nth execution result in the target test case execution result is an error result, calling the N+1th execution result in the target test case execution result in accordance with the calling format corresponding to the preset json data body format, wherein the target test case execution result is all execution results of the target test case, and N is a positive integer; The test result judgment logic includes: when a status code is defined in the test base class, determining whether the program tested by the target test case template is normal by determining whether the target status code defined in the test base class is the same as the status code set in the target test case, wherein the target status code corresponds to the target test case; when test content is defined in the test base class and the preset use case field includes a test result, when the target test result in the target test case takes a value of 1, determining whether the program tested by the target test case is normal by determining whether the test case execution result saved in a preset json data body format is the same as the test content defined in the test base class; when the target test result in the target test case takes a value of 0, determining whether the program tested by the target test case is normal by determining whether the target test content in the target test case is the same as the test content defined in the test base class.

Citation Information

Patent Citations

  • Test method and device based on dynamic script template

    CN106649073A

  • Automatic test verification method based on data template engine and test system thereof

    CN112559339A