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

By training the user behavior prediction model to generate test cases, the problem of insufficient coverage of manually written test cases is solved, and more efficient and accurate test case generation is achieved, which adapts to software changes and improves test coverage and efficiency.

CN120653551APending Publication Date: 2025-09-16CHONGQING WUTONG CAR LINK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510672555.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-23
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

Manually written test cases are difficult to fully cover various scenarios and requirements. The coverage of test cases is affected by experience and level. Traditional traversal scenarios are too random and the test coverage is insufficient.

Method used

By acquiring UI element data and user behavior data, the user behavior prediction model is trained to generate a user behavior prediction analysis graph. The graph is used to make autonomous decisions on operation intersections, generate a first-class test case set, and generate a test script in combination with the code framework template.

Benefits of technology

It improves the coverage and accuracy of test cases, reduces the workload of manual script writing, adapts to the continuous changes of software, and improves testing efficiency and quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653551A_ABST
    Figure CN120653551A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, in particular to a test case generation method and device, computer equipment and a storage medium, and the test case generation method comprises the following steps: respectively obtaining first UI element data corresponding to each first page; obtaining a trained user behavior prediction model; obtaining a user behavior prediction analysis chart according to the first UI element data corresponding to each first page and a user behavior prediction model; and analyzing the user behavior prediction analysis chart to obtain a first type of test case set. According to the method, the user scene of the current application can be understood through the user behavior prediction model, and subsequent operation intersections are autonomously decided, so that the problems that various scenes and requirements are difficult to comprehensively cover by manually compiling test cases and the coverage degree of the test cases is influenced by experience and level are solved.
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 method and device for generating a test case, a computer device, and a storage medium. Background Art

[0002] As the smart cockpit landscape continues to grow in complexity and diversity, the applications within vehicle systems are also becoming increasingly complex and diverse. Customers and businesses are also placing increasingly high demands on the quality of smart cockpits, making testing a critical step in ensuring software quality and reliability. However, manually writing test cases is a time-consuming and error-prone process, especially as applications become increasingly complex. Furthermore, manually written test cases struggle to fully cover various scenarios and requirements. Complex systems and applications also involve vast amounts of data and algorithms, making manual test case generation difficult to accurately simulate certain user behaviors. Test case coverage is also limited by experience and skill level. Summary of the Invention

[0003] In view of this, the present invention provides a test case generation method, apparatus, computer equipment and storage medium to solve the problem that manually written test cases are difficult to comprehensively cover various scenarios and requirements, and the coverage of test cases is affected by experience and level.

[0004] In a first aspect, the present invention provides a method for generating test cases, comprising the following steps: respectively obtaining first UI element data corresponding to each first page; obtaining a trained user behavior prediction model; obtaining a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model; and analyzing the user behavior prediction analysis graph to obtain a first type of test case set.

[0005] The test case generation method provided by the present invention obtains a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model, so that the user behavior prediction analysis graph can be analyzed to obtain a first type of test case set. Through the user behavior prediction model, it can understand the user scenario of the current application and independently decide on subsequent operation intersections, thereby solving the problem that manually written test cases are difficult to comprehensively cover various scenarios and requirements, and the coverage of test cases is affected by experience and level; and compared with traditional monkey tests or automatic traversal tests that only traverse according to the page structure tree, the present invention puts more perspectives on user behavior operations and vehicle systems, thereby improving the coverage of use cases.

[0006] In an optional embodiment, the training method of the user behavior prediction model includes: respectively obtaining the second UI element data and control structure tree corresponding to each second page, and the user's behavior data on each second page; organizing the user's behavior data on the second page according to the control structure tree and the second UI element data to obtain multiple operation records, wherein each operation record includes the user behavior, the interface to which the user behavior belongs, the adjacent interface of the interface to which the user behavior belongs, the user behavior's stay time on the interface to which it belongs, and the UI element data of the interface to which the user behavior belongs; using multiple operation records to train the preset first model to obtain a user behavior prediction model.

[0007] As can be seen, the user behavior prediction model of this embodiment is obtained by training the preset first model using the second UI element data and control structure tree corresponding to each second page, as well as the user behavior data on each second page. It can be understood that this embodiment can timely adjust and optimize use cases based on test execution results simply by updating the user behavior prediction model, without requiring extensive modification of test cases, thereby adapting to continuous changes in the software.

[0008] In an optional embodiment, obtaining a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model includes: inputting the first UI element data corresponding to each first page into the user behavior prediction model to obtain the user's key behaviors and the confidence levels of the key behaviors on each first page; and obtaining a user behavior prediction analysis graph based on the user's key behaviors and the confidence levels of the key behaviors on each first page.

[0009] By obtaining a user behavior prediction analysis diagram based on the first UI element data corresponding to each first page and the user behavior prediction model, the user scenario of the current application can be understood through the user behavior prediction model, and subsequent operation intersections can be decided independently, solving the problem that traditional traversal scenarios are too random and the test coverage is insufficient.

