CN-121996550-A - Method and system for generating test codes of automobile software unit
Abstract
The invention discloses a method and a system for generating test codes of an automobile software unit, comprising the following steps of step 1, converting function standardization into Mermaid flow charts, step 2, delivering the generated flow charts to AI model production Gtest use cases, and step 3, carrying out software function test by using the generated Gtest use cases. The invention solves the problems of manual dependence, low efficiency and easy error in the traditional development module from the requirement to the test, and ensures the strict consistency and high quality of the specification, the flow chart and the test code by introducing Mermaid as an intermediate logic model and combining the manual intervention and an intelligent model. The automation level, quality and efficiency of the development of the automobile software are remarkably improved.
Inventors
- CHEN ZEJIAN
- CHEN YONG
- ZHANG DA
- GUO YAJIE
Assignees
- 芜湖埃泰克汽车电子股份有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260117
Claims (9)
- 1. The method for generating the test code of the automobile software unit is characterized by comprising the following steps: Step 1, converting function standardization into Mermaid flow charts; step 2, the generated flow chart is submitted to AI model production Gtest use cases; and 3, performing software function test by using the generated Gtest use cases.
- 2. The method of claim 1, wherein in step 1, the function specification is parsed to extract logic elements, the logic elements are converted into Mermaid format flow chart code, and the parsing is based on a rule-based natural language processing technology.
- 3. The method of claim 2, wherein in step 1, the Mermaid flow chart code accurately describes control flows of functions including, but not limited to, all possible state nodes, transition directions between states, conditional decisions that trigger transitions, and actions performed upon entry or exit of states.
- 4. The method for generating test codes for automobile software unit according to claim 3, wherein said step 1 is performed by performing a manual check by visually displaying and manually modifying Mermaid the flow chart codes through the user interface.
- 5. The method for generating test code for an automotive software unit according to any one of claims 1 to 4, wherein Gtest use cases in step 2 are automatically generated source codes conforming to a unit test framework, and the generation is performed by a template-based code generator.
- 6. The method of claim 5, wherein in step 2, the instruction provided to the large language model explicitly requires traversing each branch path in the flowchart, and generating an independent test case for each path, so that the GTest code can implement conditional coverage and path coverage.
- 7. The method for generating test codes of automobile software unit according to claim 6, wherein said step 2 is performed by manual inspection and adjustment.
- 8. The method for generating test codes of an automobile software unit according to claim 1 or 7, wherein in step 3, after the functional test result is displayed, the test result data is displayed, and the result data is compared with a preset qualified threshold interval, and the test conclusion is judged and displayed.
- 9. A system for performing the method of generating test code for a software unit of an automobile according to any one of claims 1-8, the system comprising: A flow chart modeling module for receiving or assisting in generating Mermaid code describing the functional logic; The visual verification module is used for rendering Mermaid codes into graphs for verification by a user; the AI code generation interface module is used for sending the Mermaid codes after the auditing to the large language model and receiving the returned GTest codes; And the code output module is used for displaying and exporting the unit test code finally generated.
Description
Method and system for generating test codes of automobile software unit Technical Field The invention relates to the field of software automatic testing, in particular to the technical field of automobile software testing. Background In the development of software for an electronic control unit (such as a body domain controller) of an automobile, the writing of test codes is seriously dependent on the manual completion of a test engineer. Engineers need to read and understand the natural language function specifications (such as the seat heating function specification) of the formats of PDF and the like, manually design test cases, and write unit test codes such as GTest frameworks. For example, the authority bulletin number is CN119807022B, the application publication date is 2025-12-19, and the patent name is published in the publication document of method, system, device, equipment and medium for testing software products, the disclosed method is applied to GTest engine, and comprises the steps of executing initialization operation of GTest and loading operation of each test case in response to receiving a starting instruction sent by a software product to be tested, wherein the software product to be tested is developed by using a illusion engine, each test case related to C++ interface test of the software product to be tested comprises each test case related to the UI test of the software product to be tested, executing each test case loaded by the GTest engine through test service to obtain execution results of each test case, and returning the execution results of each test case to the software product to be tested. Similar software testing methods have the following problems and bottlenecks: the consistency is difficult to ensure, and the test code is inconsistent with the standard intention due to manual understanding deviation, so that test false alarm or missing report is generated. Branch coverage is incomplete, and in complex state transition logic, certain boundary conditions or abnormal branches are extremely easy to miss manually. The whole process from the specification to the code is time-consuming and labor-consuming, and when the specification is changed, synchronous updating of the test code is also dependent on manual work and is easy to make mistakes. In recent years, there have been attempts to generate codes directly from natural language using AI, but due to ambiguity and context dependency of natural language, the generated codes have low accuracy, and whether the generated logic is correct or not, it is difficult for engineers to verify directly and quickly. Disclosure of Invention The invention aims to solve the technical problem of realizing an automatic generation method and system for unit test codes, which can ensure that the test codes are strictly consistent with the function specifications, realize high branch coverage rate and are convenient for engineers to review and maintain. In order to achieve the purpose, the technical scheme adopted by the invention is that the method for generating the test code of the automobile software unit comprises the following steps: Step 1, converting function standardization into Mermaid flow charts; step 2, the generated flow chart is submitted to AI model production Gtest use cases; and 3, performing software function test by using the generated Gtest use cases. In the step1, the functional specification is parsed to extract the logic elements, the logic elements are converted into the flow chart codes in Mermaid format, and the parsing is based on the natural language processing technology of rules. In step 1, the Mermaid flow chart code accurately describes the control flow of functions, including, but not limited to, all possible state nodes, the direction of transitions between states, conditional decisions that trigger transitions, and actions performed upon entry or exit of states. And (3) after the step (1) is finished, performing manual inspection, wherein the manual inspection is performed by visually displaying and manually correcting Mermaid flow chart codes through a user interface. In the step 2, gtest use cases are automatically generated source codes conforming to the unit test framework, and the generation is realized by a code generator based on a template. In step 2, the instruction provided to the large language model explicitly requires each branch path in the traversal flow chart, and generates an independent test case for each path, so that the generated GTest codes can realize condition coverage and path coverage. And (3) after the step (2) is finished, performing manual inspection and adjustment. And step 3, after the functional test result is displayed, displaying test result data, comparing the result data with a preset qualified threshold interval, and judging and displaying a test conclusion. A system for executing the method for generating test codes of automobile software units, the system comprising: A f