Test case generation method and device

By training the test case model, automatically generate test cases for Android applications, solving the problems of low manual testing efficiency and high maintenance costs, and achieving efficient and accurate test coverage and application update adaptation.

CN119166511APending Publication Date: 2024-12-20SHANGHAI INNOVATECH INFORMATION TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411219181.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

Existing Android application testing requires a lot of manual participation, resulting in long test cycles, low coverage, high maintenance costs, and difficulty in dealing with complex interactive logic, lacking intelligent and automated functions.

Method used

By obtaining multiple xml files as training data, training test case models, determining the test operations corresponding to UI elements, realizing automated generation of test cases, reducing manual dependencies, improving testing efficiency and accuracy, and adapting to application updates and complex interaction scenarios.

Benefits of technology

It realizes automated generation of test cases, reduces labor costs, improves testing efficiency and accuracy, quickly adapts to application changes, covers various functions and interactive scenarios, and realizes intelligent and automated testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166511A_ABST
    Figure CN119166511A_ABST
Patent Text Reader

Abstract

The invention provides a test case generation method and device, and relates to the technical field of software testing, the method comprises: obtaining training data, the training data comprising a plurality of xml files, each of the plurality of xml files comprising a plurality of UI elements, attributes of the plurality of UI elements, and test operations corresponding to the attributes of the plurality of UI elements; training a test case model according to the training data; obtaining a first xml file of the first Android application under the first interface; inputting the first xml file into the test case model to determine a first test operation corresponding to a first UI element in the first xml file; and generating a test case corresponding to the first Android application based on the first test operation. Based on the test case model, the test operation corresponding to the UI element in the input xml file can be generated, the test case corresponding to the Android application is automatically generated, and the test efficiency and accuracy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software testing technology, and more specifically, to a test case generation method and device. Background Art

[0002] Before an Android application is put into use, it is usually tested to find program errors, measure the quality of the application, and evaluate whether it can meet the design requirements. Currently, Android application testing requires a large number of testers to manually participate in writing test cases, which increases the test cycle and is prone to human errors, resulting in low test coverage. Once the application is updated, the original test script cannot be used and needs to be updated, resulting in increased maintenance costs. In addition, when the interactive logic of the application is complex, manually writing test cases will affect the test efficiency and accuracy of the application.

[0003] Therefore, how to automatically generate test cases has become an urgent problem to be solved. Summary of the invention

[0004] The present application provides a test case generation method and device, aiming to realize automatic generation of test cases, avoid dependence on human resources, and improve the efficiency and accuracy of testing.

[0005] In a first aspect, a test case generation method is provided, comprising: obtaining training data, the training data comprising a plurality of xml files, each of the plurality of xml files comprising a user interface UI element, attributes of the plurality of UI elements, and test operations corresponding to the attributes of the plurality of UI elements; training a test case model according to the training data; obtaining a first xml file of a first Android application in a first interface; inputting the first xml file into the test case model to determine a first test operation corresponding to a first UI element in the first xml file; and generating a test case corresponding to the first Android application based on the first test operation.

[0006] Based on the above scheme, multiple xml files are obtained as training data to train the test case model. Through the trained test case model, the first test operation corresponding to the first UI element in the input first xml file can be obtained. In this way, even if the input first xml file is different from the multiple xml files included in the training data, the test operation corresponding to the UI element in the first xml file can still be determined through the test case model, so that when the interface corresponding to the Android application changes, the test case corresponding to the Android application can be automatically generated, reducing the time, workload and dependence on human resources for manually writing test cases, improving testing efficiency and accuracy, and when the Android application is updated, the UI elements of the updated Android application in the current interface are quickly obtained, and the corresponding test cases are automatically generated to realize the processing of complex interactions, and can quickly cover various functions and interaction scenarios of the application, thereby realizing intelligent and automated testing.

[0007] In combination with the first aspect, in certain implementations of the first aspect, the test case generation method also includes: executing the first test operation to obtain a second xml file of the first Android application under the second interface; inputting the second xml file into the test case model to generate a second test operation corresponding to the second UI element in the second xml file.

[0008] Based on the above scheme, after obtaining the first test operation, executing the first test operation can enter the second interface of the first Android application, and then obtain the xml file of the first Android application in the second interface, so as to obtain the second test operation through the test case model to obtain the entire test case corresponding to the first Android application, so that the test operation corresponding to the UI element of the first Android application in the accessible interface can be obtained in real time.

