Test optimization method and device, equipment and medium

By receiving object call instructions in the test iteration stage of unit tests, obtaining the rewritten object according to the type of the target object or creating an object based on the component library or object template, the problem of incompatibility of the test environment and the iteration process is solved, and the normal operation and optimization of application tests are achieved.

CN119557199APending Publication Date: 2025-03-04BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311103880.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-29
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

In a test environment where the Robolectric test module is injected into the Evosuite tool, the iterative process of the test is partially incompatible with the test environment, resulting in the test failure or lockdown.

Method used

During the test iteration phase of unit tests, the object call instruction is received. If the target object is an iterative association object, the overridden target object is obtained and the call is executed; otherwise, the target object is created and the call is executed based on the preset component library or object template library.

Benefits of technology

By intercepting object call instructions during the iteration stage, and generating objects or calling rewrite objects based on custom component libraries or object templates, compatibility with the test environment is achieved, ensuring that some incompatible objects can participate in iteration normally, so that the iteration process can run normally, and the application testing process is optimized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119557199A_ABST
    Figure CN119557199A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a test optimization method and device, equipment and a medium, and the method comprises the steps: receiving an object calling instruction in a test iteration stage of carrying out unit test on an application program; if the target object of the object calling instruction belongs to the iteration association object, obtaining the rewritten target object and executing calling; and otherwise, creating the target object based on a preset component library or an object template library, and executing calling. By adopting the technical scheme, the calling instruction is intercepted in the test iteration stage of the unit test, and the object is generated or the rewritten object is called based on the self-defined component library or the object template, so that the compatibility with the test environment is realized, and part of incompatible objects can normally participate in iteration, and further, the iteration process can be normally operated, and the test efficiency is improved. And the test process of the application program is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of testing technology, and in particular to a testing optimization method, device, equipment and medium. Background Art

[0002] In the related art, in order to test an application, the test environment can be injected into the Evosuite tool using the Robolectric test module, so that the Evosuite tool has the test environment, and the Evosuite tool can be used to generate test cases for testing. The test environment can be, for example, an Android environment. However, the test environment injected by the Robolectric test module may be partially incompatible with the test environment during the test iteration process, which affects the test. Summary of the invention

[0003] In order to solve the above technical problems, the present disclosure provides a test optimization method, device, equipment and medium.

[0004] The present disclosure provides a test optimization method, the method comprising:

[0005] During the test iteration phase of unit testing the application, an object call instruction is received;

[0006] If the target object of the object call instruction belongs to the iteration-related object, the rewritten target object is obtained and the call is executed;

[0007] Otherwise, the target object is created based on a preset component library or object template library and the call is executed.

[0008] The present disclosure also provides a test optimization device, the device comprising:

[0009] A receiving module, used for receiving an object calling instruction during a test iteration phase of unit testing an application program;

[0010] An acquisition calling module, used for acquiring the rewritten target object and executing the call if the target object of the object calling instruction belongs to the iteration associated object;

[0011] A call module is created, which is used to create the target object and execute the call based on a preset component library or object template library.

[0012] An embodiment of the present disclosure also provides an electronic device, which includes: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the test optimization method provided in the embodiment of the present disclosure.

[0013] The embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the test optimization method provided by the embodiment of the present disclosure.

[0014] The technical solution provided by the embodiment of the present disclosure has the following advantages over the prior art: the test optimization solution provided by the embodiment of the present disclosure receives an object call instruction during the test iteration phase of unit testing of an application; if the target object of the object call instruction belongs to an iteration-associated object, the rewritten target object is obtained and the call is executed; otherwise, the target object is created and the call is executed based on a preset component library or object template library. Using the above technical solution, during the test iteration phase of unit testing of an application, if the target object currently called belongs to an iteration management object, the rewritten target object is directly called; otherwise, the target object can be created and called based on a preset component library or object template. By intercepting the call instruction during the iteration phase, and generating an object or calling the rewritten object based on a custom component library or object template, compatibility with the test environment is achieved, ensuring that some incompatible objects can participate in the iteration normally, thereby enabling the iteration process to run normally and optimizing the application testing process. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0016] Figure 1 A flow chart of a test optimization method provided by an embodiment of the present disclosure;