[0010] In an optional embodiment, analyzing the user behavior prediction analysis graph to obtain a first type of test case set includes: extracting multiple nodes to be analyzed and the user's key behavior at each node to be analyzed, and the confidence of the key behavior in the user behavior prediction analysis graph; determining the priority of all nodes to be analyzed based on the confidence of the key behavior in all nodes to be analyzed; determining the current node based on the priority of all nodes to be analyzed, and storing the current node in the visited node set; obtaining all adjacent nodes of the current node and the priority of each adjacent node; selecting the currently visited adjacent node from all adjacent nodes based on the priority of all adjacent nodes, and using the currently visited adjacent node as the current node, returning to the step of storing the current node in the visited node set, until there are no unvisited adjacent nodes, forming a current path, and obtaining the first type of test case corresponding to the current path; after obtaining the first type of test case, returning to the step of determining the current node based on the priority of all nodes to be analyzed, until all nodes to be analyzed have been visited, obtaining multiple paths, and the first type of test case corresponding to each path.

[0011] This embodiment improves the coverage and accuracy of the generated first-category test cases by using an algorithm that covers all paths in the user behavior prediction analysis graph.

[0012] In an optional embodiment, after analyzing the user behavior prediction analysis graph to obtain the first type of test case, the test case generation method also includes: using the first type of test case to generate the first type of test case configuration file data; obtaining the preset first code framework template and the first shared function; filling the first type of test case configuration file data into the first code framework template, and obtaining the first test script according to the first shared function.

[0013] This embodiment provides a method for generating a first test script according to the first type of test case configuration file data, which solves the problem that manually writing test scripts is labor-intensive, inefficient, and prone to errors.

[0014] In an optional embodiment, generating first-class test case configuration file data using first-class test cases includes: selecting first-class test cases covering all paths from a first-class test case set to obtain a first use case subset, and generating first-class test case configuration file data using the first use case subset; or; obtaining test requirements, wherein the test requirements include multiple test paths and a use case ratio value for each test path; selecting test cases from the first-class test case set according to the test requirements to obtain a second use case subset; generating first-class test case configuration file data using the second use case subset; or; selecting first-class test cases covering all paths from the first-class test case set to obtain a first use case subset; obtaining test requirements; selecting test cases from the first-class test case set according to the test requirements to obtain a second use case subset; generating first-class test case configuration file data using the first use case subset and the second use case subset.

[0015] In this embodiment, a method of covering all paths is used to select a subset of first use cases from the first category of test case sets, thereby improving the coverage and accuracy of the first category of test case configuration file data; selecting a subset of second use cases from the first category of test case sets according to test requirements can help explore different parts of the user behavior prediction model and increase the possibility of discovering potential problems.

[0016] In an optional implementation, after obtaining the first test script according to the first shared function, the method further includes: performing testing using the first test script and obtaining test coverage; and adjusting the test requirements when the test coverage is less than a preset threshold.

[0017] This allows for timely adjustment and optimization of use cases based on test execution results, making it suitable for scenarios where software is constantly changing.

[0018] In an optional embodiment, the test case generation method also includes the following steps: obtaining a first function test case library and a control structure tree of all pages on the vehicle computer, wherein the first function test case library includes multiple first function test cases; inputting the first function test case library and the control structure tree of all pages on the vehicle computer into the use case feature data extraction model to obtain second-category test case configuration file data; wherein the second-category test case configuration file data includes multiple second-category test cases, each second-category test case includes a second precondition, a second test step, and an expected result corresponding to each second test step; obtaining a preset second code framework template and a second shared function; filling the second-category test case configuration file data into the second code framework template, and obtaining a second test script according to the second shared function.

[0019] This embodiment also provides a method for converting full-scale functional test cases into automated test cases, further improving the coverage of test cases.

[0020] In an optional embodiment, the use case feature data extraction model is obtained by the following method: obtaining a second function test case library and a control structure tree of all pages on the vehicle computer, wherein the second function test case library includes multiple second function test cases; parsing each second function test case in the second function test case library to obtain the preconditions, test steps, and expected results corresponding to each test step of each second function test case; using the parsed control structure tree of each second function test case and all pages on the vehicle computer to train the preset second model to obtain the use case feature data extraction model.

[0021] The training method of the use case feature data extraction model provided in this embodiment includes parsing each second function test case in the second function test case library to obtain the preconditions, test steps, and expected results corresponding to each test step of each second function test case; thereby, the trained use case feature data extraction model can be automatically changed according to the test execution results and functional use cases, and the use case feature data extraction model can be adjusted and optimized in time to improve the fault tolerance of automated testing and improve the execution rate.

[0022] In the second aspect, the present invention also provides a test case generation device, including a first acquisition module, a second acquisition module, a user behavior prediction analysis graph determination module and a first test case generation module; wherein the first acquisition module is used to respectively obtain the first UI element data corresponding to each first page; the second acquisition module is used to obtain a trained user behavior prediction model; the user behavior prediction analysis graph determination module is used to obtain a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model; the first test case generation module is used to analyze the user behavior prediction analysis graph to obtain multiple first-category test cases.

[0023] In a third aspect, the present invention also provides a computer device comprising a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the test case generation method of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0024] In a fourth aspect, the present invention further provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the test case generation method of the above-mentioned first aspect or any corresponding embodiment thereof.

[0025] In a fifth aspect, the present invention further provides a computer program product, comprising computer instructions for causing a computer to execute the test case generation method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0027] Figure 1 is a flowchart of a test case generation method according to an embodiment of the present invention;

