A test case generation method, system and device

By creating annotations on Java scripts and automatically obtaining reflection information to generate test cases, the problem of manually writing test cases in Java projects is solved, achieving automated generation and improved efficiency.

CN115114170BActive Publication Date: 2026-03-03JINAN INSPUR DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-15
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

After an existing Java project is completed, test cases need to be written manually by developers, resulting in high human resource costs and increased repetitive work.

Method used

By creating annotations for test cases, they are automatically marked on the Java script. After filling in the necessary information, the script is run to obtain reflection information, and test cases are automatically generated, reducing manual writing.

Benefits of technology

It enables automated generation of test cases, reducing human resource costs and improving generation efficiency and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115114170B_ABST
    Figure CN115114170B_ABST
Patent Text Reader

Abstract

The application discloses a test case generation method, system and device, and relates to the field of web applications. When a creation instruction of an annotation of a test case is received, the annotation of the test case is created according to the creation instruction; the created annotation is marked on a java script of a test case to be generated; when filling information required by the marked annotation is completed, the java script is run; reflection information of the java script marked with the annotation and the filling information of the annotation are acquired after the java script is run; and the test case is generated according to the reflection information and the filling information. The application firstly creates the annotation of the test case, marks the annotation on the java script, fills the required filling information, acquires the reflection information of the java script after the java script is run, and automatically generates the test case according to the reflection information and the filling information. The test case corresponding to each java script can be automatically generated, and the loss of human resource cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of web applications, and in particular to a test case generation method, system, and apparatus. Background Technology

[0002] With the development of Java projects, an increasingly rich variety of Java projects have been developed. Currently, after a Java project is completed, developers write test cases and submit them to testers for testing. Because test cases may contain some fixed and repetitive content and processes, developers need to spend a lot of time writing test cases, and test cases need to be written for each Java project. This increases the consumption of human resources costs. Summary of the Invention

[0003] The purpose of this invention is to provide a test case generation method, system, and apparatus. This application first creates annotations for test cases, marks the annotations on the Java script, fills in the required information, and after running the Java script, obtains the reflection information of the Java script. Based on the reflection information and the information, test cases are automatically generated, eliminating the need for manual writing and reducing the loss of human resources costs.

[0004] To address the aforementioned technical problems, this invention provides a test case generation method, comprising:

[0005] When a creation instruction for an annotation of a test case is received, the annotation of the test case is created according to the creation instruction, wherein the creation instruction includes the creation configuration information of the test case;

[0006] The created annotation is applied to the Java script from which the test cases are to be generated;

[0007] When the required information for filling the annotation of the determination mark is completed, the Java script is executed;

[0008] Obtain the reflection information of the Java script marked with the annotation after the Java script is executed, and the filling information of the annotation;

[0009] The test cases are generated based on the reflection information and the filling information.

[0010] Preferably, when the type information is of type mock, generating the test case based on the reflection information and the padding information includes:

[0011] Test cases of the mock type are generated based on the reflection information, the filling information, and the mock test case template.

[0012] Preferably, when the type information is of type Postman, the test cases are generated based on the reflection information and the padding information, including:

[0013] Generate a JSON test file based on the reflection information and the padding information;

[0014] Use the JSON test file as a test case of the Postman type.

[0015] Preferably, after generating the test cases of the mock type based on the reflection information, the padding information, and the mock test case template, the method further includes:

[0016] Run the mock test cases to obtain test result information.

[0017] Preferably, after using the JSON test file as a test case of the Postman type, it further includes:

[0018] Run the JSON test file in the Postman tool to obtain the test results.

[0019] Preferably, after obtaining the test results information, the following is also included:

[0020] An information database will be established based on the test results.

[0021] Preferably, obtaining the reflection information of the Java script marked with the annotation after the Java script is executed includes:

[0022] Obtain reflection information of the Java script marked with the annotation after the Java script belonging to the Controller class or RestController class is executed.

[0023] Preferably, the information to be filled includes test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information;

[0024] The required fill information for the annotation of the determination mark is completed, including:

[0025] Determine whether the name information, description information, method input parameter type information, exception type information, and authentication permission information filled in by the developer have been received;

[0026] If received, the required information for filling the annotation of the determination mark is completed and the process proceeds to the step of running the Java script;

[0027] If not received, determine which of the following information is missing: test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information.

[0028] The steps involve filling in the unreceived information according to the preset filling configuration to complete the filling information and then proceeding to run the Java script.

