Automatic generation method and device for integrated test cases based on artificial intelligenceTechnical Field
The invention relates to an artificial intelligence technology, in particular to an automatic generation method and device for an integrated test case based on artificial intelligence.
Background
In the prior art, for integrated test cases, tests generated by test coverage incompletely and automatically may not completely cover all test scenes, especially for some complicated logic and edge conditions. This may result in certain errors and problems being missed, affecting the quality and stability of the software.
Some test automation generators may generate a large number of test cases, which not only requires more time and resources to run the tests, but also presents challenges for inspection and maintenance of the tests. Especially in large and complex projects, too many test cases may cause the test procedure to become cumbersome and confusing.
Manual inspection and maintenance is required and the automatically generated test typically requires manual inspection and maintenance to ensure the accuracy and validity of the test. However, this may require a significant amount of time and effort, especially in large and complex projects. Learning and use costs: the use of test automation generators typically requires some learning and use costs. For example, a user may need to know the principle of operation and method of use of the generator, or to purchase and maintain related software and hardware resources. Some test automation generators may only support a particular programming language or framework. For example, intellitest only supports the NET framework, which is not available to Java developers.
As in the prior art, the main applications in the CN202210679196.6 prior art are limited to the database field, generating integrated tests for procedural units (i.e. stored procedures). The prior art oriented to the oracle database cannot be well oriented to the java service field; in order to achieve the purpose of integrated test generation, an additional blood relationship table is still required to be configured on the basis of inputting table structure information; matching with a traditional character string based on a local database; the latter is based on a large corpus of models and a generative AI search.
Disclosure of Invention
Aiming at the defect of insufficient test coverage in the prior art, the automatically generated test may not completely cover all test scenes, especially for some complicated logic and edge conditions; the problem of troublesome maintenance is solved, and an automatic integrated test case generation method and device based on artificial intelligence are provided.
In order to solve the technical problems, the invention is solved by the following technical scheme:
the automatic integrated test case generation method based on artificial intelligence comprises a user lane, an integrated test generator lane and an artificial intelligence model lane, and comprises the following steps:
s1, generating class files of integrated test cases, selecting class or folder generating nodes which need to generate integrated test case integrated tests, executing operation on the nodes by a user, and selecting the class or folder of the integrated test cases, thereby generating the class files of the integrated test cases;
s2, analyzing the class file, and analyzing the class file in an integrated test generator lane;
s3, generating a class file test template, and loading the parsed class file in an integrated test generator lane so as to generate a class file test template;
s4, detecting the class file, and detecting a class file test template in an integrated test generator lane;
s5, generating and storing integrated test class files which are integrated into test class files and main flow, and generating and storing the detected class files in an integrated test generator lane to form integrated test class files of the test class files and the main flow;
s6, loading integrated test class file data generating templates, loading integrated test data in lanes of an integrated test generator, and generating test templates for generating integrated test codes;
s7, analyzing the integrated test file data generating template in an integrated test generator lane;
s8, extracting a data model, namely extracting the data model from the analyzed integrated test file data generation template in the artificial intelligent model lane;
s9, generating and storing integrated test data and a test general tool class, and generating and storing the integrated test data and the test general tool class in an integrated test generator lane;
s10, storing operation result data, and storing the result data of the integrated test operation in an integrated test generator lane;
s11, generating and storing codes of an integrated test result verification module, and generating and storing codes of the integrated test result verification module in lanes of an integrated test generator;
s12, generating test cases, namely generating the test cases in the artificial intelligent model lanes based on logic branches and domain data knowledge detected by artificial intelligence.
Preferably, for generating and storing integrated test class files into test class files and main flow, artificial intelligence logical branch detection is also included, detecting logical branches in code in artificial intelligence model lanes to determine possible test scenarios.
Preferably, the extracted file for the data model further includes domain data knowledge base retrieval and matching, and the relevant data is retrieved and matched from the domain data knowledge base in the artificial intelligence model swim for test generation and analysis.
Preferably, for generating and storing the integrated test data and the test generic tool class further comprises processing of the integrated test data, starting an integrated test running container, and starting the container for running the integrated test in an integrated test generator lane; judging the integrated test result, storing operation result data when the integrated test operation result passes, and storing the integrated test operation result data in an integrated test generator lane; otherwise, executing the analysis of the abnormal operation of the integrated test.
Preferably, the integrated test class file data generation template parsing includes dependency call instrumentation data parsing and request parameter data parsing.
Preferably, the detection of class files includes dependency detection, reference variable detection and method signature detection; the dependency detection is used for detecting the dependency relationship in the class file; referencing variable detection to detect variable references in class files; method signature detection is used to detect method signatures in class files.
In order to solve the technical problem, the invention also provides an artificial intelligence-based integrated test case automatic generation device, which comprises a device realized by the artificial intelligence-based integrated test case automatic generation method.
The invention has the remarkable technical effects due to the adoption of the technical scheme:
the invention occupies low system resources, reduces the time for generating the integrated test by 50% compared with the bottleneck of the prior art, reduces the running time of the integrated test by more than 80%, and is originally required to wait for the integrated test which runs out for 30 seconds to finish the integrated test only by 5 seconds.
The invention uses the pile-inserting technology to simulate the response result of spring context in off-line environment, and makes the development focus on the code logic and business scene of subdivision level.
The handwriting code quantity is less, the coverage rate of the method for automatically generating the integrated test class is up to 100%, and the line coverage rate can be up to more than 95% based on the detection of the artificial intelligence logic branches. The development efficiency of developers is effectively improved.
The invention templates the integrated test code structure, is convenient for developing and understanding. Based on the acceleration of the running speed, the handwriting code quantity is reduced, and the liberation of development productivity is brought.
Drawings
FIG. 1 is a lane diagram of the present invention.
FIG. 2 is a lane diagram of example 2 of the present invention.
FIG. 3 is a batch file integration test generation diagram of the present invention.
Fig. 4 is a diagram of the operation and adjustment integration test of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples.
Example 1
The automatic integrated test case generation method based on artificial intelligence comprises a user lane, an integrated test generator lane and an artificial intelligence model lane, and comprises the following steps:
s1, generating class files of integrated test cases, selecting class or folder generating nodes which need to generate integrated test case integrated tests, executing operation on the nodes by a user, and selecting the class or folder of the integrated test cases, thereby generating the class files of the integrated test cases;
s2, analyzing the class file, and analyzing the class file in an integrated test generator lane;
s3, generating a class file test template, and loading the parsed class file in an integrated test generator lane so as to generate a class file test template;
s4, detecting the class file, and detecting a class file test template in an integrated test generator lane;
s5, generating and storing integrated test class files which are integrated into test class files and main flow, and generating and storing the detected class files in an integrated test generator lane to form integrated test class files of the test class files and the main flow;
s6, loading integrated test class file data generating templates, loading integrated test data in lanes of an integrated test generator, and generating test templates for generating integrated test codes;
s7, analyzing the integrated test file data generating template in an integrated test generator lane;
s8, extracting a data model, namely extracting the data model from the analyzed integrated test file data generation template in the artificial intelligent model lane;
s9, generating and storing integrated test data and a test general tool class, and generating and storing the integrated test data and the test general tool class in an integrated test generator lane;
s10, storing operation result data, and storing the result data of the integrated test operation in an integrated test generator lane;
s11, generating and storing codes of an integrated test result verification module, and generating and storing codes of the integrated test result verification module in lanes of an integrated test generator;
s12, generating test cases, namely generating the test cases in the artificial intelligent model lanes based on logic branches and domain data knowledge detected by artificial intelligence.
And generating template analysis by integrating test class file data, wherein the template analysis comprises dependency calling instrumentation data analysis and request parameter data analysis.
The detection of the class file comprises dependency detection, reference variable detection and method signature detection; the dependency detection is used for detecting the dependency relationship in the class file; referencing variable detection to detect variable references in class files; method signature detection is used to detect method signatures in class files.
Example 2
Based on example 1, the user swim lane start node in fig. 2: indicating the start point of the flow.
Selecting a class or folder click generating node which needs to generate an integration test: and the user performs operation on the node, selects the class or folder needing to generate the integrated test, and clicks a generation button. Confirming and generating a result node: the user confirms at the node that the results of the integrated test are generated. End node (end lane): indicating the end point of the flow.
For integrated test generator lanes parse class files: and analyzing the class file required to generate the integrated test according to the type of the class file. Loading a class file generation template: loading a class file and generating a test template for generating an integrated test code, wherein the integrated test class method template flow mainly comprises the following steps: reading and analyzing data, declaring pile inserting variables, running by a test method, and checking test results and expected results. Dependency detection: and detecting the dependency relationship in the class file, and ensuring that the integrated test can independently run in an offline environment. Reference variable detection: detecting variable references in the class file, judging whether the referenced variables need networking and a context environment during operation, if so, marking the referenced variables as needing pile-inserting processing, and ensuring that the integrated test can independently operate in an offline environment; the method comprises the steps of signature detection: detecting a method signature in the class file, and combining a class file path as a unique identifier of the integrated test method; generating and storing test class files and a main flow integration test method: generating and storing an integrated test method which is integrated into a test class file and a main flow; the integrated test method for generating and storing the logic branches of the abnormal scene and the like comprises the following steps: generating and storing an integrated test method of logic branches such as an abnormal scene and the like; loading integrated test data to generate a template: loading an integrated test data generation template, limiting the type and range of data and the like, and generating integrated test data; relying on invoking instrumentation data parsing: analyzing the dependency calling instrumentation data based on the mark of the reference variable detection step; request parameter data parsing: analyzing request parameter data based on the mark of the method signature detection step; generating and storing integrated test data: generating and storing integrated test data, wherein the storage format is JSON; generating and storing a test generic tool class: and generating and storing test universal tool classes, including a unified check returned result packaging class, a test check tool class and the like. Starting an integrated test running container: starting a container for running the integrated test, pre-running the generated integrated test, and performing self-circulation fine tuning on input data of the integrated test according to an operation result; storing operation result data: storing result data of the integrated test operation; generating and storing integrated test result verification module codes: code stored as a test result verification module is generated and stored.
Lanes for artificial intelligence models; artificial intelligence logical branch detection: detecting logical branches in the code to determine a possible test scenario; domain data knowledge base retrieval and matching: retrieving and matching related data from a domain data knowledge base for test data generation; and (3) generating test cases: based on the logic branches and domain data knowledge detected by artificial intelligence, generating an integration test of a corresponding abnormal scene.
Based on AIGC, mockito and Junit5, test codes and corresponding test data are automatically generated. Single java file integration test generation: right clicking on the integrated test generator-generate integrated test class and data-in the java file, the integrated test generator automatically generates the corresponding test code. FIG. 3 is a batch java file integration test generation: click on the directory where the java file in the left project is located, click on the toolbar "Tools-batch integration test class and data generation" above IDEA. Fig. 4 shows the expected result of the integration test in the json integrated test data, and the other methods of mock return the result. Modifications may be made according to the actual circumstances.
Example 3
Based on the above embodiment, the present embodiment provides an artificial intelligence based integrated test case automatic generation device, which includes a device implemented by the artificial intelligence based integrated test case automatic generation method.