[0028] Figure 2 is a flowchart of another test case generation method according to an embodiment of the present invention;

[0029] Figure 3 is a schematic diagram of a method for generating a user behavior prediction model according to an embodiment of the present invention;

[0030] Figure 4 According to the embodiment of the present invention, user behavior prediction analysis Figure 1 Schematic diagram of the example;

[0031] Figure 5 is a flowchart of converting a user behavior prediction analysis graph into a first test script according to an embodiment of the present invention;

[0032] Figure 6 is a flowchart of converting a first type of test case into a first test script according to an embodiment of the present invention;

[0033] Figure 7 is a flowchart of an example of generating a test case based on user behavior according to an embodiment of the present invention;

[0034] Figure 8 is a flowchart of a test case generation method according to an embodiment of the present invention;

[0035] Figure 9 This is a flowchart of an example of converting a full set of functional use cases into automated test cases according to an embodiment of the present invention;

[0036] Figure 10 is a flow chart of an exception handling mechanism according to an embodiment of the present invention;

[0037] Figure 11 1. It is a schematic diagram of the abnormality handling mechanism and result calibration and push process according to an embodiment of the present invention;

[0038] Figure 12 It is a flow chart of UI automation use case generation according to an embodiment of the present invention;

[0039] Figure 13 is a structural block diagram of a test case generating device according to an embodiment of the present invention;

[0040] Figure 14 Schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0041] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.

[0042] According to an embodiment of the present invention, an embodiment of a method for generating a test case is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0043] This embodiment provides a method for generating a test case, which can be used in a computer device. Figure 1 Flowchart of a test case generation method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0044] Step S101: respectively obtain first UI element data corresponding to each first page.

[0045] Specifically, the first UI element data corresponding to each first page does not require any input. After the device is connected via ADB, the first page is automatically scanned to obtain the first UI element data corresponding to each first page. The first UI element data includes but is not limited to the visual data of the page, such as color information, font information, image resources, layout size, spacing, text display content, etc.

[0046] Step S102: Obtain a trained user behavior prediction model.

[0047] In this embodiment, the user behavior prediction model can understand the user scenario of the current application and make autonomous decisions on subsequent operation paths, thus solving the problem that traditional traversal scenarios are too random and have insufficient test coverage.

[0048] Step S103: obtaining a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model.

[0049] Step S104: Analyze the user behavior prediction analysis graph to obtain a first type of test case set.

[0050] The first type test case set includes a plurality of first type test cases, each of which includes a first precondition, a first test step, and an expected result corresponding to each first test step.

[0051] The test case generation method provided in this embodiment obtains a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model, so that the user behavior prediction analysis graph can be analyzed to obtain a first type of test case. Through the user behavior prediction model, it can understand the user scenario of the current application and independently decide on subsequent operation intersections, thereby solving the problem that manually written test cases are difficult to comprehensively cover various scenarios and requirements, and the coverage of test cases is affected by experience and level; and compared with traditional monkey tests or automatic traversal tests that only traverse according to the page structure tree, the present invention puts more perspectives on user behavior operations and vehicle systems, thereby improving the coverage of use cases.

[0052] This embodiment provides a method for generating a test case, which can be used in a computer device. Figure 2 is a flowchart of another test case generation method according to an embodiment of the present invention, Figure 7 FIG. 1 is a flow chart of an example of generating a test case based on user behavior according to an embodiment of the present invention. Figure 2 and Figure 7 As shown, the process includes the following steps:

[0053] Step S201: respectively obtaining the second UI element data and the control structure tree corresponding to each second page, and the user's behavior data on each second page.

[0054] Specifically, user behavior data in real-world operating environments can be collected through embedded vehicle system logs or third-party professional user behavior tracking tools such as Google Analytics and Mixpanel. This behavior data includes various user interactions such as click events on the second page, input operations, sliding gestures, and voice commands.

[0055] Step S202: Organize the user's behavior data on the second page according to the control structure tree and the second UI element data to obtain multiple operation records, where each operation record includes the user behavior, the interface to which the user behavior belongs, the adjacent interface of the interface to which the user behavior belongs, the user behavior's stay time on the interface to which it belongs, and the UI element data of the interface to which the user behavior belongs.

[0056] Specifically, before organizing the user behavior data on the second page based on the control structure tree and the second UI element data, the process also includes preprocessing the second UI element data and the user behavior data on the second page, such as cleaning missing values, to ensure the accuracy and reliability of subsequent analysis and model building. After obtaining multiple operation records, this information can be uploaded to the cloud and stored in a database, with each second page corresponding to an operation record.

[0057] Step S203: Utilize multiple operation records to train a preset first model to obtain a user behavior prediction model.

[0058] Figure 3 FIG. 1 is a schematic diagram of a method for generating a user behavior prediction model according to an embodiment of the present invention. Figure 3 As shown, after the preset first model is trained using the second UI element data and control structure tree corresponding to each second page, and the user's behavior data on each second page to obtain a trained user behavior prediction model, the specified data can be input into the trained user behavior prediction model, and the trained user behavior prediction model can be evaluated by the generated confidence probability value to determine whether there is an anomaly. When an anomaly exists, the user behavior prediction model needs to be adjusted and optimized, such as adjusting model parameters, supplementing more training data, replacing the model architecture, etc.; when there is no anomaly, the user behavior prediction model is obtained.