[0009] In combination with the first aspect, in certain implementations of the first aspect, generating a test case corresponding to the first Android device based on the first test operation includes: generating a first test code based on the first test operation; generating a second test code based on the second test operation; and integrating the first test code and the second test code in sequence to generate a test case corresponding to the first Android application.

[0010] Based on the above scheme, by obtaining the XML file under each interface in real time, the test operations corresponding to the UI elements on each interface can be obtained in real time, and the test operations corresponding to each UI element under the start interface can be generated, as well as the test codes corresponding to the UI elements under the interface entered by executing the test operations corresponding to each UI element, thereby generating test cases corresponding to the Android application.

[0011] It can be understood that when the third interface corresponding to the first Android application can be entered after the second test operation is executed, the third xml file of the first Android application under the third interface can be obtained, and the third xml file can be input into the test case model, so that the third test operation corresponding to the third UI element in the third xml file can be determined, and then the third test code is generated based on the third test operation, and the first test code, the second test code and the third test code are integrated in sequence to generate the test case corresponding to the first Android application. In other words, after executing the first test operation, if the next interface of the first interface can be entered, the test operation corresponding to the UI element in the next interface is executed, and so on, until the interface of the next level cannot be entered, the test operation starting from the first UI element in the first interface to the UI element corresponding to the first UI element in the last interface, the test code is generated, and the generated test code is integrated into the test case corresponding to the Android application. Among them, the UI element corresponding to the first UI element can be understood as the UI element of the last level corresponding to the first UI element.

[0012] In combination with the first aspect, in certain implementations of the first aspect, the first xml file is input into the test case model to determine a first test operation corresponding to a first UI element in the first xml file, including: the test case model parses the first xml file to generate a UI element tree, the nodes in the UI element tree include the first UI element; traverses the UI element tree to identify the first UI element; and based on the first UI element, determines the first test operation corresponding to the first UI element.

[0013] In combination with the first aspect, in some implementations of the first aspect, identifying the first UI element includes: traversing each node in the UI element tree to determine a property of the first UI element.

[0014] In combination with the first aspect, in certain implementations of the first aspect, determining the first test operation corresponding to the first UI element based on the first UI element includes: determining the test operation corresponding to the first UI element based on the attributes of the first UI element; determining the first test operation corresponding to the first UI element based on the test operation corresponding to the first UI element.

[0015] In combination with the first aspect, in certain implementations of the first aspect, obtaining a first xml file of a first Android application in a first interface includes: connecting the first Android application to a computer through an Android Debug Bridge ADB tool; obtaining a layout of multiple UI elements of the first Android application in the first interface through a first command in the ADB tool; saving the layout of the multiple UI elements in the first interface as the first xml file, and transferring the first xml file to the computer, wherein the multiple UI elements in the first interface include the first UI element.

[0016] In combination with the first aspect, in certain implementations of the first aspect, connecting the first Android application to the computer through the Android Debug Bridge ADB tool includes: obtaining a device list through a second command in the ADB tool, the device list including one or more Android devices, wherein the one or more Android devices include a first Android device corresponding to the first Android application, and selecting the first Android device to connect to the computer.

[0017] In combination with the first aspect, in some implementations of the first aspect, the test case model is deployed on a cloud server or a computer.

[0018] In a second aspect, a test case generation device is provided, the test case generation device comprising an acquisition module, a training module, a determination module and a generation module,

[0019] The acquisition module is used to acquire training data, the training data includes multiple xml files, each of the multiple xml files includes multiple user interface UI elements, attributes of the multiple UI elements and test operations corresponding to the attributes of the multiple UI elements; the training module is used to train the test case model according to the training data; the acquisition module is also used to acquire a first xml file of a first Android application under a first interface; the determination module is used to input the first xml file into the test case model to determine a first test operation corresponding to a first UI element in the first xml file; the generation module is used to generate a test case corresponding to the first Android application based on the first test operation.

[0020] In a third aspect, a test case generation device is provided, which includes: a processor and a memory, the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the test case generation method provided in the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is a schematic block diagram of manually writing an Android application test case 100.

[0022] Figure 2 It is a schematic block diagram of a test case generation method 200 provided in an embodiment of the present application.

[0023] Figure 3 It is a schematic block diagram of a method 300 for obtaining a first XML file provided in an embodiment of the present application.

[0024] Figure 4 It is a schematic block diagram of a method 400 for determining a first test operation corresponding to a first UI element in a first XML file provided in an embodiment of the present application.

[0025] Figure 5 It is a schematic block diagram of a method 500 for generating a test case corresponding to a first Android application provided in an embodiment of the present application.