[0029] To address the aforementioned technical problems, the present invention also provides a test case generation system, comprising:

[0030] The first processing unit is configured to, upon receiving a creation instruction for an annotation of a test case, create the annotation of the test case according to the creation instruction, wherein the creation instruction includes the creation configuration information of the test case;

[0031] A tagging unit is used to mark the created annotation on the Java script to generate the test case;

[0032] The second processing unit is used to determine when the required filling information for the annotation of the mark is completed, and then run the Java script.

[0033] The information acquisition unit is used to acquire the reflection information of the Java script marked with the annotation after the Java script is run and the filling information of the annotation. The reflection information includes interface address information, number of interface input parameters and interface return value. The filling information includes test case type information, name information, description information, method input parameter type information, exception type information and authentication permission information.

[0034] The test case generation unit is used to generate the test cases based on the reflection information and the filling information.

[0035] To address the aforementioned technical problems, the present invention also provides a test case generation device, comprising:

[0036] Memory, used to store computer programs;

[0037] A processor for executing the computer program to implement the steps of the test case generation method described above.

[0038] This application provides a test case generation method, system, and apparatus. Upon receiving a creation instruction for an annotation to create a test case, the method creates the annotation according to the instruction, which includes test case creation configuration information. The created annotation is then marked on the Java script from which the test cases are to be generated. Once the required population information for the marked annotation is completed, the Java script is run. Reflection information and annotation population information of the Java script marked with the annotation are obtained after the Java script runs. Test cases are generated based on the reflection information and population information. This application first creates the test case annotation, marks it on the Java script, populates the required population information, and obtains the reflection information of the Java script after running the Java script. Test cases are automatically generated based on the reflection information and population information. Each Java script's corresponding test case can be automatically generated without manual writing, reducing the loss of human resource costs. Attached Figure Description

[0039] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the prior art and embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0040] Figure 1 A flowchart of a test case generation method provided by the present invention;

[0041] Figure 2 This is a schematic diagram of a test case generation device provided by the present invention. Detailed Implementation

[0042] The core of this invention is to provide a test case generation method, system, and apparatus. This application first creates annotations for test cases, marks the annotations on the Java script, fills in the required information, runs the Java script, obtains the reflection information of the Java script, and automatically generates test cases based on the reflection information and the information filled in, without the need for manual writing, thus reducing the loss of human resources costs.

[0043] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0044] Please refer to Figure 1 , Figure 1 A flowchart of a test case generation method provided by the present invention, the method comprising:

[0045] S11: When a creation instruction for an annotation of a test case is received, the annotation of the test case is created according to the creation instruction. The creation instruction includes the creation configuration information of the test case.

[0046] First, upon receiving a user's command to create a test case annotation, the required test case annotation is created. This annotation is created through the command, which includes the test case creation configuration information. This configuration information includes the test case name, description, method parameter types, possible exception types, and authentication information, thus laying the foundation for subsequent steps in creating the test case annotation.