[0059] It is understandable that this embodiment can timely adjust and optimize use cases based on the test execution results by simply updating the user behavior prediction model without the need to modify the test cases extensively, thereby adapting to continuous changes in the software.

[0060] Step S204: respectively obtain first UI element data corresponding to each first page.

[0061] Specifically, after adb is connected to the vehicle computer, the automated testing tool UIAutomator may be used to traverse the UI elements to obtain the first UI element data corresponding to each first page.

[0062] Step S205: inputting the first UI element data corresponding to each first page into the user behavior prediction model to obtain the key behavior of the user on each first page and the confidence level of the key behavior.

[0063] Specifically, after inputting the first UI element data corresponding to each first page into the user behavior prediction model, the user behavior prediction model can predict the user's key behaviors on each first page, such as the car machine functions (playback, radio, video, etc.) that the user may use at a fixed time point on the map interface, and the confidence level of the user's key behaviors on each first page.

[0064] Step S206: obtaining a user behavior prediction analysis graph based on the user's key behavior on each first page and the confidence level of the key behavior.

[0065] Figure 4 According to the embodiment of the present invention, user behavior prediction analysis Figure 1 Schematic diagram of the example, Figure 4 The map interface, application center homepage, iQiyi homepage, Kugou homepage, vehicle center homepage, play page, personal center, play page details, singer page, security, etc. are all first pages, where the first page can also be called a node; Figure 4 Viewing videos, clicking, clicking to play, viewing singers, clicking the emergency warning switch, clicking lane keeping, adding followers, searching for movies, logging in, and logging out are all key behaviors.

[0066] Specifically, such as Figure 7 As shown, after obtaining the confidence of the key behavior of each first page, it can be determined whether the confidence of the key behavior is greater than a preset threshold, and the user behavior prediction analysis diagram is drawn only based on the confidence of the key behavior greater than the threshold.

[0067] Step S207: Analyze the user behavior prediction analysis graph to obtain a first type of test case set.

[0068] In an optional implementation, analyzing the user behavior prediction analysis graph to obtain the first type of test case configuration file data includes the following steps A1 to A7.

[0069] Step A1: extract multiple nodes to be analyzed, the key behavior of the user at each node to be analyzed, and the confidence level of the key behavior from the user behavior prediction analysis graph.

[0070] Step A2: Determine the priorities of all nodes to be analyzed according to the confidence levels of the key behaviors in all nodes to be analyzed.

[0071] Step A3: Determine the current node according to the priorities of all nodes to be analyzed, and store the current node in the visited node set.

[0072] Step A4: Obtain all adjacent nodes of the current node and the priority of each adjacent node.

[0073] Step A5: Select the currently visited adjacent node from all adjacent nodes according to the priority of all adjacent nodes, and use the currently visited adjacent node as the current node. Return to the step of storing the current node in the visited node set until there are no unvisited adjacent nodes, forming the current path, and obtaining the first type of test case corresponding to the current path.

[0074] Step A6: After obtaining the first type of test cases, return to the step of determining the current node according to the priority of all nodes to be analyzed, until all nodes to be analyzed have been visited, and obtain multiple paths and the first type of test cases corresponding to each path.

[0075] That is, each node and behavior in the prediction graph is extracted, and each node is assigned a priority value based on the confidence of the user behavior. Then, the nodes are sorted from high to low according to the priority value; then three sets are established (the set of visited nodes, the path list, and the operation record list). Then, starting with the node with the highest priority, it is placed in the set of visited nodes, and its adjacent nodes are visited in order of priority. The adjacent nodes are then used as new nodes to continue the search. When the current node has no unvisited adjacent nodes, the search stops, returns to the previous node, and continues to visit other unvisited nodes; if a path has been completed (i.e., returns to the starting point or there are no other accessible nodes), this path is added to the path list. The above process is repeated until all nodes and edges have been visited. Each operation performed during this period must be stored in the operation record list.

[0076] Step S208: Generate first-category test case configuration file data using the first-category test case.

[0077] In an optional embodiment, generating first-class test case configuration file data using first-class test cases includes the following steps: selecting first-class test cases covering all paths from a first-class test case set to obtain a subset of first use cases, and generating first-class test case configuration file data using the subset of first use cases.

[0078] The above method of covering all paths is used to select from the first type of test case set to obtain the first use case subset, thereby improving the coverage and accuracy of the first type of test case configuration file data.

[0079] In another optional embodiment, generating first-category test case configuration file data using first-category test cases includes the following steps: obtaining test requirements, wherein the test requirements include multiple test paths and a use case ratio value for each test path; selecting test cases from the first-category test case set according to the test requirements to obtain a second use case subset; and generating first-category test case configuration file data using the second use case subset.

[0080] The second set of test cases is obtained by selecting the first set of test cases according to the test requirements, which can help explore different parts of the user behavior prediction model and increase the possibility of discovering potential problems.