[0026] Figure 6 It is a schematic structural block diagram of a test case generating device 600 provided in an embodiment of the present application.

[0027] Figure 7 It is a schematic structural block diagram of another test case generating device 700 provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] The technical solution in this application will be described below in conjunction with the accompanying drawings.

[0029] Figure 1 1 shows a schematic block diagram of manually writing an Android application test case 100. Figure 1 As shown, manually writing an Android application test case 100 includes the following steps.

[0030] S110. Determine the test scope.

[0031] Testers determine the functional points or modules that need to be tested based on the functional requirements of the application.

[0032] S120. Write test case scripts.

[0033] Testers manually write test case scripts based on the functional points or modules that need to be tested, defining the test steps and expected results. Specifically, each test case is assigned a unique number; the purpose of the test case is described; the conditions that need to be met when executing the test are set, such as a specific system configuration; the results that should be observed after the test is successful are defined; and the actual results observed after the test execution is completed are recorded.

[0034] S130, executing the written test case script.

[0035] Use automated testing tools to execute written test case scripts, test the application's functionality by simulating user operations, and record actual test results.

[0036] The above method can realize automated testing to a certain extent, but there are still the following shortcomings:

[0037] 1) High labor costs: Writing and maintaining test scripts requires a lot of human resources, and the workload will increase exponentially when faced with frequently updated and complex interactive applications.

[0038] 2) Prone to omissions and human errors: Manually written test scripts are prone to omissions and human errors, resulting in insufficient test coverage, making it impossible to discover potential problems in the application when using the written test cases.

[0039] 3) High maintenance cost: After the application is updated, the test script needs to be modified and updated accordingly, which increases the maintenance workload, resulting in higher maintenance costs and is prone to introducing new errors.

[0040] 4) Difficulty in handling complex interactions: When dealing with complex user interactions and dynamic interface elements, manually written test cases are inefficient and difficult to cover all test scenarios.

[0041] 5) Lack of intelligence and automation: Most existing automated testing tools rely on predefined scripts, lack intelligence and automation functions, and cannot automatically generate new test cases based on changes in the application.

[0042] In view of this, the present application proposes a new test case generation method. By acquiring training data, a test case model is trained. When a new xml file is obtained, the trained test case model can be used to determine the test operations corresponding to the UI elements in the new xml file, and then the test cases corresponding to the Android application can be obtained. In this way, the test cases for Android applications can be automatically generated, the testing efficiency can be improved, and the labor costs can be reduced.

[0043] Figure 2 A schematic block diagram of a test case generation method 200 provided in an embodiment of the present application is shown.

[0044] like Figure 2 As shown, the test case generation method 200 includes the following steps.

[0045] S210. Acquire training data, where the training data includes multiple xml files, each of the multiple xml files includes multiple user interface UI elements, attributes of the multiple UI elements, and test operations corresponding to the attributes of the multiple UI elements.

[0046] S220: Train a test case model based on the training data.

[0047] S230, obtaining a first xml file of the first Android application in the first interface.

[0048] S240. Input the first xml file into the test case model to determine a first test operation corresponding to the first UI element in the first xml file.

[0049] S250: Based on the first test operation, generate a test case corresponding to the first Android application.

[0050] The first Android application is an application program in the first Android device. The first Android application may also be referred to as a first Android application, and the first Android device may also be referred to as a first Android device.

[0051] The embodiment of the present application generates test cases for Android applications based on a test case model, and executing the test cases can achieve automated testing of Android applications.

[0052] In the above step S210, the training data is a plurality of XML files, each of which includes layout information of a plurality of user interface (UI) elements, and the layout information includes the attributes and hierarchical structure of the plurality of UI elements and the test operations corresponding to the attributes of the plurality of UI elements, for example, the position, size and arrangement of UI elements on the Android interface.

[0053] Specifically, the training data can be obtained by connecting a computer to an Android device. For example, the connection between the Android device and the computer can be achieved through the Android Debug Bridge (ADB) tool configured in the computer, and then the adb shell uiautomator dump command is executed through ADB to obtain the layout information of the user interface (UI) elements of the application in the Android device, and the layout information of the UI elements is saved as an XML file, such as a window_dump.xml file.

[0054] Optionally, the training data may be a plurality of XML files saved historically, for example, a plurality of window_dump.xml files saved on a computer.

[0055] Exemplarily, the above-mentioned multiple XML files can be XML files obtained from multiple Android applications, or can be XML files obtained from one Android application in different interfaces. Among them, multiple XML files can be XML files obtained from multiple Android applications, and it can be understood that one XML file corresponds to an XML file in one interface of an Android application.