[0017] Figure 2 A schematic diagram of creating an object provided by an embodiment of the present disclosure;

[0018] Figure 3 A schematic diagram of the structure of a test optimization device provided in an embodiment of the present disclosure;

[0019] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0020] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0021] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0022] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0023] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0024] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0025] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0026] In the related art, when the Robolectric test module is injected into the test environment of the Evosuite tool for testing, the following problems exist: some components in the test environment are based on specific application program interface calls or generation and cannot be generated directly. For example, the global application (Application) object is created using new Application(), which is inconsistent with a single environment; the transfer (Parcel) object is created using new Parcel(), and the object creation is obtained from the object pool using the obtain function. The initialization of these two objects is based on iteration, which is too random and cannot be implemented; during the test process, when calling the system method, it can be implemented by calling the system method recorded in the shadow component (for example, obtaining the system version number, obtaining the power, obtaining the Android service, etc.), but the implementation of the iteration stage may be partially incompatible with the shadow component, which may cause the test to lock or time out, causing the test to fail. In summary, due to the partial incompatibility between the iterative process of the test and the test environment, it may affect the test.

[0027] In order to solve the above problems, the embodiments of the present disclosure provide a test optimization method, which is introduced below in conjunction with specific embodiments.

[0028] Figure 1 The present invention provides a flow chart of a test optimization method provided by an embodiment of the present invention. The method can be executed by a test optimization device, wherein the device can be implemented by software and / or hardware and can generally be integrated in an electronic device. Figure 1 As shown, the method includes:

[0029] Step 101: During the test iteration phase of unit testing an application program, an object call instruction is received.

[0030] Among them, the application program can be an application program to be unit tested, for example, the application program can be a video application program, a reading application program, etc., without specific limitation. This embodiment has different restrictions on the operating system where the application program is located, for example, the operating system where the application program is located can be an Android operating system. Unit testing is also called single testing, and the unit testing can be an application program test based on a method as the basic unit. The unit test can generate corresponding test code for each method included in each class to be tested, so as to implement the test of each method through the test code, that is, each method is regarded as a basic unit to be tested, and the application program is tested by means of unit testing.

[0031] The test iteration phase may be a phase in the unit test, and the test iteration phase may be a phase for iterative testing of the application. The object call instruction may be an instruction for instructing to call a specific object. When the specific object does not exist, the object may be created first and then called, that is, the object call instruction may include an object creation instruction.

[0032] In the disclosed embodiment, after the code corresponding to the application is modified, or before the application is launched, a unit test of the application can be initiated, and the test can be performed in the test environment of the Evosuite tool injected by the Robolectric test module. The unit test process includes a test iteration phase. In the test iteration phase, when an object call instruction is detected, the object call instruction can be intercepted.

[0033] Step 102 , determine whether the target object of the object call instruction belongs to an iteration-associated object, if so, execute step 103 ; otherwise, execute step 104 .

[0034] The target object may be a specific object that the object call instruction needs to call. The iteration-associated object may be a partial object in the test environment that is incompatible with the iteration phase. In the embodiment of the present disclosure, the iteration-associated object may be rewritten in advance according to the incompatible part, and the iteration-associated object may include multiple types. Rewriting may be a process of modifying a partial implementation or attribute of an object to be compatible with the test environment.

[0035] The rewritten target object is a target object that is logically compatible with the test environment, that is, running the rewritten target object in the test iteration phase will not cause abnormal phenomena such as freezing or locking of the Android environment.

[0036] In the disclosed embodiment, the test optimization device may rewrite some objects in advance, and the rewritten parts of the objects are iteration-related objects. After the test optimization device receives the object call instruction, it parses the object call instruction and determines the target object called by the object call instruction. Further, it is determined whether the target object belongs to the iteration-related object, that is, whether the target object exists in the iteration-related object. If the target object belongs to the iteration-related object, step 103 is executed.