[0081] In another optional embodiment, generating first-class test case configuration file data using first-class test cases includes the following steps: selecting first-class test cases covering all paths from the first-class test case set to obtain a first use case subset; obtaining test requirements; selecting test cases from the first-class test case set according to the test requirements to obtain a second use case subset; and generating first-class test case configuration file data using the first use case subset and the second use case subset.

[0082] Figure 5 is a flowchart of converting a user behavior prediction analysis graph into a first test script according to an embodiment of the present invention, such as Figure 5 As shown in the figure, after obtaining the user behavior prediction graph, multiple first-category test cases are generated according to the above method. When converting these multiple first-category test cases into configuration data files, test case selection is performed by randomly combining test cases and covering all paths. The random combination method introduces a ratio value, selecting a specified ratio of content from all paths and nodes for combination, generating test cases for multiple application environments. The all-path coverage method selects test cases for nodes along all paths. This method combines path coverage with randomness to maximize software testing and significantly reduce the occurrence of missed tests.

[0083] Step S209: Obtain a preset first code framework template and a first shared function.

[0084] First shared functions are functions that can be shared across different test cases or test scripts. These functions can implement various functions designed to improve test efficiency, enhance code maintainability, and ensure test consistency and reliability. Specifically, these functions include, but are not limited to, file parsing and creation, email sending, and task scheduling.

[0085] Step S210: Fill the first type of test case configuration file data into the first code framework template, and obtain the first test script according to the first shared function.

[0086] That is, the embodiment of the present invention also provides an algorithm for converting configuration files into UI automated test scripts, thereby eliminating the need to write automated test scripts one by one, significantly improving the efficiency of test case generation and reducing the workload of manual script writing. Figure 6As shown, generating a test script according to a configuration file involves the following work: obtaining multiple first-category test cases in a database, selecting a subset of first use cases and / or a subset of second use cases from the multiple first-category test cases; generating first-category test case configuration file data according to the subset of first use cases and / or the subset of second use cases. Obtain a first code framework template and a first shared function in a database, wherein the first code framework module can introduce a third-party open source framework pytest, uiautomator2; automatically fill the first-category test case configuration file data into the first code framework template to generate a complete set of directly executable first test scripts; finally, package and publish the first test script, and directly execute the exe file to perform the corresponding test and generate the test results. As shown Figure 7 As shown, it is possible to determine whether the generated content meets actual needs based on the test results. If not, the user behavior prediction model is continuously improved and optimized; if it is satisfied, the first test script is obtained.

[0087] In an optional embodiment, as Figure 5 As shown, after obtaining the first test script according to the first shared function, the following steps are further included: using the first test script to perform testing and obtain test coverage; when the test coverage is less than a preset threshold, adjusting the test requirements. Specifically, adjusting the test requirements can be understood as adjusting the test path and / or adjusting the use case ratio value of the test path. This allows for timely adjustment and optimization of use cases based on the test execution results, which is suitable for scenarios where the software under test is constantly changing.

[0088] The test case generation method provided in this embodiment, by incorporating user behavior, can more accurately simulate real-world user scenarios, improving test coverage and effectiveness. Furthermore, the vehicle-mounted system can optimize functional layout and interaction design based on user behavior predictions, enhancing the user experience. Furthermore, the test case generation method provided in this embodiment can be integrated with existing CI / CD processes, test management, and defect tracking systems, enabling pipeline testing and increasing the automation level of the entire software testing and development process.

[0089] It should be noted that the test case generation method provided in this embodiment only needs to update the user behavior prediction model when the software system to be tested changes, and there is no need to modify a large number of test cases; and it can be reused in multiple test projects, reducing a lot of duplication of work and improving test quality. For example, a single project in a company has more than 6,000 use cases tested on the test bench alone. Each person manually writes 15 automated use cases per day, so it takes 400 man-days to complete the automated test cases for a project, and 4 days of maintenance due to version changes. Generating automated use cases through the user behavior prediction model requires: early model training (60 man-days, which can be reused in multiple projects for 2 man-days) + use case generation (0.5 man-days). After the functional use cases are adjusted, the model is automatically reconstructed and generated, which greatly reduces the testing cost, and testers can focus more on complex scenarios.

[0090] This embodiment provides a method for generating a test case, which can be used in a computer device. Figure 8 FIG. 1 is a flow chart of another test case generation method according to an embodiment of the present invention. Figure 8 As shown, the process includes the following steps:

[0091] Step S801: obtaining a first function test case library and a control structure tree of all pages on the vehicle computer, wherein the first function test case library includes a plurality of first function test cases.

[0092] Step S802: Input the first functional test case library and the control structure tree of all pages on the vehicle computer into the use case feature data extraction model to obtain the second type of test case configuration file data.

[0093] Specifically, the second-category test case configuration file data includes a plurality of second-category test cases, and each second-category test case includes a second precondition, a second test step, and an expected result corresponding to each second test step.

[0094] In an optional embodiment, the use case feature data extraction model is obtained by the following method: obtaining a second function test case library and a control structure tree of all pages on the vehicle computer, wherein the second function test case library includes multiple second function test cases; parsing each second function test case in the second function test case library to obtain the preconditions, test steps, and expected results corresponding to each test step of each second function test case; using the parsed control structure tree of each second function test case and all pages on the vehicle computer to train the preset second model to obtain the use case feature data extraction model.