[0056] Exemplarily, UI elements may include buttons, text boxes, labels, sliders, menus, icons, check boxes, radio buttons, drop-down menus, scroll bars, dialog boxes, etc. UI elements can display the structure of Android applications, provide application information to users, interact with applications, etc. For example, users can interact with applications through buttons.

[0057] The properties of a UI element include: the identity (ID) of the UI element, the class name of the UI element, the text content of the UI element, etc., wherein the ID of the UI element is used to uniquely identify the UI element, the class name of the UI element is used to indicate the function of the UI element or the type of the UI element or the position of the UI element in the interface; the text content of the UI element includes the label of the button, the default text in the text box, prompt information, error information, navigation menu items, page titles, paragraph text, etc. For example, the multiple UI elements obtained are buttons, and the properties of the button include the button ID, the class name of the button, etc.

[0058] The test operations corresponding to the attributes of the UI element include: click, input, slide, etc. For example, if the attribute of the UI element is a button ID, the test operation corresponding to the button element is click.

[0059] In the above step S220, the test case model can be trained according to the acquired training data to obtain a trained test case model.

[0060] Specifically, according to the multiple UI elements, the attributes of the multiple UI elements, and the test operations corresponding to the attributes of the multiple UI elements included in each of the multiple xml files included in the training data, the test case model learns the test operations corresponding to each UI element and the attributes of each UI element. Taking the multiple xml files as multiple window_dump.xml files as an example, the process of training the test case model can also be understood as analyzing the input multiple window_dump.xml files, obtaining the multiple UI elements, the attributes of the multiple UI elements, and the test operations corresponding to the attributes of the multiple UI elements in each of the multiple window_dump.xml files, so that the test case model has the ability to learn the UI elements in the input xml files. For example, for a button element, the corresponding test operation is clicking. For another example, for a sliding element, the corresponding test operation is sliding up and down or sliding left and right. For another example, for a text box element, the corresponding test operation is inputting text.

[0061] Furthermore, the trained test case can determine the test operation corresponding to the UI element in the input XML file based on the input XML file. The test case model is deployed on a cloud server or a computer.

[0062] In a possible implementation, the test case model is deployed in a cloud server, which has computing capabilities.

[0063] In a possible implementation, the test case model is deployed in a computer.

[0064] Exemplarily, in the process of training the test case model, the test operation corresponding to each UI element learned can be stored in an extensible test operation library. The extensible test operation library means that the test operations in the test operation library can be increased in real time. For example, after obtaining a new XML file, the test operations corresponding to the UI elements in the new XML file are learned, and the obtained test operations are stored in the test operation library.

[0065] It should be noted that in the embodiment of the present application, the test operation corresponding to the attributes of each UI element can also be called the test rule corresponding to the attributes of each UI element. That is to say, in the embodiment of the present application, the test operation can also be called the test rule, and the test operation library can also be called the test rule library.

[0066] In the above step S230, the first Android device where the first Android application is located is connected to the computer to obtain the first XML file of the first Android application in the first interface.

[0067] Specifically, the first Android device corresponding to the first Android application can be connected to the computer through the ADB tool, and the first xml file of the first Android application in the first interface can be obtained through the command in the ADB tool.

[0068] Specifically, the above step S230 includes: Figure 3 Steps S310 to S330 in .

[0069] Figure 3 A schematic block diagram of a method 300 for obtaining a first XML file provided in an embodiment of the present application is shown.

[0070] like Figure 3 As shown, the method 300 for obtaining the first XML file includes the following steps.

[0071] S310. Connect the first Android application to the computer through the ADB tool.

[0072] Specifically, the first Android application is located in the first Android device. Therefore, connecting the first Android application to the computer through the ADB tool can be understood as connecting the first Android device to the computer through the ADB tool, thereby realizing the connection between the first Android application and the computer.

[0073] As a possible implementation method, the connection between the first Android application and the computer can also be achieved through TCP / CP / WIFI.

[0074] S320. Obtain a layout of multiple UI elements of a first Android application in a first interface through a first command in an ADB tool.

[0075] Specifically, a first command is sent to the first Android device through an ADB tool, and a layout of multiple UI elements of a first Android application in a first interface in the first Android device is obtained by executing the first command.

[0076] Exemplarily, the first command may be an adb shell uiautomator dump command. The layout of multiple UI elements of the first Android application in the first interface includes the hierarchy and attributes of the UI elements. For example, the position, size, and arrangement of the UI elements on the Android screen.