[0037] In an optional implementation, the iteration-related object includes at least one of the following: a key-value pair storage object, a process object, a lifecycle callback object, and a broadcast callback object.

[0038] The key-value pair storage object is the SharedPrefrences object in the Robolectric test module. Based on the key-value pair storage object, the value before the application is closed can be retained, so that after the application is opened again, the value in the application when it was last closed can be restored.

[0039] For the key-value storage object before the rewrite, the data processing of the key-value storage object before the rewrite is implemented on the disk, and a deadlock problem will occur during the iteration process. As a result, each code statement that calls the key-value storage object before the rewrite will have a timeout error, and the execution of the real input / output operation will fail.

[0040] Specifically, in the rewritten key-value pair storage object, the implementation of the custom class of file storage is simulated by a map, and the class here may include SharedPrefrencesImp and EditorImpl. The data processing of the rewritten key-value pair storage object is based on memory implementation, and it can support iterative search based on key and value in the iteration phase.

[0041] The process object is a Process object. For the process object before rewriting, the start of the process object is not allowed in the test iteration phase. However, the operation of the process call function (exec) in the Android system is based on the communication with the process object, and the call of the process call function is not supported.

[0042] For the rewritten process object, a virtual runtime object (MockRuntime) and a virtual process object (MockProcess) are created through virtual object (Mock) technology, and the process call function in the virtual runtime object is rewritten. The rewritten process call function can communicate with the virtual process object. A plurality of candidate data may be pre-stored in the virtual process object, and the candidate data may include the data that the rewritten process call function needs to obtain. This embodiment does not limit the type of the candidate data. For example, the type of the candidate data may include device power and / or device model. This embodiment does not limit the data value of the candidate data. For example, the data value of the candidate data of the type of device power may include: 100% and / or 50%, etc.

[0043] In the case where a process object needs to be created, the virtual process object is created, and the virtual process object communicates with the rewritten process call function. After receiving the data acquisition request sent by the rewritten process call function, the virtual process object matches the candidate data in the virtual process object with the data acquisition request, determines the target data that successfully matches the data acquisition request, and sends the target data to the process call function through the communication channel between the virtual process object and the process call function. Thereby, the normal operation of the process call function is achieved. Optionally, the virtual process object can also provide an interface for switching data values ​​for the same type of candidate data, so that the data value of the candidate data acquired by the rewritten process call function each time is different.

[0044] For example, the device power and device model may be stored in the virtual process object, and the data acquisition request sent by the rewritten process call function may be a request to obtain the device power (getprop), and the target data returned by the virtual process object may be the device power.

[0045] The lifecycle callback object is the registerActivityLifecycleCallbacks object. The broadcast callback object is the registerReceiverCallbacks object.

[0046] For the above life cycle callback objects and broadcast callback objects before rewriting, they are triggered in the case of network abnormalities. In the test iteration phase, if the iterations under different network conditions are tested, it is necessary to wait for the external network connection to have problems. However, in some application scenarios, the probability of network connection problems is small, and the above life cycle callback objects and broadcast callback objects lack triggering opportunities.

[0047] For the above-mentioned rewritten lifecycle callback objects and broadcast callback objects, simulations of different network conditions can be provided to trigger the above-mentioned rewritten lifecycle callback objects and broadcast callback objects. Specifically, in order to simulate the situation where the network condition of the device is abnormal, the rewritten callback objects (including lifecycle callback objects and / or broadcast callback objects) can provide virtual network conditions through the network condition simulation interface, and then trigger different virtual network conditions when the rewritten callback objects are registered, and store the callback data of the rewritten callback objects corresponding to each virtual network condition, and record the test conditions of the callback objects under different virtual network conditions. Among them, the virtual network conditions include but are not limited to: virtual network disconnection and / or virtual network reconnection.

[0048] Thus, the triggering timing of the lifecycle callback object and the broadcast callback object is increased, and the testing of the lifecycle callback object and the broadcast callback object under different network conditions is realized.

