Test case generation method, generation device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202111240955.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-25
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2041-10-25
AI Technical Summary
[0003]本申请实施例的目的是提供一种测试用例生成方法、测试用例生成装置、电子设备和可读存储介质,能够解决相关技术中生成测试用例失败的问题
[0015]在本申请实施例中,将测试模块的第二类加载器的加载逻辑与第一类加载器的原有加载逻辑进行融合,生成第三类加载器,从而实现在目标工具中注入测试模块提供的预设类型的代码的测试环境。进而利用该第三类加载器,生成用于测试预设类型的应用的测试用例。通过上述方式,实现将测试模块提供的预设类型的代码的测试环境,注入到目标工具中,使得目标工具中具有预设类型的代码的测试环境,从而能够利用目标工具正确地生成预设类型的测试用例。
Smart Images

Figure CN116028330B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of testing technology, specifically relating to a test case generation method, a test case generation device, an electronic device, and a readable storage medium. Background Technology
[0002] Test case generation tools can generate test cases, enabling application testing. During test case generation, the generated code needs dynamic analysis to obtain coverage information during execution, facilitating subsequent evaluation and code searching. However, because test case generation tools lack the application environment for certain types of code, dynamic analysis fails directly on these types of code, preventing the successful generation of test cases. Summary of the Invention
[0003] The purpose of this application is to provide a test case generation method, test case generation device, electronic device, and readable storage medium, which can solve the problem of test case generation failure in related technologies.
[0004] In a first aspect, embodiments of this application provide a test case generation method, the method comprising:
[0005] Obtain the first type of loader for the target tool and the second type of loader for the test module, where the target tool is used to generate test cases and the test module is used to test applications of a preset type;
[0006] Generate a third type of loader based on the first and second type of loaders;
[0007] Using the third type of loader, test cases are generated for testing applications of a preset type.
[0008] Secondly, embodiments of this application provide a test case generation apparatus, the apparatus comprising:
[0009] The acquisition module is used to acquire the first type of loader for the target tool and the second type of loader for the test module. The target tool is used to generate test cases, and the test module is used to test applications of a preset type.
[0010] The first generation module is used to generate a third type of loader based on the first type of loader and the second type of loader;
[0011] The second generation module is used to generate test cases for testing applications of a preset type using the third type of loader.
[0012] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method as described in the first aspect.
[0013] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, and when the program or instructions are executed by a processor, they implement the steps of the method as described in the first aspect.
[0014] Fifthly, embodiments of this application provide a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the method as described in the first aspect.
[0015] In this embodiment, the loading logic of the second type of loader in the test module is merged with the original loading logic of the first type of loader to generate a third type of loader. This allows for the injection of a test environment containing pre-defined code provided by the test module into the target tool. The third type of loader is then used to generate test cases for testing applications of the pre-defined type. Through this method, a test environment containing pre-defined code provided by the test module is injected into the target tool, enabling the target tool to correctly generate test cases of the pre-defined type. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating the test case generation method according to an embodiment of this application;
[0017] Figure 2 This is a flowchart illustrating the dynamic analysis process in an embodiment of this application;
[0018] Figure 3 This is a schematic block diagram of a test case generation device according to an embodiment of this application;
[0019] Figure 4 This is one of the schematic block diagrams of the electronic device according to an embodiment of this application;
[0020] Figure 5 This is a second schematic block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0022] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0023] The test case generation method, test case generation device, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0024] This application provides a test case generation method, such as... Figure 1 As shown, the method includes:
[0025] Step 102: Obtain the first type of loader for the target tool and the second type of loader for the test module, wherein the target tool is used to generate test cases and the test module is used to test applications of a preset type;
[0026] Step 104: Generate a third type of loader based on the first and second type of loaders;
[0027] Step 106: Use the third type of loader to generate test cases for testing applications of the preset type.
[0028] The target tool is a tool capable of generating test cases, which requires dynamic analysis of the generated code during the test case generation process. To avoid the target tool failing to generate test cases for preset application types, this embodiment proposes injecting the test environment provided by the test module into the target tool. However, simply replacing the second type of loader in the test module with the first type of loader in the target tool will lead to a series of problems. For example, the first type of loader provided by the target tool contains a lot of instrumentation logic from the target tool, which is crucial for subsequent test case generation and coverage recording. Therefore, it is necessary to retain the logic of the first type of loader while adding the second type of loader.
[0029] Specifically, the loading logic of the second type of loader in the test module is merged with the original loading logic of the first type of loader to generate a third type of loader, thereby realizing a test environment that injects the pre-defined type of code provided by the test module into the target tool. Then, this third type of loader is used to generate test cases for testing applications of the pre-defined type.
[0030] By using the above method, the test environment of the preset type of code provided by the test module is injected into the target tool, so that the target tool has the test environment of the preset type of code, thereby enabling the target tool to correctly generate test cases of the preset type.
[0031] The target tool mentioned above is Evosuite, the first type of loader is InstrumentClassLoader, the test module mentioned above is Robolectric, and the second type of loader is SandboxClassLoader, with the default type being Android. Evosuite is a Java test case generation tool whose generated test cases can be run directly in JUnit. Robolectric is an Android test module based on the Java Virtual Machine (JVM), which can execute Android tasks directly in the JVM environment without an Android emulator. Specifically, Robolectric simulates the interface files of the Android Software Development Kit (SDK), allowing tests to run directly on the JVM.
[0032] This application embodiment enables the initialization of the Android testing environment and the acquisition of Robolectric's SandboxClassLoader class loader within the Evosuite tool. Furthermore, within Evosuite's InstrumentClassLoader class loader, reflection is used to merge the loading logic of the SandboxClassLoader class loader with the original loading logic of the InstrumentClassLoader class loader.
[0033] The InstrumentClassLoader class loader has two key objects: classloader and BytecodeInstrumentation. The classloader loads the class file into memory. After loading, it passes it to BytecodeInstrumentation, where ASM is used for instrumentation. Specifically, the classloader first calls the findLoadedClass method to check if the class has been loaded. If so, it returns directly. If not, it calls the loaderclass method to load the class. After loading, it obtains the class's bytecode file, then uses BytecodeInstrumentation for instrumentation, and finally returns the loaded class.
[0034] The fusion method involves replacing the original classloader object of the InstrumentClassLoader with Robolectric's classloader (i.e., Rclassloader). Then, using Java reflection, the previously called findLoadedClass and loaderclass methods are reflected back to Rclassloader for execution. This method achieves the fusion of the two class loaders, generating a third class loader. Ultimately, packages and classes will be loaded and defined within this third class loader.
[0035] Furthermore, in one embodiment of this application, before the step of generating test cases for testing applications of a preset type using a third type of loader, the method further includes: setting an instrumentation function for the third type of loader.
[0036] In this embodiment, instrumentation logic is applied to subsequent use case generation, coverage recording, etc. Therefore, instrumentation functionality is set for the third type of loader, so that the third type of loader can instrument other classes (such as class files) to ensure the subsequent use case generation, coverage recording, etc.
[0037] ASM is a Java bytecode manipulation module that can modify existing classes or dynamically generate classes in binary form. ASM can directly generate binary class files or dynamically change class behavior before the class is loaded into the JVM. In this embodiment, ASM is used for bytecode manipulation within the instrumentation logic of Evosuite and Robolectric.
[0038] Furthermore, in one embodiment of this application, before the step of obtaining the second type loader of the test module, the method further includes: setting a first preset class, wherein the initial value of the first preset class is empty; and setting resource path information for obtaining the second type loader of the test module in the first preset class.
[0039] In this embodiment, the call logic for initializing the SandboxClassLoader class loader in Robolectric is used to expose the required SandboxClassLoader class loader. Specifically, a public method is added for Evosuite to call, which initializes the resource path and obtains the SandboxClassLoader class loader.
[0040] Specifically, the method for initializing the resource path is as follows: the setProperty method of the buildSystemApiProperties property object of Robolectric is called to set the "android_merged_manifest", "android_merged_resources", "android_merged_assets", "android_resource_apk" and "android_custom_package" properties respectively.
[0041] The method to obtain the SandboxClassLoader class loader is as follows: By passing in a "FrameworkMethod object", the `getSandbox` method of Robolectric is called, which returns the SandboxClassLoader class loader. Furthermore, to obtain the "FrameworkMethod object", a public method is also exposed, which returns a FrameworkMethod object named "initedFrameworkMethod" from Robolectric.
[0042] Furthermore, in Evosuite, a predefined test class (i.e., the first preset class) with empty test content is used for execution via RobolectricTestRunner. The Android test environment is initialized within this test class. Specifically, this test class is passed to the constructor of RobolectricTestRunner to obtain a runner object. This runner object calls the aforementioned resource path initialization method to initialize the environment and obtain the SandboxClassLoader class loader.
[0043] At this point, the exposed SandboxClassLoader class loader is called again to set the SDK version, resource path, etc.
[0044] By using the above method, Robolectric is initialized at the appropriate time, ensuring that the Android testing environment is loaded before Evosuite is called. Some environment-related parameters, such as SDK version and resource paths, can also be dynamically configured.
[0045] Furthermore, in one embodiment of this application, the method further includes: setting a second preset class; and storing a second class loader in the second preset class.
[0046] In this embodiment, a singleton (i.e., the second preset class) is defined in Evosuite. This singleton class manages the SandboxClassLoader class loader and the corresponding Robolectric resources. For example, the process of initializing the Robolectric environment using the test class executed by RobolectricTestRunner is managed and invoked within the RobolectricManager singleton class.
[0047] By using the above method, the SandboxClassLoader obtained in Evosuite is unique, thus avoiding duplicate loading of classes.
[0048] Furthermore, in one embodiment of this application, the method further includes: determining whether the class to be loaded is a tracking management class through a second type of loader; if the class to be loaded is a tracking management class, loading the class to be loaded through a fourth type of loader.
[0049] When Evosuite's InstrumentClassLoader loads the code, it performs Trace instrumentation. After the modifications to the InstrumentClassLoader, it now contains both Trace instrumentation logic and Robolectric's Shadow logic. While the code does indeed record Trace execution logic, the retrieved Trace results are empty when summarizing and saving them. This is because the Trace management class (i.e., the tracing management class) is loaded simultaneously by both the system's AppClassLoader and Robolectric's SandboxClassLoader. As a result, two TraceManager.class instances exist in memory, with runtime recording and final storage occurring in separate classes.
[0050] This application proposes a mechanism to prevent trace loss. Specifically, in the Roboletric code, the class loading logic of the SandboxClassLoader is modified to determine if a class is related to trace management. If so, the class is loaded by the system's AppClassLoader (i.e., the fourth type of loader). Specifically, the class name is checked before class loading; if it is related to trace management, the class is loaded by the AppClassLoader during the loadClass() process, thereby preventing trace loss.
[0051] Furthermore, in one embodiment of this application, the method further includes: using the main thread to dynamically analyze the test cases.
[0052] Due to Android's characteristics, View-related operations can only be performed on the Android main thread. However, when Evosuite performs dynamic analysis, to avoid the running code thread affecting the tool's main thread, the dynamic analysis is often performed in a background thread. Therefore, it is necessary to switch the execution thread to the Android main thread when Evosuite is dynamically analyzing the running code.
[0053] In this embodiment, a mechanism is proposed to ensure that Android-related code runs in the main thread. Specifically, by modifying the source code of Robolectric, the dynamic analysis is switched to be executed in the Android main thread, and the method is exposed to Evosuite calls so that the Android-related code can be executed smoothly.
[0054] In one specific embodiment of this application, after injecting the Android testing environment provided by Robolectric into Evosuite, the dynamic analysis process of Evosuite is as follows: Figure 2 As shown, it includes:
[0055] Step 202, RobolectricManager initialization;
[0056] Step 204, CaseExecutor is created;
[0057] Step 206: InstrumentClassLoader integrates SandboxClassLoader;
[0058] Step 208: Replace the Executor class loader with the InstrumentClassLoader;
[0059] Step 210: Switch the Android main thread;
[0060] Step 212: Execute the generated code;
[0061] Step 214: Restore the Executor class loader.
[0062] The above method allows the Android testing environment provided by Robolectric to be injected into Evosuite, thus enabling Evosuite to have an Android testing environment and generate Android test code correctly.
[0063] It should be noted that the test case generation method provided in this application embodiment can be executed by a test case generation device, or by a control module within the test case generation device for executing the test case generation method. This application embodiment uses the execution of the test case generation method by a test case generation device as an example to illustrate the test case generation device provided in this application embodiment.
[0064] This application provides a test case generation device, such as... Figure 3 As shown, the test case generation device 300 includes:
[0065] The acquisition module 302 is used to acquire the first type of loader for the target tool and the second type of loader for the test module, wherein the target tool is used to generate test cases and the test module is used to test applications of a preset type.
[0066] The first generation module 304 is used to generate a third type of loader based on the first type of loader and the second type of loader;
[0067] The second generation module 306 is used to generate test cases for testing applications of a preset type using a third type of loader.
[0068] In this embodiment, the loading logic of the second type of loader in the test module is merged with the original loading logic of the first type of loader to generate a third type of loader. This allows for the injection of a test environment containing pre-defined code provided by the test module into the target tool. The third type of loader is then used to generate test cases for testing applications of the pre-defined type. Through this method, a test environment containing pre-defined code provided by the test module is injected into the target tool, enabling the target tool to correctly generate test cases of the pre-defined type.
[0069] Furthermore, in one embodiment of this application, the target tool is the Evosuite tool; the test module is the Robolectric test module.
[0070] Furthermore, in one embodiment of this application, the test case generation device 300 further includes a processing module for setting instrumentation functionality for the third type of loader.
[0071] Furthermore, in one embodiment of this application, the test case generation device 300 further includes: a first setting module, used to set a first preset class, and in the first preset class, set resource path information of the second type loader for obtaining the test module, wherein the initial value of the first preset class is empty.
[0072] Furthermore, in one embodiment of this application, the test case generation device 300 further includes: a second setting module, used to set a second preset class and store a second class loader in the second preset class.
[0073] Furthermore, in one embodiment of this application, the test case generation device 300 further includes: a judgment module, used to determine whether the class to be loaded is a tracking management class through a second type of loader; and a loading module, used to load the class to be loaded through a fourth type of loader if the class to be loaded is a tracking management class.
[0074] Furthermore, in one embodiment of this application, the test case generation device 300 further includes an analysis module, used to dynamically analyze the test cases using the main thread.
[0075] The test case generation device 300 in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0076] The test case generation device 300 in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.
[0077] The test case generation device 300 provided in this application embodiment can achieve... Figure 1 and Figure 2 The various processes implemented in the method embodiments are not described in detail here to avoid repetition.
[0078] Optional, such as Figure 4 As shown, this application embodiment also provides an electronic device 400, including a processor 402, a memory 404, and a program or instructions stored in the memory 404 and executable on the processor 402. When the program or instructions are executed by the processor 402, they implement the various processes of the above-described test case generation method embodiment and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0079] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0080] Figure 5 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0081] The electronic device 500 includes, but is not limited to, components such as: radio frequency unit 502, network module 504, audio output unit 506, input unit 508, sensor 510, display unit 512, user input unit 514, interface unit 516, memory 518, and processor 520.
[0082] Those skilled in the art will understand that the electronic device 500 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 520 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 5 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0083] The processor 520 is used to: obtain a first type loader for the target tool and a second type loader for the test module, wherein the target tool is used to generate test cases and the test module is used to test applications of a preset type; generate a third type loader based on the first type loader and the second type loader; and use the third type loader to generate test cases for testing applications of a preset type.
[0084] In this embodiment, the loading logic of the second type of loader in the test module is merged with the original loading logic of the first type of loader to generate a third type of loader. This allows for the injection of a test environment containing pre-defined code provided by the test module into the target tool. The third type of loader is then used to generate test cases for testing applications of the pre-defined type. Through this method, a test environment containing pre-defined code provided by the test module is injected into the target tool, enabling the target tool to correctly generate test cases of the pre-defined type.
[0085] Furthermore, in one embodiment of this application, the target tool is the Evosuite tool; the test module is the Robolectric test module.
[0086] Furthermore, in one embodiment of this application, the processor 520 is also configured to set a first preset class, and in the first preset class, set resource path information of the second type loader for obtaining the test module, wherein the initial value of the first preset class is empty.
[0087] Furthermore, in one embodiment of this application, the processor 520 is also configured to set a second preset class and store a second class loader in the second preset class.
[0088] Furthermore, in one embodiment of this application, the processor 520 is also configured to determine whether the class to be loaded is a tracking management class through a second type of loader, and if the class to be loaded is a tracking management class, load the class to be loaded through a fourth type of loader.
[0089] Furthermore, in one embodiment of this application, the processor 520 is also used to dynamically analyze test cases using the main thread.
[0090] It should be understood that, in this embodiment, the radio frequency unit 502 can be used to send and receive information or signals during a call; specifically, it can receive downlink data from the base station or send uplink data to the base station. The radio frequency unit 502 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier, a duplexer, etc.
[0091] Network module 504 provides users with wireless broadband internet access, such as helping users send and receive emails, browse web pages, and access streaming media.
[0092] The audio output unit 506 can convert audio data received by the radio frequency unit 502 or the network module 504 or stored in the memory 518 into audio signals and output them as sound. Furthermore, the audio output unit 506 can also provide audio output related to specific functions performed by the electronic device 500 (e.g., call signal reception sound, message reception sound, etc.). The audio output unit 506 includes a speaker, a buzzer, and a receiver, etc.
[0093] Input unit 508 is used to receive audio or video signals. Input unit 508 may include a graphics processing unit (GPU) 5082 and a microphone 5084. GPU 5082 processes image data of still images or videos acquired by an image capture device (such as a camera) in video capture mode or image capture mode. The processed image frames may be displayed on display unit 512, stored in memory 518 (or other storage medium), or transmitted via radio frequency unit 502 or network module 504. Microphone 5084 can receive sound and process the sound into audio data. The processed audio data can be converted into a format that can be transmitted to a mobile communication base station via radio frequency unit 502 in telephone call mode.
[0094] The electronic device 500 also includes at least one sensor 510, such as a fingerprint sensor, pressure sensor, iris sensor, molecular sensor, gyroscope, barometer, hygrometer, thermometer, infrared sensor, light sensor, motion sensor, and other sensors.
[0095] The display unit 512 is used to display information input by the user or information provided to the user. The display unit 512 may include a display panel 5122, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like.
[0096] User input unit 514 can be used to receive input numeric or character information, and generate key signal inputs related to user settings and function control of electronic devices. Specifically, user input unit 514 includes touch panel 5142 and other input devices 5144. Touch panel 5142, also known as touch screen, can collect touch operations by the user on or near it. Touch panel 5142 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 520, which receives commands from the processor 520 and executes them. Other input devices 5144 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.
[0097] Furthermore, the touch panel 5142 can cover the display panel 5122. When the touch panel 5142 detects a touch operation on or near it, it transmits the information to the processor 520 to determine the type of touch event. Subsequently, the processor 520 provides corresponding visual output on the display panel 5122 according to the type of touch event. The touch panel 5142 and the display panel 5122 can be two independent components or integrated into one component.
[0098] Interface unit 516 serves as an interface for connecting external devices to electronic device 500. For example, external devices may include a wired or wireless headphone port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, and so on. Interface unit 516 can be used to receive input from external devices (e.g., data, power, etc.) and transmit the received input to one or more components within electronic device 500, or it can be used to transmit data between electronic device 500 and external devices.
[0099] The memory 518 can be used to store software programs and various data. The memory 518 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback, image playback, etc.), etc.; the data storage area may store data created based on the use of the mobile terminal (such as audio data, phonebook, etc.). Furthermore, the memory 518 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0100] The processor 520 performs various functions and processes data of the electronic device 500 by running or executing software programs and / or modules stored in the memory 518 and calling data stored in the memory 518, thereby providing overall monitoring of the electronic device 500. The processor 520 may include one or more processing units; preferably, the processor 520 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication.
[0101] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described test case generation method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0102] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0103] This application also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described test case generation method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0104] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0105] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0106] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0107] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A test case generation method, characterized in that, include: Obtain a first-type loader for the target tool and a second-type loader for the test module, wherein the target tool is used to generate test cases and the test module is used to test applications of a preset type; A third type of loader is generated by fusing the first type of loader with the second type of loader, including: The original class loader object of the first class loader is replaced with the class loader object of the second class loader in the test module; and The invoked class loading check method and class loading execution method are reflected back to the replaced class loader object in the first class loader to generate the third class loader; Based on the bytecode instrumentation object of the first type of loader, instrumentation functionality is set for the third type of loader; and Using the third type of loader, test cases are generated for testing the preset type of application.
2. The test case generation method according to claim 1, characterized in that, The target tool is Evosuite. The test module is the Robolectric test module.
3. The test case generation method according to claim 1, characterized in that, Prior to the step of obtaining the second type loader of the test module, the following is also included: Set a first preset class, wherein the initial value of the first preset class is empty; In the first preset class, the resource path information of the second type loader of the test module is obtained.
4. The test case generation method according to claim 1, characterized in that, Also includes: Set a second preset class; Store the second type of loader into the second preset class.
5. The test case generation method according to any one of claims 1 to 4, characterized in that, Also includes: The second type of loader is used to determine whether the class to be loaded is a tracking and management class; If the class to be loaded is the tracking management class, the class to be loaded is loaded using the fourth type loader.
6. The test case generation method according to any one of claims 1 to 4, characterized in that, Also includes: The test cases are dynamically analyzed using the main thread.
7. A test case generation device, characterized in that, include: The acquisition module is used to acquire the first type of loader for the target tool and the second type of loader for the test module, wherein the target tool is used to generate test cases and the test module is used to test applications of a preset type. A first generation module is used to generate a third type of loader by fusing the first type of loader with the second type of loader, including: The original class loader object of the first class loader is replaced with the class loader object of the second class loader in the test module; and The invoked class loading check method and class loading execution method are reflected back to the replaced class loader object in the first class loader to generate the third class loader; The processing module is used to set instrumentation functions for the third type of loader based on the bytecode instrumentation object of the first type of loader; and the second generation module is used to generate test cases for testing the preset type of application using the third type of loader.
8. The test case generation device according to claim 7, characterized in that, The target tool is Evosuite. The test module is the Robolectric test module.
9. The test case generation device according to claim 7, characterized in that, Also includes: A first setting module is used to set a first preset class, and in the first preset class, to set the resource path information of the second type loader of the test module, wherein the initial value of the first preset class is empty.
10. The test case generation device according to claim 7, characterized in that, Also includes: The second setting module is used to set the second preset class and store the second class loader in the second preset class.
11. The test case generation apparatus according to any one of claims 7 to 10, characterized in that, Also includes: The judgment module is used to determine whether the class to be loaded is a tracking and management class through the second type of loader; The loading module is used to load the class to be loaded by a fourth type of loader when the class to be loaded is the tracking management class.
12. The test case generation apparatus according to any one of claims 7 to 10, characterized in that, Also includes: The analysis module is used to dynamically analyze the test cases using the main thread.
13. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the test case generation method as described in any one of claims 1 to 6.
14. A readable storage medium having a program or instructions stored thereon, characterized in that, When the program or instructions are executed by the processor, they implement the steps of the test case generation method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Application program testing method and device
CN102799515A