[0077] Among them, the implementation method of connecting the first Android application to the computer can be: obtaining a device list through a second command in the ADB tool, the device list including one or more Android devices, wherein the one or more Android devices include a first Android device corresponding to the first Android application, and selecting the first Android device to connect to the computer.

[0078] Exemplarily, the second command may be an adb devices command. Executing the adb devices command can obtain a device list, select the first Android device in the device list, and connect the first Android device to the computer, thereby connecting the first Android application to the computer.

[0079] S330. Save the layout of multiple UI elements in the first interface as a first xml file, and transfer the first xml file to a computer, wherein the multiple UI elements in the first interface include the first UI element.

[0080] Specifically, taking the first xml file as the first window_dump.xml file as an example for description, the command adb pull / sdcard / window_dump.xml is sent to the first Android device through ADB, and the first window_dump.xml file is transferred to the computer by executing the adb pull / sdcard / window_dump.xml command.

[0081] Furthermore, the first XML file is input into the above-mentioned trained test case model.

[0082] In the above step S240, after obtaining the first xml file, the first xml file is used as the input of the trained test case model to determine the test operation corresponding to each UI element in the first xml file. For ease of description, the following description is based on the first xml file being the first window_dump.xml file.

[0083] Specifically, when the test case model is deployed on a computer, the computer directly inputs the acquired first window_dump.xml file into the test case model. When the test case model is not deployed on a computer, for example, due to low computing efficiency of the computer, the test case model can be deployed on a cloud server, at which point the computer transmits the first window_dump.xml file to the cloud server through an interface, and then the cloud server inputs the first window_dump.xml file into the test case model.

[0084] Further, the test case model parses the input first window_dump.xml file, identifies the UI elements therein, and thereby determines the test operations corresponding to the UI elements in the first window_dump.xml file. Taking the first UI element in the first window_dump.xml file as an example, determining the test operations corresponding to the first UI element in the first window_dump.xml file includes: Figure 4 Steps S410 to S430 in .

[0085] Figure 4 A schematic block diagram of a method 400 for determining a first test operation corresponding to a first UI element in a first XML file provided in an embodiment of the present application is shown.

[0086] like Figure 4 As shown, the method 400 for determining a first test operation corresponding to a first UI element in a first XML file includes the following steps.

[0087] S410: The test case model parses the first XML file to generate a UI element tree, where the nodes in the UI element tree include the first UI element.

[0088] Specifically, taking the first xml file as the first window_dump.xml file as an example for description, the test case model includes a parsing function, which is used to parse the first window_dump.xml file. For example, the parsing function can be a function of the xml.etree.ElementTree library in Python. After parsing the first window_dump.xml file, the parsing function generates a UI element tree, and the nodes in the UI element tree are UI elements in the first window_dump.xml file.

[0089] Among them, the UI element tree arranges the UI elements in the first window_dump.xml file in a tree manner. The UI element tree includes a root node and child nodes. The root node is the starting point of the entire UI element tree structure, and the child nodes represent the UI elements in the first window_dump.xml file. The UI element tree can represent the hierarchical relationship between multiple UI elements in the first window_dump.xml file.

[0090] S420: Traverse the UI element tree and identify the first UI element.

[0091] The UI element tree is traversed by a parsing function to identify multiple UI elements in the first xml file, that is, the first UI element can be identified by traversing the UI element tree.

[0092] The identifying of the first UI element includes: traversing each node in the UI element tree to determine the attribute of the first UI element. Specifically, traversing each node in the UI element tree through a parsing function to determine the attribute of the UI element in the first window_dump.xml file.

[0093] Exemplarily, in the present application, the parsing function can traverse the UI element tree recursively or non-recursively. For example, the UI element tree can be traversed recursively, starting from the root node, traversing and searching all child nodes, identifying the UI elements of the first Android application in the current interface, that is, identifying the UI elements in the first window_dump.xml file, and at the same time, it can also determine the attributes of the UI elements in the first window_dump.xml file.

[0094] S430: Based on the first UI element, determine a first test operation corresponding to the first UI element.

[0095] Specifically, the test operation corresponding to the first UI element is determined through the identified attribute of the first UI element, and then the first test operation corresponding to the first UI element is determined according to the test operation corresponding to the first UI element.

[0096] Further, based on the first test operation, a test case corresponding to the first Android application is generated.

[0097] In the above step S250, the acquired first test operation is saved, and then a first test code is generated, and then a test case corresponding to the first Android application is generated.