[0049] In the above solution, different iteration-related objects are rewritten so that the rewritten iteration-related objects can be compatible with the test environment and thus run normally, and the overall running status is more consistent with the actual situation.

[0050] Step 103: Get the rewritten target object and execute the call.

[0051] If the test optimization device determines that the target object belongs to the iteration-associated object, it means that the target object has been rewritten in advance and the rewritten target object is compatible with the test environment. Then, the rewritten target object is obtained and called.

[0052] Step 104: Create a target object based on the preset component library and object template library and execute the call.

[0053] Among them, the component library can be a collection of pre-set custom objects. The object template library can be a collection of pre-set object templates, and the number of object templates can be multiple. The object template library includes multiple object templates, each object template is used to indicate the specific process of generating an object, that is, each object template records the specific steps of generating an object, so that the specific steps can be executed in sequence to obtain the corresponding object, and the object template can be the basis for constructing the object. Based on the object template, the standardized and fixed construction of the object can be realized, and the properties and method calls of the object can be initialized according to the object template. Through the object template, the specific generation process of the object is recorded, and the standardized generation of the object based on the object template is realized. And the object template can be adjusted according to the needs of the developer, so that the test optimization method can be adapted to more application scenarios. The custom objects in the above-mentioned component library and the objects built based on the object template are objects compatible with the Android environment, that is, running the object built based on the object template in the test iteration phase will not cause abnormal phenomena such as freezing and locking of the Android environment.

[0054] In the disclosed embodiment, if the target object of the object calling instruction does not belong to the iterative associated object, the target object therein can be reused according to a preset component library, or a target object can be created according to a preset object template library and called.

[0055] In some embodiments of the present disclosure, a target object is created based on a preset component library and object template library, including: if the component library includes a target object corresponding to an object call instruction, the target object is reused; otherwise, a match is performed in the object template library according to the target type corresponding to the target object, a matching target object template is determined, and the target object is created according to the target object template.

[0056] The type may be a parameter that characterizes the characteristics of an object. Each object template in the object template library has a corresponding type, that is, when objects of the same type are created, the object templates based on them are the same. The target type may be a parameter that characterizes the characteristics of the target object. The target object template may be an object template that matches the target type.

[0057] In this embodiment, a plurality of custom objects are pre-set in the component library, and it is determined whether the component library includes the target object corresponding to the object call instruction. If so, it means that the target object has been created, and no new target object is created, but the existing target object in the component library is reused, thereby avoiding the creation of a target object every time a call is made. If the component library does not include the target object corresponding to the object call instruction, the test optimization device can obtain the target type of the target object carried in the object call instruction, and match the target type in the object template library to determine a target object template that matches successfully. Furthermore, the target object is created based on the target object template, that is, the properties and method calls are initialized according to the target object template.

[0058] In the above scheme, by reusing the target objects that already exist in the component library, it is avoided to create a target object each time it is called, so that the number of target objects is 1, which is consistent with the number of target objects in the actual operation process, improves the accuracy of the iteration process, and realizes the rapid and standardized generation of objects according to the object template.

[0059] Figure 2 A schematic diagram of creating an object provided by an embodiment of the present disclosure, such as Figure 2 As shown, the creation process of the target object may include: creating an object (createObject) through a constructor (constructor). After the object is created, attributes (addField), methods (addMethod), and static methods (addMethodFor) may be created for the object. In order to implement the creation method or static method, getInPutParams may be executed. Creating attributes and getting parameters may be performed by using a template (useTemplet) to complete the initialization of the object. Specifically, in the process of using the template, the corresponding object template is determined in the object template library by selecting a template (chooseTemplet), or a reusable object is determined in the component library. Further, an object is created based on the object template selected in the object template library or an object is reused based on the component library (templeData), that is, an object is created or reused (createOrReuseObject). Afterwards, the object is initialized (initObject).

[0060] In the process of creating or reusing objects, there are multiple methods of creating or reusing objects, including creating based on return value type (callReturnTypeMethod), reusing existing objects (reuseObject), and creating objects (createObject). In particular, creating objects includes creating objects through constructors (constructor).