[0047] Specifically, create a custom annotation `@AutoTestGenerate`, marked with `Retention` (meaning it's valid at runtime), and select `Method` as the `Target`, indicating that this custom annotation can only be applied at the Java method level. Create configuration items `type`, `name`, `description`, `targetClass`, `exceptionType`, and `token`. `type` indicates the type of test case to be generated, with three options: `all` generates JSON files for both mock and Postman tests; `mock` generates only mock tests; and `postman` generates only Postman test JSON files. `name` represents the name of the test case (a string). `description` represents the description of the test case (a string). `targetClass` represents the method parameter type (a `Class`). `exceptionType` represents the possible exception types thrown by the test case (a `Class` array). `token` indicates whether the test case requires token authentication (a string). The following is a code example:

[0048]

[0049]

[0050] The `@Retention` (runtime validity) property in the custom annotation `@AutoTestGenerate` has three types: `SOURCE` (representing resource validity), `CLASS` (representing class validity), and `RUNTIME` (representing runtime validity). `@Target` (target attribute) includes types like `FIELD` and `METHOD`, indicating the target type for which the annotation applies. This annotation is primarily applied to methods, hence the `METHOD` type. `name`, `description`, `targetClass`, `executionType`, and `token` represent attribute items of the custom annotation, filled with corresponding default values ​​based on the `default` attribute of Java custom annotations. For example, `targetClass` represents the input parameter of the method it affects, with a default value of `Object`. `token` is generally empty in test cases where login information verification is not required.

[0051] S12: Mark the created annotation on the Java script to be used to generate test cases;

[0052] The created custom annotations are marked on the Java scripts that need to generate test cases. This process can be automated after the test case annotations are generated, using professional marking tools. The Java scripts refer to the script programs written by developers that need to be tested by test cases. The annotation marking process is automated, improving the reliability and automation of the solution.

[0053] S13: When the required information for the annotation of the determination mark is completed, run the Java script;

[0054] After the test case annotations are created, attributes such as type, name, and description are populated. The targetClass attribute of the custom annotation is populated according to the input parameter type of the method. The exceptionType attribute is populated according to the exceptions that the method may throw. The token attribute is populated according to whether the method requires token authentication. After these data or attributes are populated, the Java script is run. That is, the Java script is automatically controlled to run when the above data or attributes are populated, which improves the automation level of the solution and continues to the subsequent steps, thereby improving the efficiency of the final test case generation.

[0055] S14: Obtain the reflection information and annotation population information of the Java script marked with annotations after the Java script is executed;

[0056] After running the Java script, all class files in the project are scanned. Based on Java's inherent reflection principles, reflection information can be obtained, mainly including the Java script's interface address information, the number of interface input parameters, and the interface return value. However, this information is not obtained for the entire Java script, but rather for the Java script annotated with annotations. This part of the Java script needs to generate test cases, and the annotation population information also needs to be obtained. The actual annotation information obtained includes test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information. Based on this, all the information for generating test cases is obtained, laying the foundation for subsequent steps. This step is also executed automatically, improving the efficiency of the solution. Furthermore, the automated execution of this step improves the reliability of the solution.

[0057] Specifically, the method obtains reflection information and annotation population information of the Java scripts marked with annotations after the Java scripts are executed. First, it scans all class files in the Java project to find all Java scripts marked with @AutoTestGenerate. Then, it obtains all attributes of the Java scripts and the attributes of custom annotations through reflection, and finally combines them into the specific information of the Java script. This completes the acquisition of the necessary information to generate test cases, improving the reliability and feasibility of the solution. The whole process is automated, improving efficiency and eliminating the need for developers to write test cases for the Java scripts, thus reducing the consumption of human resources.

[0058] S15: Generate test cases based on reflection and filling information.

[0059] In the above process, Java reflection information is obtained based on Java's inherent reflection principle. This information mainly includes the interface address information, the number of interface input parameters, and the interface return value. At the same time, annotation population information is obtained, including test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information. After obtaining all the information for generating test cases, Java script test cases can be generated based on the reflection information and the population information. The entire process is automated. By using an automated method to generate Java script test cases, the manual writing by developers in existing technologies is replaced, improving the reliability of the solution and reducing the consumption of human resources.

[0060] In summary, this application provides a test case generation method. Upon receiving a creation instruction for an annotation to create a test case, the method creates the annotation according to the instruction, which includes test case creation configuration information. The created annotation is then marked on the Java script from which the test cases are to be generated. Once the required population information for the marked annotation is completed, the Java script is run. Reflection information and annotation population information of the annotated Java script are obtained after the Java script runs. Test cases are generated based on the reflection information and population information. This application first creates the test case annotation, marks it on the Java script, populates the required population information, and obtains the reflection information of the Java script after running the Java script. Test cases are automatically generated based on the reflection information and population information. Each Java script's corresponding test case can be automatically generated without manual writing, reducing the loss of human resource costs.

[0061] Based on the above embodiments:

[0062] Please refer to Figure 2 , Figure 2 This is a schematic diagram of a test case generation device provided by the present invention.

[0063] As a preferred embodiment, when the type information is of type mock, test cases are generated based on reflection information and padding information, including:

[0064] Generate mock test cases based on reflection information, filling information, and mock test case templates.

[0065] If it is necessary to generate mock test cases, since 'type' represents the type of test case to be generated, the specific type of 'type' is 'mock'. Using the aforementioned reflection information and padding information, combined with the mock test case template, mock test code is generated, written to the specified file, and generated to the specified directory, thus completing the generation of mock test cases. The entire process is automated, improving the automation level of the solution.

[0066] Before generating mock test cases, the program pre-initializes the mock test case template. The content of the mock test case template is dynamically replaced using Thymeleaf, and includes request method type, template parameters, return information, exception information, etc. The method type is defined according to the Web HTTP specification, categorized as GET, POST, PUT, and DELETE methods. Template parameters are parsed using `@AutoTestGenerate` to retrieve method input parameters, and return information is parsed using `@AutoTestGenerate` to retrieve return information.

[0067] Pre-set mock test case templates can be adjusted and modified according to actual conditions, improving the flexibility of the solution and making it easier to generate test cases for each Java script more accurately. The pre-setting process of mock test case templates is relatively simple. If no modifications are needed, the template only needs to be set once, improving the efficiency of the solution. After the template is set, subsequent use of the template is automated, eliminating the need for developers to write test cases from memory and reducing the loss of human resources.

[0068] As a preferred embodiment, when the type information is of type Postman, test cases are generated based on reflection information and padding information, including:

[0069] Generate a JSON test file based on the reflection and padding information;

[0070] Use the JSON test file as a Postman test case.

[0071] Unlike generating mock test cases, Postman test cases do not require template settings. They are generated from reflection information and populated data into a JSON test file. This JSON test file is essentially a program in JSON format, similar to a template. The JSON test file automatically populates the Java script's interface address, number of input parameters, and return value, along with annotation information including test case type, name, description, method parameter types, exception types, and authentication / authorization information, based on the reflection and populated data. This automatically creates the Postman test case, which can then be used as the Postman test case without pre-setting any modules. Therefore, this solution can generate both Postman and mock test cases, although the specific generation methods differ. Users can choose to generate different types of test cases according to their needs, improving the solution's comprehensiveness. The entire process is automated, increasing the solution's automation level.

[0072] In addition, different types of test cases in this application can be generated simultaneously. Since type represents the type of test case to be generated, the specific type of type is all at this time. That is, based on the reflection information and the filling information, combined with the mock test case template and the JSON test file, mock type test cases and Postman type test cases are generated respectively, which improves the comprehensiveness of the solution and improves the feasibility of the solution.

[0073] As a preferred embodiment, after generating mock-type test cases based on reflection information, padding information, and mock test case templates, the method further includes:

[0074] Run mock test cases to obtain test result information.

[0075] After the test cases are obtained, the mock test cases are run to obtain test result information. This test result information includes the interface information and execution time of the corresponding Java script. The interface information can specifically determine whether there are any deficiencies in the Java script and thus find the location of the deficiencies. The execution time information can specifically identify which part takes longer and make modifications accordingly. The whole process is automated, which improves the efficiency of the solution.

[0076] As a preferred embodiment, after using the JSON test file as a Postman type test case, it also includes:

[0077] Run the JSON test file in the Postman tool to get the test results.

[0078] After the test cases are obtained, the test cases of the Postman type are run by running the JSON test file in the Postman tool to obtain test result information. The test result information includes the interface information and time consumption of the corresponding Java script. The interface information can specifically determine whether there are any deficiencies in the Java script and thus find the location of the deficiencies. The time consumption information can specifically identify which part takes longer and make modifications. The whole process is automated, which improves the efficiency of the solution.

[0079] It should be noted that the JSON test file can be considered a program, so it can be run directly in the Postman tool to obtain the test results, which improves the reliability and feasibility of the solution.

[0080] In a preferred embodiment, after obtaining the test result information, the method further includes:

[0081] An information database will be established based on the test results.

[0082] After successfully acquiring the test results, an information database can be built based on these results. This database includes interface names, interface address parameters, and processing times. By mapping each interface name to its corresponding information, the database allows developers to modify data and parameters and serves as an overall reference for experience accumulation. This solution automatically builds the database after successful acquisition of test results. Based on the integrated information in the database, users can more intuitively and clearly see the specific data for each step, improving the user experience. Furthermore, the entire process is automated, increasing the automation level of the solution and reducing human resource consumption.

[0083] As a preferred embodiment, obtaining reflection information of the annotated Java script after the Java script is executed includes:

[0084] Retrieves reflection information of the JavaScript script annotated after the JavaScript script belonging to the Controller or RestController class is executed.

[0085] The scanning dimension is not all files in the Java project, but all Java scripts in classes marked with @Controller or @RestController. After scanning for methods marked with @AutoTestGenerate, the Method object of the method marked with that annotation can be obtained using Java reflection. Calling the getAnnotation method of the Method can obtain all annotation information marked on the current method, thereby obtaining the extended attributes of @AutoTestGenerate. Calling the getParematerTypes method of the Method can obtain the collection of all input parameters of the method. After obtaining complete information, a JSON test file is generated based on this information to obtain Postman-type test cases. Alternatively, mock test cases can be generated based on complete information and mock test case templates. Users can choose according to their actual needs, improving the user experience.

[0086] The scanning dimension is all the Java scripts in classes marked with @Controller or @RestController, without scanning the entire file, which can greatly improve processing efficiency. Some dimensions that do not need to be scanned are not scanned, and the focus is on the files that need to be scanned. The scanning is automated, which also improves processing efficiency and the reliability of the solution.

[0087] As a preferred embodiment, the information to be filled includes test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information;

[0088] The annotation of the judgment mark needs to be filled with the required information, including:

[0089] Determine whether the name information, description information, method input parameter type information, exception type information, and authentication permission information filled in by the developer have been received;

[0090] If received, the annotation of the determination mark is filled with the required information and the process proceeds to the step of running the Java script;

[0091] If not received, determine which of the following information is missing: test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information.

[0092] Fill in the unreceived information according to the preset filling configuration to complete the filling information and proceed to the step of running the Java script.

[0093] The process of filling in the required information for annotations involves two steps. First, the user fills in the information once, including attributes such as type, name, and description. Based on the method's input parameter types, the user fills in the targetClass attribute of the custom annotation; based on the exceptions the method might throw, the user fills in the exceptionType attribute; and based on whether the method requires token authentication, the user fills in the token attribute. However, the user doesn't necessarily fill in all the information at once. Therefore, the system first checks if the name, description, method input parameter types, exception types, and authentication information filled in by the developer has been received. If all of the above information has been filled in, the system proceeds to the step of running the Java script. If there is any missing information, the system identifies the missing information from the test case type, name, description, method input parameter types, exception types, and authentication information. This missing information is then filled in according to the preset configuration to complete the information filling process and proceeds to the step of running the Java script. The entire process is automated, improving the efficiency of the solution.

[0094] The preset filling configuration can be set according to the actual situation, and can automatically fill in the items that the user has not filled in, thereby improving the level of automation and user experience.

[0095] In addition, the processor also determines whether the entered data is correct. If the user enters test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information, the processor determines whether the information is correct. If it is correct, the processor continues to execute the subsequent steps. If it is incorrect, the Java script will not be able to run, so the subsequent steps will not be executed to prevent more errors from being executed. Therefore, after the user enters incorrect information, the processor controls the prompt module to issue an alarm and records the user's information entry error in a log file. After the user receives the prompt information, he / she understands that the input is incorrect and then re-enters the information, which improves the reliability and security of the solution.

[0096] This invention also provides a test case generation system, comprising:

[0097] The first processing unit is used to create the annotation of the test case according to the creation instruction when it receives the creation instruction for the annotation of the test case. The creation instruction includes the creation configuration information of the test case.

[0098] The tag unit is used to mark the created annotations on the Java script to which test cases are to be generated;

[0099] The second processing unit is used to determine the required fill information for the annotation of the mark, and then executes a Java script when the fill is completed.

[0100] The information acquisition unit is used to acquire the reflection information and annotation population information of the Java script marked with annotations after the Java script is executed. The reflection information includes interface address information, number of interface input parameters and interface return value. The population information includes test case type information, name information, description information, method input parameter type information, exception type information and authentication permission information.

[0101] The test case generation unit is used to generate test cases based on reflection information and padding information.

[0102] When the type information is mock, the test case generation unit includes:

[0103] Generate mock test cases based on reflection information, filling information, and mock test case templates.

[0104] When the type information is Postman, the test case generation unit includes:

[0105] Generate a JSON test file based on the reflection and padding information;

[0106] Use the JSON test file as a Postman test case.

[0107] After generating mock test cases based on reflection information, padding information, and mock test case templates, the process also includes:

[0108] Run mock test cases to obtain test result information.

[0109] After using the JSON test file as a Postman test case, it also includes:

[0110] Run the JSON test file in the Postman tool to get the test results.

[0111] After obtaining the test results information, the process also includes:

[0112] An information database will be established based on the test results.

[0113] This includes obtaining reflection information of the annotated Java scripts after the Java script has run, including:

[0114] Retrieves reflection information of the JavaScript script annotated after the JavaScript script belonging to the Controller or RestController class is executed.

[0115] The information to be filled includes test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information;

[0116] The information acquisition unit includes:

[0117] The judgment unit is used to determine whether the name information, description information, method input parameter type information, exception type information and authentication permission information filled in by the developer have been received. If yes, proceed to the first judgment unit; otherwise, proceed to the second judgment unit.

[0118] The first determination unit is used to determine whether the annotation of the mark needs to be filled with the required information and then proceed to the step of running the Java script;

[0119] The second determination unit is used to determine any information not received in the test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information.

[0120] The fill unit is used to fill in the unreceived information according to the preset fill configuration to complete the fill information and proceed to the step of running the Java script.

[0121] For a description of the test case generation system provided by this invention, please refer to the embodiments of the test case generation method described above; further details will not be repeated here.

[0122] The present invention also provides a test case generation device, comprising:

[0123] Memory 1 is used to store computer programs;

[0124] Processor 2 is used to execute computer programs to implement the steps of the test case generation method described above.

[0125] For a description of the test case generation device provided by the present invention, please refer to the embodiments of the test case generation method described above, which will not be repeated here.

[0126] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0127] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0128] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A test case generation method, characterized in that, include: When a creation instruction for an annotation of a test case is received, the annotation of the test case is created according to the creation instruction, wherein the creation instruction includes the creation configuration information of the test case; The created annotation is applied to the Java script from which the test cases are to be generated; When the required information for filling the annotation of the determination mark is completed, the Java script is executed; After the Java script is executed, obtain the reflection information of the Java script marked with the annotation and the filling information of the annotation, wherein the reflection information includes: interface address information, number of interface input parameters and interface return value; The test cases are generated based on the reflection information and the filling information. Obtain reflection information of the Java script marked with the annotation after the Java script is executed, including: Obtain reflection information of the Java script marked with the annotation after the Java script belonging to the Controller class or RestController class is executed; The scanning dimension is all Java scripts marked in the Controller class or RestController class; When the test case type information is mock, the test case is generated based on the reflection information and the padding information, including: Based on the reflection information, the padding information, and the mock test case template, generate test cases of the mock type; When the test case type information is Postman, the test case is generated based on the reflection information and the padding information, including: Generate a JSON test file based on the reflection information and the padding information; Use the JSON test file as a test case of the Postman type.