[0098] Figure 5 A schematic block diagram of a method 500 for generating a test case corresponding to a first Android application provided in an embodiment of the present application is shown.

[0099] like Figure 5 As shown, the method 500 for generating a test case corresponding to the first Android application includes the following steps.

[0100] S510: Determine a test operation corresponding to the first UI element based on an attribute of the first UI element.

[0101] Specifically, the first xml file is described as the first window_dump.xml file as an example, and based on the attributes of each UI element in the first window_dump.xml file, the test operation corresponding to each UI element can be determined. For example, the attribute of the first UI element is a button, and according to the test operation corresponding to the button, it is determined that the test operation corresponding to the button element is click.

[0102] S520: Determine a first test operation corresponding to the first UI element based on the test operation corresponding to the first UI element.

[0103] Specifically, if the test operation corresponding to the first UI element is click, then the first test operation corresponding to the first UI element is click.

[0104] Further, based on the first test operation, a test case corresponding to the first Android application is generated.

[0105] S530: Generate a first test code based on the first test operation.

[0106] Specifically, the first test code corresponding to the first test operation is generated through a string template function. For example, for a button click operation, the code new UiSelector().resourceId("button_id").click() is generated. The string template function is a function in the string library in Python.

[0107] In a possible implementation, the first test operation is performed to enter the second interface of the first Android application. At this time, since the first Android device is still connected to the computer, after the second interface is performed, the second XML file of the first Android application in the second interface can be obtained.

[0108] It can be understood that the second interface is a layer below the first interface, and the multiple UI elements in the second xml file are multiple UI elements in the next hierarchical structure of the multiple UI elements in the first xml file. At this time, the test case generation method 200 further includes:

[0109] Execute a first test operation to obtain a second xml file of the first Android application in the second interface; input the second xml file into the test case model to generate a second test operation corresponding to the second UI element in the second xml file.

[0110] Specifically, the layout of multiple UI elements of the first Android application in the second interface is obtained through the first command in the ADB tool, and the layout of multiple UI elements of the first Android application in the second interface is saved as a second XML file. Then, the second XML file is used as an input of the test case model, and the test operation corresponding to each UI element in the second XML file is determined through the test case model, for example, the second test operation corresponding to the second UI element.

[0111] Furthermore, the above-mentioned generating a test case corresponding to the first Android application based on the first test operation includes: generating a first test code based on the first test operation; generating a second test code based on the second test operation; integrating the first test code and the second test code in sequence to generate a test case corresponding to the first Android application.

[0112] Specifically, the second test code is generated through the string template function in the string library in Python, the first test code and the second test code are integrated into a complete test case script, and saved in a Java file, and then the Java file is executed on the first Android device through the UIAutomator framework.

[0113] It should be noted that the second test operation is a test operation at the next level of the first test operation. For example, if it is the attribute button of the first UI element, the first test operation is a click. After executing the click operation, the second interface is displayed. At this time, the second UI element can be input text. The second test operation is to input text content. Further, the first test operation generates a corresponding first test code, and the second test operation generates a corresponding second test code. The first test code and the second test code are integrated into a test case, that is, a test case corresponding to the first Android application is generated.

[0114] It should also be noted that after executing the second test operation, if you can still enter the third interface corresponding to the first Android application, you can further obtain the third xml file of the first Android application in the third interface, input the third xml file into the test case model, and determine the third test operation corresponding to the third UI element in the third xml file, and then generate a third test code based on the third test operation, and integrate the first test code, the second test code and the third test code in sequence to generate a test case corresponding to the first Android application. In other words, after executing the first test operation, if you can enter the next interface of the first interface, then execute the test operation corresponding to the UI element in the next interface, and so on, until you cannot enter the next level of interface, and generate test code from the test operation of the first UI element in the first interface to the UI element corresponding to the first UI element in the last interface, and integrate the generated test code into the test case corresponding to the Android application. Among them, the UI element corresponding to the first UI element can be understood as the UI element of the last level corresponding to the first UI element.