[0095] Step S803: Obtain a preset second code framework template and a second shared function.

[0096] Secondary shared functions are those that can be shared across different test cases or test scripts. These functions can implement a variety of functions designed to improve test efficiency, enhance code maintainability, and ensure test consistency and reliability. Specifically, these functions include, but are not limited to, file parsing and creation, email sending, and task scheduling.

[0097] Step S804: Fill the second type of test case configuration file data into the second code framework template, and obtain the second test script according to the second shared function.

[0098] Figure 9 This is a flowchart of an example of converting a full set of functional use cases into automated test cases according to an embodiment of the present invention. Figure 9 As shown, the following steps are included:

[0099] (1) Obtain the test case data in the functional test case library (i.e., the second functional test case library) of the test project.

[0100] (2) Extract keyword information from the use case to obtain the preconditions, test steps, and expected results corresponding to each test step of each second function test case in the second function test case library.

[0101] (3) The above data is passed to the second model, and the second model is trained to obtain the use case feature data extraction model. When training the second model, the operations described in the functional test case will first be semantically matched with the controls in the control structure tree. The concept of user behavior confidence is also introduced in the matching process. For example, a test case is to click on the application center page to enter the map page. There are two controls on the interface (bottom navigation bar and application list). If there is no special description in the file, the control operation with high user behavior confidence will be used for mapping, and the text description operation will be mapped to the specific control. The model output corresponds to the test case configuration file after natural language conversion.

[0102] (4) Obtain the control structure tree of the first function test case library and all pages on the vehicle computer, input the control structure tree of the first function test case library and all pages on the vehicle computer into the use case feature data extraction model, and obtain the second type of test case configuration file data.

[0103] (5) Convert the second type of test case configuration file data into a UI automation test script, automatically fill the second type of test case configuration file data into the second code framework template, and use the second shared function to generate a complete set of second test scripts that can be directly executed; finally, package and publish the second test script, and directly execute the exe file to perform the corresponding test and generate test results.

[0104] (6) Manually review the second test script to ensure that the generated content meets the actual needs. The use case feature data extraction model continuously improves and optimizes the corresponding algorithm based on the results of manual review.

[0105] Furthermore, in order to ensure the fault tolerance of automated testing and improve the execution rate, a test exception handling mechanism is provided during the execution of automated test cases, such as Figure 10 and Figure 11 As shown, if pop-up window anomalies or black card module anomalies cause subsequent testing to be interrupted or impossible, the process is as follows: Start the automated test execution tool and execute the automated test cases in sequence. When the case execution is successful, the test results are marked green and written to the report. When the case execution fails, the test exception judgment mechanism process is entered; according to the pop-up window whitelist, it is traversed to see whether it is an advertising pop-up window, upgrade prompt box, new message prompt box, etc. If it is detected, click the pop-up window OK / Cancel / X / blank interface button; otherwise, the black card module detection mechanism is used to detect whether the subsequent case execution cannot be executed due to the black screen, white screen, gray screen, etc. If so, an exception message is immediately sent to the notification group and manual verification is arranged. Otherwise, the test is not terminated, the test result is marked red, the exception image is captured, and the log and exception message are pushed to the notification group, and the next test case is executed. It should be noted that in the process of converting configuration data and automated test scripts, abnormal monitoring logic for pop-up boxes, module card black problems, and logs can be added to ensure that various test scenarios in software applications can be identified during testing. For example, monitoring of abnormal processes such as pop-up boxes, module card black problems, logs, etc. can be carried out to ensure that the test cases can fully cover the functional requirements of the software.

[0106] Figure 12 This is a flow chart of UI automation use case generation according to an embodiment of the present invention, such as Figure 12 As shown, this embodiment provides a method and system for automatically generating UI automated test cases, which includes two methods for generating automated test scripts based on AI models. One method is to generate UI automated test cases based on user behavior training, which is mainly used for generating smoke automated test cases. For details, see Figure 2 and Figure 7 Corresponding implementation examples: One is based on the conversion of full-scale functional use cases into automated test cases, mainly used to generate full-scale business use cases, see Figure 8 Corresponding embodiments.

[0107] This embodiment also provides a test case generation device for implementing the above-mentioned embodiments and preferred implementations. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0108] This embodiment provides a test case generation device, such as Figure 13 Shown, including:

[0109] The first acquisition module 1301 is configured to respectively acquire first UI element data corresponding to each first page.

[0110] The second acquisition module 1302 is used to acquire a trained user behavior prediction model.

[0111] The user behavior prediction analysis graph determining module 1303 is configured to obtain a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model.

[0112] The first type test case generation module 1304 is used to analyze the user behavior prediction analysis graph to obtain a first type test case set.

[0113] In some optional embodiments, the training method of the user behavior prediction model includes: respectively obtaining the second UI element data and control structure tree corresponding to each second page, and the user's behavior data on each second page; organizing the user's behavior data on the second page according to the control structure tree and the second UI element data to obtain multiple operation records, wherein each operation record includes the user behavior, the interface to which the user behavior belongs, the adjacent interface of the interface to which the user behavior belongs, the user behavior's stay time on the interface to which it belongs, and the UI element data of the interface to which the user behavior belongs; using multiple operation records to train the preset first model to obtain a user behavior prediction model.