[0061] In some embodiments of the present disclosure, the component library includes at least one of a context object, a window container object, and a transfer object.

[0062] The context object is a custom Context object, which includes a global application object. When the target program runs normally, the number of running context objects is 1.

[0063] In this embodiment, when the Robolectric test module is initialized, a custom global application object is created. Through the custom global application object, it is avoided to create a new global application object each time the context object is called, so that the number of global application objects running is kept at 1, which is consistent with the actual situation. Among them, the global custom application object can be a static custom application object.

[0064] The window container object is a custom Activity object, and the window container object can be understood as an object that holds a window.

[0065] In this embodiment, a window container object is started through an interface in the Robolectric test module, and the window container object may include but is not limited to a text view (TextView) object, an edit view (EditView) object, a delayed task (Handler) object, and a window (Window) object. When a new window container object is subsequently created, the existing objects in the object pool may be reused first, and the object pool includes all the above-defined window container objects, and the object pool supports expansion. If the new window container object does not exist in the processing object pool, it is created, and the newly created window container object is added to the object pool for expansion.

[0066] In addition, in this embodiment, a target identifier is pre-set, and the target identifier records the window objects that can be run in the main thread of the Robolectric test module. A loop object (loop) can be run in the child thread. When the main thread of the Robolectric test module detects the above window object, the child thread running the loop object will also be detected at the same time. If the window identifier of the window object in the child thread running the loop object is consistent with the target identifier, the window object in the child thread passes the detection and the window object can run normally. Among them, the main thread of the Robolectric test module is also called the user interface (UI) thread.

[0067] In the related art, the test optimization device can bind the window object in the window container object to the main thread of the Robolectric test module before the window object can be tested. In this embodiment, the window object is bound to the main thread of the Robolectric test module through the bind (attach) function, so that the child thread can perform the operation of updating the user interface. And by setting a loop object in the child thread, the window object can pass the test, so that the tool class corresponding to the child thread can be used normally while the window object can pass the test.

[0068] The transfer object is a custom Parcel object. For the transfer object, when the transfer object is obtained through the obtain function, the transfer object is obtained from the above object pool instead of creating a new transfer object. Among them, the object pool is the object pool corresponding to the system.

[0069] In the above scheme, in the actual program running, by setting up the component library to customize some objects, these objects can be compatible with the test environment and support the call of the iteration phase, thereby ensuring that some incompatible objects can participate in the iteration normally.

[0070] The test optimization scheme provided by the embodiment of the present disclosure receives an object call instruction during the test iteration phase of unit testing of an application; if the target object of the object call instruction belongs to an iteration-associated object, the rewritten target object is obtained and the call is executed; otherwise, the target object is created and the call is executed based on a preset component library and object template library. Using the above technical scheme, during the test iteration phase of unit testing of an application, if the target object currently called belongs to an iteration management object, the rewritten target object is directly called; otherwise, the target object can be created and called based on a preset component library or object template. By intercepting the call instruction during the iteration phase, and generating an object or calling the rewritten object based on a custom component library or object template, compatibility with the test environment is achieved, ensuring that some incompatible objects can participate in the iteration normally, thereby enabling the iteration process to run normally, thereby optimizing the application testing process.

[0071] In some embodiments of the present disclosure, the test optimization method also includes: adding timeout logic in the main thread of the test module and canceling the thread check logic; blocking the iteration thread in the test iteration phase, and using the main thread to execute the iteration process, and using atomic variables to return the execution results to the iteration thread.

[0072] Among them, the test module is a Robolectric test module. The timeout logic can be a logic for determining whether the duration of a certain test process exceeds a duration threshold, and the duration threshold can be set according to demand, and this embodiment does not limit it. For example, the duration threshold can be 5 seconds. In the related art, the code can be bound to the thread, that is, the code needs to run in a specific thread, and the thread check logic can be a logic for determining whether the thread and the code running on the thread are bound. The iterative thread can be a thread for implementing iterative testing. The atomic variable can be a type of variable, and the atomic variable will not be dirty read due to simultaneous access by multiple threads.