2. The test case generation method as described in claim 1, characterized in that, After generating the mock type test cases based on the reflection information, the padding information, and the mock test case template, the method further includes: Run the mock test cases to obtain test result information.

3. The test case generation method as described in claim 1, characterized in that, After using the JSON test file as a test case of the Postman type, it also includes: Run the JSON test file in the Postman tool to obtain the test results.

4. The test case generation method as described in claim 2 or 3, characterized in that, After obtaining the test results information, it also includes: An information database will be established based on the test results.

5. The test case generation method according to any one of claims 1 to 3, characterized in that, The information to be filled in includes test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information; The required fill information for the annotation of the determination mark is completed, including: Determine whether the name information, description information, method input parameter type information, exception type information, and authentication permission information filled in by the developer have been received; If received, the required information for filling the annotation of the determination mark is completed and the process proceeds to the step of running the Java script; If not received, determine which of the following information is missing: test case type information, name information, description information, method input parameter type information, exception type information, and authentication permission information. The steps involve filling in the unreceived information according to the preset filling configuration to complete the filling information and then proceeding to run the Java script.

6. A test case generation system, characterized in that, include: The first processing unit is configured to, upon receiving a creation instruction for an annotation of a test case, create the annotation of the test case according to the creation instruction, wherein the creation instruction includes the creation configuration information of the test case; A tagging unit is used to mark the created annotation on the Java script to generate the test case; The second processing unit is used to determine when the required filling information for the annotation of the mark is completed, and then run the Java script. The information acquisition unit is used to acquire the reflection information of the Java script marked with the annotation after the Java script is run and the filling information of the annotation. The reflection information includes interface address information, number of interface input parameters and interface return value. The filling information includes test case type information, name information, description information, method input parameter type information, exception type information and authentication permission information. A test case generation unit is used to generate the test cases based on the reflection information and the filling information; The information acquisition unit is used to acquire reflection information of the Java script marked with the annotation after the Java script belonging to the Controller class or RestController class is executed; The scanning dimension is all Java scripts marked in the Controller class or RestController class; When the test case type information is mock type, the test case generation unit is used to: generate test cases of the mock type based on the reflection information, the padding information and the mock test case template; When the test case type information is Postman type, the test case generation unit is used to: generate a JSON test file based on the reflection information and the filling information; and use the JSON test file as a test case of the Postman type.

7. A test case generation device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the test case generation method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method, device and equipment for generating test case and computer readable storage medium

    CN108334443A

  • Method and system for dynamically invoking and / or checking conditions of a computer test program

    US20030041288A1