[0114] In some optional implementations, the user behavior prediction analysis graph determination module 1303 is specifically used to: input the first UI element data corresponding to each first page into the user behavior prediction model to obtain the user's key behavior on each first page and the confidence level of the key behavior; and obtain a user behavior prediction analysis graph based on the user's key behavior on each first page and the confidence level of the key behavior.

[0115] In some optional embodiments, the first type of test case generation module 1304 is specifically used to: extract multiple nodes to be analyzed and the key behaviors of users in each node to be analyzed, and the confidence of the key behaviors in the user behavior prediction analysis graph; determine the priority of all nodes to be analyzed according to the confidence of the key behaviors in all nodes to be analyzed; determine the current node according to the priority of all nodes to be analyzed, and store the current node in the visited node set; obtain all adjacent nodes of the current node and the priority of each adjacent node; select the currently visited adjacent node from all adjacent nodes according to the priority of all adjacent nodes, and use the currently visited adjacent node as the current node, return to the step of storing the current node in the visited node set, until there are no unvisited adjacent nodes, form the current path, and obtain the first type of test case corresponding to the current path; after obtaining the first type of test case, return to the step of determining the current node according to the priority of all nodes to be analyzed, until all nodes to be analyzed have been visited, and obtain multiple paths and the first type of test case corresponding to each path.

[0116] In some optional embodiments, the test case generation device further includes a first test case generation module, wherein the first test case generation module includes a first configuration file generation unit, a first acquisition unit, and a first test case generation unit. The first configuration file generation unit is configured to: generate first-category test case configuration file data using the first-category test case; the first acquisition unit is configured to acquire a preset first code framework template and a first shared function; and the first test case generation unit is configured to fill the first-category test case configuration file data into the first code framework template and obtain a first test script according to the first shared function.

[0117] In some optional embodiments, the first configuration file generation unit is specifically used to: select a first type of test case covering all paths from a first type of test case set to obtain a first use case subset, and use the first use case subset to generate a first type of test case configuration file data; or; obtain test requirements, wherein the test requirements include multiple test paths and a use case ratio value for each test path; select test cases from the first type of test case set according to the test requirements to obtain a second use case subset; use the second use case subset to generate the first type of test case configuration file data; or; select a first type of test case covering all paths from the first type of test case set to obtain a first use case subset; obtain test requirements; select test cases from the first type of test case set according to the test requirements to obtain a second use case subset; use the first use case subset and the second use case subset to generate the first type of test case configuration file data.

[0118] In some optional embodiments, the test case generation device further includes a third acquisition module, a second configuration file data determination module, and a second test case generation module. The third acquisition module is used to obtain a control structure tree of a first functional test case library and all pages on the vehicle computer, wherein the first functional test case library includes multiple first functional test cases; the second configuration file data determination module is used to input the control structure tree of the first functional test case library and all pages on the vehicle computer into a use case feature data extraction model to obtain second-category test case configuration file data; wherein the second-category test case configuration file data includes multiple second-category test cases, each second-category test case includes a second precondition, a second test step, and an expected result corresponding to each second test step; the second test case generation module is used to obtain a preset second code framework template and a second shared function; fill the second-category test case configuration file data into the second code framework template, and obtain a second test script according to the second shared function.

[0119] In some optional embodiments, the use case feature data extraction model is obtained by the following method: obtaining a second function test case library and a control structure tree of all pages on the vehicle computer, wherein the second function test case library includes multiple second function test cases; parsing each second function test case in the second function test case library to obtain the preconditions, test steps, and expected results corresponding to each test step of each second function test case; using the parsed control structure tree of each second function test case and all pages on the vehicle computer to train the preset second model to obtain the use case feature data extraction model.

[0120] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0121] The test case generation device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0122] The embodiment of the present invention also provides a computer device having the above Figure 11 The test case generation device shown.

[0123] See also Figure 14 , Figure 14 is a structural diagram of a computer device provided by an optional embodiment of the present invention, such as Figure 14As shown, the computer device includes: one or more processors 10, memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components utilize different buses to communicate with each other and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in the memory or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Equally, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 14 A processor 10 is taken as an example.

[0124] The processor 10 may be a central processing unit, a network processor, or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic, or any combination thereof.

[0125] The memory 20 stores instructions that can be executed by at least one processor 10, so as to enable at least one processor 10 to execute the method shown in the above embodiment.

[0126] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created based on the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0127] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid-state drive; the memory 20 may also include a combination of the above types of memory.

[0128] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 can be connected via a bus or other means. Figure 14 The bus connection is taken as an example.

[0129] The input device 30 can receive input digital or character information and generate key signal input related to user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a trackpad, a touch pad, an indicator stick, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 can include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor). The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display, and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0130] The embodiment of the present invention also provides a computer-readable storage medium. The above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.

[0131] A portion of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the form in which the computer program instruction exists in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc. Accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium that can be accessed by the computer.

[0132] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for generating a test case, characterized in that: include: Respectively obtain first UI element data corresponding to each first page; Obtain a trained user behavior prediction model; Obtaining a user behavior prediction analysis graph based on the first UI element data corresponding to each of the first pages and the user behavior prediction model; The user behavior prediction analysis graph is analyzed to obtain a first type of test case set.