[0073] In this embodiment, the test optimization device can cancel the thread check logic in the main thread of the Robolectric test module, so that the iterative code bound to the iterative thread can run in the main thread, realizing the reuse of the iterative thread and the main thread. And add timeout logic in the main thread, so that when the iterative code runs in the main thread for too long, the timeout exception can be discovered.

[0074] Furthermore, in the test iteration phase, the iteration thread is blocked, and the iteration code in the iteration process is executed in the main thread to implement the iteration process in the main thread. During the process of the main thread running the iteration code, if the running time exceeds the time threshold, an alarm is issued according to the timeout logic. After the iteration code is executed, the execution result is assigned to the atomic variable, and the atomic variable return value is iterated to the thread.

[0075] In the above solution, by changing the logic in the main thread of the Robolectric test module, the effect of implementing the iteration process in the main thread is achieved.

[0076] In some embodiments of the present disclosure, the test optimization method further includes: injecting the thread management object of the iteration thread into the main thread of the test module through an interface to merge the main thread and the iteration thread. The thread management object is a single thread pool SingleThreadExecutor.

[0077] In this embodiment, the main thread of the Robolectric test module can be pre-set with an interface, through which the thread management object of the iteration thread can be injected, thereby realizing the merger of the main thread and the iteration thread. After the merger of the main thread and the execution thread, the iteration code in the execution thread can be run on the main thread.

[0078] After the test environment is injected into the Evosuite tool through the Robolectric test module, the Evosuite tool that injects the test environment is the Evodroid tool. The above-mentioned iterative thread is the execution thread of the Evodroid tool. Optionally, before the main thread of the Robolectric test module injects the thread management object of the iterative thread through the interface, it can also include: adjusting the initialization process of the thread management object. Specifically, the class loader (classloader) of the iterative thread of the Evodroid tool is the custom class loader (sandboxcClassloader) of the Robolectric test module. When the custom class loader is initialized, the thread management object of the Robolectric test module will be initialized, and then the thread management object of the iterative thread injected into the main thread of the Robolectric test module through the interface will be executed.

[0079] In the above scheme, by merging the main thread and the iteration thread, the main thread can directly run the code of the iteration thread, thereby realizing the reuse of the iteration thread and the main thread without the need for other logical settings, thereby simplifying the implementation process of running the iteration code of the execution thread on the main thread.

[0080] The test optimization method provided by the embodiment of the present disclosure intercepts object generation and object calling during the test iteration phase to provide the ability to create objects based on custom object templates and call object interfaces. In addition, by establishing an object template library and a component library, objects that were originally incompatible in the iteration objects are made compatible, ensuring that some incompatible objects can participate in the iteration normally, thereby enabling the iteration process to run normally and optimizing the test process of the application. In addition, the iteration thread and the main thread are reused and unified, solving the problem of incompatibility between the iteration thread and the main thread in the related art. In summary, this solution solves the problem of partial incompatibility between the test iteration process and the test environment for the test environment injected by the Robolectric test module, optimizes the test process, and enables the Robolectric test module to play a better role in the iteration-based single test framework.

[0081] Figure 3 This is a schematic diagram of the structure of a test optimization device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated into an electronic device. Figure 3 As shown, the device comprises:

[0082] The receiving module 301 is used to receive an object calling instruction during a test iteration phase of unit testing an application program;

[0083] The acquisition calling module 302 is used for acquiring the rewritten target object and executing the call if the target object of the object calling instruction belongs to the iteration associated object;

[0084] The creation calling module 303 is used to create the target object based on a preset component library or object template library and execute the call.

[0085] In some embodiments of the present disclosure, the iteration-associated object includes at least one of the following: a key-value pair storage object, a process object, a lifecycle callback object, and a broadcast callback object.

[0086] In some embodiments of the present disclosure, a calling module 303 is created to:

[0087] If the component library includes the target object corresponding to the object call instruction, reusing the target object;