[0115] In an embodiment of the present application, the first Android application has UI elements other than the first UI element under the first interface, and the method for determining the test operation corresponding to the UI elements other than the first UI element is the same as the method for determining the first test operation corresponding to the first UI element. That is to say, the corresponding test operation can be determined for each UI element, and then the corresponding test code can be determined, and then when each UI element has a UI element of the next level, the test code can be generated in sequence. For example, the first Android application corresponds to two levels, and the first UI element is on the first level. After executing the first test operation corresponding to the first UI element, it enters the second level where the second UI element is located, and then the test code corresponding to the first UI element and the test code corresponding to the first UI element are integrated to generate a test case for the first Android application. In this way, by obtaining the xml file under each interface in real time, the test operation corresponding to the UI element on each interface can be obtained in real time, and the test operation corresponding to each UI element under the start interface is generated, as well as the test code corresponding to the UI element under the interface entered by executing the test operation corresponding to each UI element, thereby generating a test case corresponding to the Android application.

[0116] In an embodiment of the present application, the test case model can be used to determine the test operations corresponding to the UI elements in the input xml file. The test case model can be a rule-based model, that is, the test rules corresponding to the UI elements can be determined through training data.

[0117] In one implementation, a test case corresponding to the first Android application can be generated through a template matching-based method. Specifically, a predefined interface template matching technology is used to identify the UI elements and the layout of the UI elements of the first Android application in the current interface, and generate a test case corresponding to the first Android application.

[0118] Optionally, a series of test rules and strategies may be defined to generate test cases based on the UI elements and the layout of the UI elements of the first Android application in the current interface in combination with the interaction logic.

[0119] Optionally, the template matching method, the rule-based model method and the rule-based method may be combined to generate test cases using a hybrid method of the above methods.

[0120] In the scheme of the embodiment of the present application, multiple xml files are obtained as training data to train the test case model. Through the trained test case model, the first test operation corresponding to the first UI element in the input first xml file can be obtained. In this way, even if the input first xml file is different from the multiple xml files included in the training data, the test operation corresponding to the UI element in the first xml file can still be determined through the test case model, so that when the interface corresponding to the Android application changes, the test case corresponding to the Android application can be automatically generated, reducing the time, workload and dependence on human resources for manually writing test cases, improving testing efficiency and accuracy, and when the Android application is updated, the UI elements of the updated Android application in the current interface are quickly obtained, and the corresponding test cases are automatically generated to realize the processing of complex interactions, and can quickly cover various functions and interaction scenarios of the application, thereby realizing intelligent and automated testing.

[0121] An embodiment of the present application also provides a test case generating device. Figure 6 A schematic structural block diagram of a test case generating device 600 provided in an embodiment of the present application is shown.

[0122] like Figure 6 As shown, the test case generating device 600 may include an acquisition module 610 , a training module 620 , a determination module 630 and a generation module 640 .

[0123] The acquisition module 610 is used to acquire training data, which includes multiple XML files. Each of the multiple XML files includes multiple user interface UI elements, attributes of the multiple UI elements, and test operations corresponding to the attributes of the multiple UI elements.

[0124] The training module 620 is used to train the test case model according to the training data.

[0125] The acquisition module 610 is further used to acquire the first XML file of the first Android application in the first interface.

[0126] The determination module 630 is used to input the first XML file into the test case model to determine the first test operation corresponding to the first UI element in the first XML file.

[0127] The generating module 640 is used to generate a test case corresponding to the first Android application based on the first test operation.

[0128] The embodiment of the present application also provides another test case generating device. Figure 7Another test case generating device 700 provided in an embodiment of the present application is shown. The test case generating device 700 may include a memory 710 and a processor 720 .

[0129] The memory 710 is used to store computer programs.

[0130] The processor 720 is used to call and run the computer program stored in the memory 710 to execute: the test case generation method provided in the above embodiment.

[0131] An embodiment of the present application also provides a computer-readable storage medium for storing a computer program.

[0132] Optionally, the computer-readable storage medium can be applied to the method of generating test cases for the application in the embodiments of the present application, and the computer program enables the computer to execute the corresponding processes in the various methods in the embodiments of the present application. For the sake of brevity, they will not be repeated here.

[0133] An embodiment of the present application also provides a computer program product, including computer program instructions.

[0134] Optionally, the computer program product can be applied to the method of generating test cases for the application in the embodiments of the present application, and the computer program instructions enable the computer to execute the corresponding processes in the various methods in the embodiments of the present application, which will not be described in detail here for the sake of brevity.

[0135] The embodiment of the present application also provides a computer program.

[0136] Optionally, the computer program can be applied to the method of generating test cases for the application program in the embodiments of the present application. When the computer program runs on a computer, the computer executes the corresponding processes in the various methods in the embodiments of the present application. For the sake of brevity, they are not described here.

[0137] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0138] It should be understood that the specific examples in this article are only intended to help those skilled in the art better understand the embodiments of the present application, rather than to limit the scope of the embodiments of the present application.