2. The method according to claim 1, characterized in that The training method of the user behavior prediction model includes: Respectively obtain the second UI element data and control structure tree corresponding to each second page, and the user's behavior data on each second page; The user's behavior data on the second page is sorted according to the control structure tree and the second UI element data to obtain multiple operation records, wherein each operation record includes the user behavior, the interface to which the user behavior belongs, the adjacent interfaces of the interface to which the user behavior belongs, the time the user behavior stays on the interface to which it belongs, and the UI element data of the interface to which the user behavior belongs; The preset first model is trained using the multiple operation records to obtain the user behavior prediction model.

3. The method according to claim 1, characterized in that The obtaining of a user behavior prediction analysis graph according to the first UI element data corresponding to each first page and the user behavior prediction model includes: Inputting the first UI element data corresponding to each first page into the user behavior prediction model to obtain the key behavior of the user on each first page and the confidence level of the key behavior; The user behavior prediction analysis graph is obtained based on the key behavior of the user on each of the first pages and the confidence level of the key behavior.

4. The method according to claim 1, wherein The first type of test case set obtained by analyzing the user behavior prediction analysis graph includes: Extracting a plurality of nodes to be analyzed, a key behavior of the user at each of the nodes to be analyzed, and a confidence level of the key behavior from the user behavior prediction analysis graph; Determining the priorities of all the nodes to be analyzed according to the confidence levels of the key behaviors in all the nodes to be analyzed; Determine a current node according to the priorities of all the nodes to be analyzed, and store the current node in a visited node set; Obtaining all adjacent nodes of the current node and the priority of each adjacent node; Selecting a currently visited adjacent node from all the adjacent nodes according to the priorities of all the adjacent nodes, and using the currently visited adjacent node as the current node, returning to the step of storing the current node in the visited node set until there are no unvisited adjacent nodes, forming a current path, and obtaining a first type of test case corresponding to the current path; After obtaining the first type of test case, return to the step of determining the current node according to the priorities of all the nodes to be analyzed until all the nodes to be analyzed have been visited, and obtain multiple paths and the first type of test case corresponding to each path.

5. The method according to claim 1, wherein After analyzing the user behavior prediction analysis graph to obtain the first type of test cases, the method further includes: generating first-category test case configuration file data using the first-category test case; Obtaining a preset first code framework template and a first shared function; The first type of test case configuration file data is filled into the first code framework template, and the first test script is obtained according to the first shared function.

6. The method according to claim 5, characterized in that Generating first-category test case configuration file data using the first-category test case includes: Selecting first-category test cases covering all paths from the first-category test case set to obtain a first subset of test cases, and generating the first-category test case configuration file data using the first subset of test cases; Alternatively, obtaining a test requirement, wherein the test requirement includes a plurality of test paths and a use case ratio value of each test path; selecting a test case from the first type of test case set according to the test requirement to obtain a second use case subset; and generating the first type of test case configuration file data using the second use case subset; Or; select the first type of test cases covering all paths from the first type of test case set to obtain a first use case subset; obtain the test requirements; select test cases from the first type of test case set according to the test requirements to obtain the second use case subset; use the first use case subset and the second use case subset to generate the first type of test case configuration file data.

7. The method according to claim 6, characterized in that After obtaining the first test script according to the first shared function, the method further includes: Performing testing using the first test script and obtaining test coverage; When the test coverage is less than a preset threshold, the test requirement is adjusted.

8. The method according to claim 1, characterized in that Also includes: Obtaining a first function test case library and a control structure tree of all pages on the vehicle computer, wherein the first function test case library includes multiple first function test cases; Inputting the first functional test case library and the control structure tree of all pages on the vehicle computer into the use case feature data extraction model to obtain the second type of test case configuration file data; The second-category test case configuration file data includes a plurality of second-category test cases, each of which includes a second precondition, a second test step, and an expected result corresponding to each second test step; Obtain a preset second code framework template and a second shared function; The second type of test case configuration file data is filled into the second code framework template, and the second test script is obtained according to the second shared function.

9. The method according to claim 8, characterized in that The use case feature data extraction model is obtained by the following method: Obtaining a second function test case library and a control structure tree of all pages on the vehicle computer, wherein the second function test case library includes a plurality of second function test cases; Parsing each second function test case in the second function test case library to obtain a precondition, a test step, and an expected result corresponding to each test step of each second function test case; The preset second model is trained using each parsed second function test case and the control structure tree of all pages on the vehicle computer to obtain the use case feature data extraction model.

10. A test case generation device, characterized in that: include: A first acquisition module is used to respectively acquire first UI element data corresponding to each first page; The second acquisition module is used to obtain the trained user behavior prediction model; a user behavior prediction analysis graph determination module, configured to obtain a user behavior prediction analysis graph based on the first UI element data corresponding to each first page and the user behavior prediction model; The first type test case generation module is used to analyze the user behavior prediction analysis graph to obtain multiple first type test cases.

11. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the test case generation method according to any one of claims 1 to 9 by executing the computer instructions.

12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the test case generation method according to any one of claims 1 to 9.

13. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the test case generation method according to any one of claims 1 to 9.