[0088] Otherwise, a match is performed in an object template library according to the target type corresponding to the target object, a matching target object template is determined, and the target object is created according to the target object template.

[0089] In some embodiments of the present disclosure, the component library includes at least one of a context object, a window container object, and a transfer object.

[0090] In some embodiments of the present disclosure, the object template library includes multiple object templates, and each object template is used to indicate a specific process of generating an object.

[0091] In some embodiments of the present disclosure, the device further includes:

[0092] Logic adjustment module, used to add timeout logic and cancel thread check logic in the main thread of the test module;

[0093] The iteration module is used to block the iteration thread in the test iteration phase, use the main thread to execute the iteration process, and use atomic variables to return the execution result to the iteration thread.

[0094] In some embodiments of the present disclosure, the device further includes:

[0095] The merging module is used to inject the thread management object of the iteration thread into the main thread of the test module through an interface to merge the main thread and the iteration thread.

[0096] The test optimization device provided in the embodiments of the present disclosure can execute the test optimization method provided in any embodiment of the present disclosure, and has the functional modules and beneficial effects corresponding to the execution method.

[0097] A computer program product, comprising a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the steps of the method according to claim 1 are implemented.

[0098] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure.

[0099] The following specific reference Figure 4 , which shows a schematic diagram of the structure of an electronic device 400 suitable for implementing the embodiment of the present disclosure. The electronic device 400 in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0100] like Figure 4As shown, the electronic device 400 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage device 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 are also stored. The processing device 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0101] Typically, the following devices may be connected to the I / O interface 405: an input device 406 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 408 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 409. The communication device 409 may allow the electronic device 400 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 400 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0102] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 409, or installed from a storage device 408, or installed from a ROM 402. When the computer program is executed by the processing device 401, the above-mentioned functions defined in the test optimization of the embodiment of the present disclosure are executed.

[0103] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0104] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0105] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0106] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: receives an object call instruction during the test iteration phase of unit testing of the application; if the target object of the object call instruction belongs to the iteration-associated object, obtains the rewritten target object and executes the call; otherwise, creates the target object based on a preset component library or object template library and executes the call.

[0107] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0108] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0109] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, constitute a limitation on the unit itself.

[0110] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0111] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0112] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.

[0113] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0114] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A test optimization method, characterized in that: include: During the test iteration phase of unit testing the application, an object call instruction is received; If the target object of the object call instruction belongs to the iteration-related object, the rewritten target object is obtained and the call is executed; Otherwise, the target object is created based on a preset component library or object template library and the call is executed.

2. The method according to claim 1, characterized in that The iteration-related object includes at least one of the following: a key-value pair storage object, a process object, a lifecycle callback object, and a broadcast callback object.

3. The method according to claim 1, characterized in that Creating the target object based on a preset component library or object template library includes: If the component library includes the target object corresponding to the object call instruction, reusing the target object; Otherwise, a match is performed in an object template library according to the target type corresponding to the target object, a matching target object template is determined, and the target object is created according to the target object template.

4. The method according to claim 3, characterized in that The component library includes at least one of a context object, a window container object, and a transfer object.

5. The method according to claim 3, characterized in that: The object template library includes a plurality of object templates, each of which is used to indicate a specific process of generating an object.

6. The method according to claim 1, characterized in that The method further comprises: Add timeout logic to the main thread of the test module and cancel the thread check logic; In the test iteration phase, the iteration thread is blocked, the main thread is used to execute the iteration process, and the execution result is returned to the iteration thread using atomic variables.

7. The method according to claim 1, characterized in that The method further comprises: The thread management object of the iteration thread is injected into the main thread of the test module through an interface to merge the main thread and the iteration thread.

8. A test optimization device, characterized in that: include: A receiving module, used for receiving an object calling instruction during a test iteration phase of unit testing an application program; An acquisition calling module, used for acquiring the rewritten target object and executing the call if the target object of the object calling instruction belongs to the iteration associated object; A call module is created, which is used to create the target object and execute the call based on a preset component library or object template library.

9. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the test optimization method described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the test optimization method described in any one of claims 1 to 7.