[0139] It should also be understood that the various implementation methods described in this specification can be implemented individually or in combination, and the embodiments of the present application are not limited to this.

[0140] Unless otherwise stated, all technical and scientific terms used in the embodiments of the present application are the same as the meanings generally understood by those skilled in the art of the technical field of the present application. The terms used in the present application are only for the purpose of describing specific embodiments and are not intended to limit the scope of the present application. The singular forms "a kind of", "above" and "the" used in the embodiments of the present application and the appended claims are also intended to include majority forms, unless the context clearly indicates other meanings. In addition, the terms "first", "second" etc. are only used for description purposes and cannot be interpreted as indicating or suggesting relative importance.

[0141] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0142] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0143] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0144] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0145] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A test case generation method, characterized in that: include: Acquire training data, wherein the training data includes a plurality of xml files, each of the plurality of xml files includes a plurality of user interface UI elements, attributes of the plurality of UI elements, and test operations corresponding to the attributes of the plurality of UI elements; Training a test case model based on the training data; Obtain a first XML file of a first Android application in a first interface; Inputting the first xml file into the test case model to determine a first test operation corresponding to a first UI element in the first xml file; Based on the first test operation, a test case corresponding to the first Android application is generated.

2. The test case generation method according to claim 1, characterized in that: The test case generation method also includes: Execute the first test operation to obtain a second XML file of the first Android application in the second interface; The second xml file is input into the test case model to generate a second test operation corresponding to the second UI element in the second xml file.

3. The test case generation method according to claim 2, characterized in that: The generating, based on the first test operation, a test case corresponding to the first Android application includes: generating a first test code based on the first test operation; generating a second test code based on the second test operation; Integrate the first test code and the second test code in sequence to generate a test case corresponding to the first Android application.

4. The test case generation method according to claim 1, characterized in that: Inputting the first xml file into the test case model to determine a first test operation corresponding to a first UI element in the first xml file includes: The test case model parses the first XML file to generate a UI element tree, wherein the nodes in the UI element tree include the first UI element; Traversing the UI element tree to identify the first UI element; Based on the first UI element, a first test operation corresponding to the first UI element is determined.

5. The test case generation method according to claim 4, characterized in that: The identifying the first UI element includes: Each node in the UI element tree is traversed to determine the attribute of the first UI element.

6. The test case generation method according to claim 5, characterized in that: The determining, based on the first UI element, a first test operation corresponding to the first UI element includes: Determine, based on the attribute of the first UI element, a test operation corresponding to the first UI element; Based on the test operation corresponding to the first UI element, the first test operation corresponding to the first UI element is determined.

7. The test case generation method according to any one of claims 1 to 6, characterized in that: The obtaining of the first XML file of the first Android application in the first interface includes: Connecting the first Android application to the computer via the Android Debug Bridge ADB tool; Obtaining, by means of a first command in the ADB tool, a layout of a plurality of UI elements of the first Android application in the first interface; The layout of the multiple UI elements in the first interface is saved as the first xml file, and the first xml file is transferred to the computer, wherein the multiple UI elements in the first interface include the first UI element.

8. The test case generation method according to claim 7, characterized in that: Connect the first Android application to the computer through the Android Debug Bridge ADB tool, including: A device list is obtained through a second command in the ADB tool, wherein the device list includes one or more Android devices, wherein the one or more Android devices include a first Android device corresponding to the first Android application, and the first Android device is selected to connect to the computer.

9. The test case generation method according to any one of claims 1 to 6, characterized in that: The test case model is deployed on a cloud server or a computer.

10. A test case generating device, characterized in that: The test case generation device includes an acquisition module, a training module, a determination module and a generation module. The acquisition module is used to acquire training data, wherein the training data includes a plurality of XML files, each of the plurality of XML files includes a plurality of user interface UI elements, attributes of the plurality of UI elements, and test operations corresponding to the attributes of the plurality of UI elements; The training module is used to train the test case model according to the training data; The acquisition module is further used to acquire a first XML file of the first Android application in the first interface; The determining module is used to input the first xml file into the test case model to determine a first test operation corresponding to a first UI element in the first xml file; The generating module is used to generate a test case corresponding to the first Android application based on the first test operation.

11. A test case generating device, characterized in that: The test case generating device comprises: a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute: the test case generating method according to any one of claims 1 to 9.

Citation Information

Cited By

  • Test method and device, computer equipment and computer readable storage medium

    CN116049009A

  • Test method, device, computer equipment and computer readable storage medium

    CN116049009B