Test method, device, readable medium and electronic device

By combining test classes with dependencies with the specified object, the target test class is formed, which solves the problems of management inconvenience and extended run time caused by the increase in the number of test class files in unit tests, and improves the execution efficiency of unit tests.

CN114036053BActive Publication Date: 2025-03-07BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111342659.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-12
Publication Date
2025-03-07
Estimated Expiration
2041-11-12

AI Technical Summary

Technical Problem

When using PowerMock for unit test development, as the number of test class files increases, the number of test class files increases, resulting in inconvenient file management, and the test class loading time and unit test run time are longer, which reduces the execution efficiency of unit tests.

Method used

By obtaining multiple test classes in the test file, combining those test classes that have dependencies with the specified object, forming the target test class. Dependencies are used to characterize a specified object that provides test parameters to the test class. Then test according to the target test class to get the test results.

Benefits of technology

By merging the test classes with dependencies, the number of test class files is reduced, management is simplified, and the time to mock the specified object is reduced, thus reducing the overall running time of unit tests and improving the execution efficiency of unit tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114036053B_ABST
    Figure CN114036053B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a testing method, device, readable medium and electronic device, and relates to the field of testing technology. The method comprises: obtaining a test file, wherein the test file comprises a plurality of test classes; merging the test classes in the plurality of test classes that have a dependency relationship with a specified object to obtain a target test class, wherein the dependency relationship is used to characterize that the specified object can provide test parameters for the test class, and testing the task to be tested according to the target test class to obtain a test result. The present disclosure merges the test classes that have a dependency relationship with the specified object so that the merged target test class can share the specified object, thereby reducing the number of test class files and facilitating management. At the same time, the loading time of the test class and the time used to simulate the specified object can be reduced, thereby reducing the overall running time of the unit test, and further improving the execution efficiency of the unit test.
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 method, a device, a readable medium and an electronic device. Background Art

[0002] Unit testing is a testing activity to be performed during the software development process. During the unit testing process, the method to be tested will reference many external dependent objects (such as sending emails, network communications, remote services, and file systems, etc.). Therefore, it is usually necessary to use Mock tools to simulate these external dependent objects to complete unit testing. At present, the PowerMock framework is mainly used for unit test development. When using PoweMock for unit test development, a single class is used as a unit to create a corresponding test class and write test cases for the class methods.

[0003] However, when using PoweMock for unit test development, as the number of classes increases, the number of corresponding test classes will also increase linearly, resulting in a large number of files, which is not conducive to management. At the same time, during the test execution process, the loading time of the test class and the overall running time of the unit test will be longer, reducing the execution efficiency of the unit test. Summary of the invention

[0004] This summary is provided to introduce concepts in a brief form that will be described in detail in the detailed description below. This summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.

[0005] In a first aspect, the present disclosure provides a testing method, the method comprising:

[0006] Obtain a test file, wherein the test file includes multiple test classes;

[0007] Merging the test classes that have a dependency relationship with the specified object among the multiple test classes to obtain a target test class; the dependency relationship is used to indicate that the specified object can provide test parameters for the test class;

[0008] According to the target test class, the task to be tested is tested to obtain a test result.

[0009] In a second aspect, the present disclosure provides a testing device, the device comprising:

[0010] An acquisition module, used to acquire a test file, wherein the test file includes a plurality of test classes;

[0011] A merging module, used to merge the test classes in the plurality of test classes that have a dependency relationship with the specified object to obtain a target test class; the dependency relationship is used to indicate that the specified object can provide test parameters for the test class;

[0012] The test module is used to test the task to be tested according to the target test class and obtain the test result.

[0013] In a third aspect, the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect of the present disclosure.

[0014] In a fourth aspect, the present disclosure provides an electronic device, including:

[0015] a storage device having a computer program stored thereon;

[0016] A processing device is used to execute the computer program in the storage device to implement the steps of the method described in the first aspect of the present disclosure.

[0017] Through the above technical solution, the present invention first obtains a test file, the test file includes multiple test classes, and then merges the test classes in the multiple test classes that have a dependency relationship with the specified object to obtain a target test class, wherein the dependency relationship is used to characterize that the specified object can provide test parameters for the test class, and finally tests the task to be tested according to the target test class to obtain a test result. The present invention merges the test classes that have a dependency relationship with the specified object so that the merged target test class can share the specified object, thereby reducing the number of test class files and facilitating management. At the same time, it can reduce the loading time of the test class and the time used to simulate the specified object, thereby reducing the overall running time of the unit test, and thus improving the execution efficiency of the unit test.

[0018] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] 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 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. In the drawings:

[0020] Figure 1 is a flow chart of a testing method according to an exemplary embodiment;

[0021] Figure 2 is based on Figure 1 A flow chart of step 102 is shown in the illustrated embodiment;

[0022] Figure 3 is a flowchart showing a preset merging step according to an exemplary embodiment;

[0023] Figure 4 is based on Figure 3 A flow chart of step 202 is shown in the illustrated embodiment;

[0024] Figure 5 is a block diagram of a testing device according to an exemplary embodiment;

[0025] Figure 6 is based on Figure 5 A block diagram of a merging module shown in the illustrated embodiment;

[0026] Figure 7 is based on Figure 5 A block diagram of a test module shown in the illustrated embodiment;

[0027] Figure 8 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0028] 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.

[0029] 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.

[0030] 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.

[0031] 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.

[0032] 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".

[0033] 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.

[0034] Figure 1 FIG. 1 is a flow chart of a testing method according to an exemplary embodiment. Figure 1 As shown, the method comprises the following steps:

[0035] Step 101, obtain a test file, the test file includes multiple test classes.

[0036] For example, in the process of unit testing using the PowerMock framework, a corresponding test class is created based on a single class (for example, the test classes corresponding to classes ClassA1 and ClassA2 are ClassA1Test and ClassA2Test, respectively), and each test class is tested in isolation from the rest of the program. At this time, for test classes that need to rely on external specified objects, a mock object can be created to replace these specified objects to complete the unit test. However, when using PoweMock for unit test development, as the number of classes increases, there will be a large number of files that are not conducive to management, and the loading time of the test class and the overall running time of the unit test will be long, which will affect the execution efficiency of the unit test. In order to avoid the above problems, the method of automatically merging the test classes that need to rely on external specified objects in the unit test can be used to improve the execution efficiency of the unit test.

[0037] Specifically, the test file can be obtained first, and the Java original files of all test classes that need to simulate the specified object under the test file can be read. Among them, the task to be tested can be a unit test of any of the system files of the specified system (such as the game system), the project files of the specified business project under the system (such as the transaction project under the game system), and the module files of the specific business module under the project (such as the payment module under the transaction project). The corresponding test file can be the file used for unit testing the system file, project file or module file.

[0038] Step 102: merge the test classes in the plurality of test classes that have a dependency relationship with the specified object to obtain a target test class, wherein the dependency relationship is used to indicate that the specified object can provide test parameters for the test class.

[0039] Furthermore, the test classes that have dependencies with external designated objects can be determined from multiple test classes. The designated objects corresponding to each test class can be functions, methods, and single classes that the test class depends on and can provide the test class with test parameters for supporting the unit testing of the test class. When using the test class for unit testing, it is necessary to simulate the designated object and replace the designated object with the simulated object generated by the simulation to complete the unit test. This simulated object can call a specific method with specific parameters and return the expected result to support the test class to complete the unit test.

[0040] Then, according to the specified object that the test class depends on, the test classes that have a dependency relationship with the specified object and can share the specified object can be merged to obtain a target test class (the target test class is a test class generated by merging at least two test classes). In this way, the number of test classes can be greatly reduced, which is convenient for managing test class files. At the same time, due to the reduction in the number of test classes, the loading time of the test class and the time used to simulate the specified object will also be reduced, thereby reducing the overall running time of the unit test and improving the execution efficiency of the unit test.

[0041] For example, when the specified object is a class (i.e., the test class needs to rely on its corresponding class to complete the unit test), the Mock tool can be used to Mock the class that the test class depends on to complete the unit test. When mocking a class B that a test class A1 depends on, at least 300ms are required each time (the 300ms here is just an example, and the present disclosure does not make specific restrictions on this), and the Mock validity period of class B is during the operation of the entire class, and different classes cannot share Mocks. If class A2 also needs to mock class B, it also needs to spend at least 300ms. If class A1 and class A2 are not merged, class B needs to be mocked once respectively, and there will be two mocks (at this time, it takes at least 600ms). If class A1 and class A2 are merged into a class C, then class C only needs to mock class B once, and it can be valid in the entire life cycle of class C, reducing the number of mocks and the time consumed by mocks (at this time, it takes at least 300ms). It can be seen that the more test classes are merged, the more obvious the sharing effect of Mock will be, and the more time spent on Mock will be reduced, which can greatly reduce the overall running time of unit testing and improve the execution efficiency of unit testing.

[0042] Step 103: Test the task to be tested according to the target test class to obtain a test result.

[0043] In this step, the target test class and the test classes that are not merged in the multiple test classes can be stored in a preset file to obtain the target test file, and the task to be tested is tested according to the target test file to obtain the test result. Furthermore, there can be multiple test files. When there are multiple test files, the target test class corresponding to each test file can be obtained through steps 101-102, and the target test class corresponding to each test file and the test classes that are not merged in each test file can be stored in a preset file to obtain the target test file, and the task to be tested is tested according to the target test file to obtain the test result.

[0044] It should be noted that the use of the test method disclosed in the present invention is not limited to business. As long as it is a scene (such as the Internet, e-commerce, and game scenes) in which PoweMock is used for unit test development in a Java project, the test method disclosed in the present invention can be used to merge the test class. For example, for the payment system of an e-commerce platform, the various payment methods in the payment system need to rely on the order system and the third-party payment interface, but it is difficult to instantiate the order system and the third-party payment interface in the unit test development of the payment system, and it is necessary to generate a simulation object through Mock. At this time, the above solution for merging the test class can be used to automatically merge all test files in the payment system into one file to improve the unit test execution efficiency. For another example, for the ranking system in the game, different rankings in the ranking system need to rely on player character information, but it is difficult to instantiate a large amount of player character data in the unit test development of the ranking system, and it is necessary to generate a simulation object of the player character information through Mock. At this time, the above solution for merging the test class can be used to merge multiple test files in the ranking into one file to improve the unit test execution efficiency.

[0045] In summary, the present disclosure first obtains a test file, the test file includes multiple test classes, then merges the test classes in the multiple test classes that have a dependency relationship with the specified object to obtain a target test class, wherein the dependency relationship is used to characterize that the specified object can provide test parameters for the test class, and finally tests the task to be tested according to the target test class to obtain a test result. The present disclosure merges the test classes that have a dependency relationship with the specified object so that the merged target test class can share the specified object, thereby reducing the number of test class files and facilitating management. At the same time, it can reduce the loading time of the test class and the time used to simulate the specified object, thereby reducing the overall running time of the unit test, and thus improving the execution efficiency of the unit test.

[0046] Figure 2 is based on Figure 1 The embodiment shown is a flow chart of step 102. Figure 2 As shown, step 102 may include the following steps:

[0047] Step 1021 , looping through the preset set processing steps to obtain a target test class set, until the number of test classes in the target test class set is less than or equal to a preset number threshold.

[0048] Among them, the preset set processing step includes: step 1), according to the first test class and the second test class in the test class set, a target test class set is obtained through a preset merging step, the first test class is the current test class, the second test class is the first test class in the test class set, the test class set includes test classes in multiple test classes that have a dependency relationship with the specified object, and the test classes are arranged in a preset arrangement order. Step 2), when the number of test classes in the target test class set is greater than the preset number threshold, the first test class in the target test class set is removed to obtain a pending test class set. Step 3), the pending test class set is used as a new test class set.

[0049] Step 1022: When the number of test classes in the target test class set is less than or equal to a preset number threshold, determine a target test class according to the test classes removed from the target test class set.

[0050] For example, after obtaining multiple test classes, a test class collection can be generated based on the test classes in the multiple test classes that have a dependency relationship with the specified object, and the preset collection processing steps can be looped to obtain the target test class collection until the number of test classes in the target test class collection is less than or equal to the preset number threshold (the preset number threshold can be 1).

[0051] Among them, the preset set processing step includes: first, traverse the test class set from the beginning to the end, and at the same time, in the process of traversing the test class set, continuously merge the first test class and the second test class according to the first test class (i.e., the current test class currently traversed) and the second test class (i.e., the first test class in the test class set) through the preset merging step to obtain the target test class set, and then, when the number of test classes in the target test class set is greater than the preset number threshold, remove the first test class in the target test class set to update the test classes in the target test class set to obtain the pending test class set, and use the pending test class set as the new test class set. The loop execution of the preset set processing step can actually be understood as starting from the second test class in the test class set, traversing backwards, and judging whether the current test class and the first test class in the test class set can be merged. If they can be merged, the first test class and the current test class are merged (at this time, not only the properties and methods in the test class are merged, but also the dependencies of the test class are merged). If the merge is not possible, skip the current test class and continue to traverse backwards until the end of the test class set is traversed to obtain the target test class set, then remove the first test class in the target test class set to obtain the pending test class set, and repeat the above steps until the number of test classes in the target test class set is less than or equal to the preset number threshold.

[0052] Then, for each test class removed from the target test class set, it can be determined whether the removed test class is generated by merging at least two test classes. If the removed test class is generated by merging at least two test classes, the removed test class is used as the target test class.

[0053] Figure 3 FIG. 1 is a flowchart showing a preset merging step according to an exemplary embodiment. Figure 3 As shown, when the specified object is a class, the preset merging step may include:

[0054] Step 201 , obtaining dependency information of a first test class and dependency information of a second test class, wherein the dependency information includes classes that the test class needs to depend on and classes that the test class does not need to depend on.

[0055] For example, when the specified object is a class, the PrepareForTest and PowermockIgnore annotations added to the test class can be analyzed to obtain the dependency information of the first test class and the dependency information of the second test class. Among them, the dependency information may include a first dependency list and a second dependency list, the first dependency list includes classes that the test class needs to depend on, and the second dependency list includes classes that the test class does not need to depend on. The PrepareForTest annotation is mainly used to declare classes that are loaded by the PowerMock loader and need to manipulate bytecodes (i.e., classes in the first dependency list), for example, may include Mock final classes, or final, private, static or native methods in non-final classes. The PowermockIgnore annotation is used to declare classes loaded by the AppclassLoader loader (i.e., classes in the second dependency list), rather than classes loaded by the PowerMock loader.

[0056] Step 202: merge the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class.

[0057] Step 203: according to the preset arrangement order, the next test class of the first test class is used as a new first test class.

[0058] Steps 201 to 203 are repeatedly executed until the first test class is the last test class in the test class set, thereby obtaining a target test class set.

[0059] For example, it can be determined whether the first test class and the second test class can be merged based on the dependency information of the first test class and the dependency information of the second test class. If the first test class and the second test class can be merged, merge the first test class and the second test class (not only the properties and methods in the first test class and the second test class, but also the dependencies of the first test class and the second test class, that is, merge the contents of PrepareForTest and PowerMockIgnore), and use the next test class of the first test class as the new first test class in the preset arrangement order. If the first test class and the second test class cannot be merged, directly use the next test class of the first test class as the new first test class. Then the above steps can be repeated until the first test class is the last test class in the test class set (that is, the traversal of the test class set is completed), and the target test class set is obtained.

[0060] Figure 4 is based on Figure 3 The embodiment shown shows a flow chart of step 202. Figure 4 As shown, step 202 may include the following steps:

[0061] Step 2021: Determine whether there is a conflict between the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class.

[0062] Step 2022: When there is no conflict between the first test class and the second test class, merge the first test class and the second test class.

[0063] For example, after obtaining the dependency information of the first test class and the dependency information of the second test class, it can be determined whether there is a conflict between the first test class and the second test class based on the classes that the first test class needs to depend on, included in the first dependency list of the first test class, and the classes that the second test class does not need to depend on, included in the second dependency list of the second test class. If each class that the first test class needs to depend on and the parent class of the class do not have the same class as the classes that the second test class does not need to depend on, it means that the first test class and the second test class are not mutually exclusive and can be merged, and it is determined that there is no conflict between the first target test class and the second target test class. If each class that the first test class needs to depend on and the parent class of the class have the same class as the classes that the second test class does not need to depend on, it means that the first test class and the second test class are mutually exclusive and cannot be merged, and it is determined that there is a conflict between the first target test class and the second target test class.

[0064] In summary, the present disclosure first obtains a test file, the test file includes multiple test classes, then merges the test classes in the multiple test classes that have a dependency relationship with the specified object to obtain a target test class, wherein the dependency relationship is used to characterize that the specified object can provide test parameters for the test class, and finally tests the task to be tested according to the target test class to obtain a test result. The present disclosure merges the test classes that have a dependency relationship with the specified object so that the merged target test class can share the specified object, thereby reducing the number of test class files and facilitating management. At the same time, it can reduce the loading time of the test class and the time used to simulate the specified object, thereby reducing the overall running time of the unit test, and thus improving the execution efficiency of the unit test.

[0065] Figure 5 FIG. 1 is a block diagram of a testing device according to an exemplary embodiment. Figure 5 As shown, the device 300 includes:

[0066] The acquisition module 301 is used to acquire a test file, where the test file includes multiple test classes.

[0067] The merging module 302 is used to merge the test classes in the plurality of test classes that have a dependency relationship with the specified object to obtain a target test class, wherein the dependency relationship is used to indicate that the specified object can provide test parameters for the test class.

[0068] The testing module 303 is used to test the task to be tested according to the target test class and obtain the test result.

[0069] Figure 6 is based on Figure 5 The embodiment shown is a block diagram of a merging module. Figure 6 As shown, the merging module 302 includes:

[0070] The execution submodule 3021 is used to cyclically execute the preset set processing steps to obtain a target test class set, until the number of test classes in the target test class set is less than or equal to a preset number threshold.

[0071] The preset set processing step includes: obtaining a target test class set through a preset merging step according to the first test class and the second test class in the test class set, wherein the first test class is the current test class, the second test class is the first test class in the test class set, the test class set includes test classes in a plurality of test classes that have a dependency relationship with the specified object, and the test classes are arranged in a preset arrangement order. When the number of test classes in the target test class set is greater than the preset number threshold, the first test class in the target test class set is removed to obtain a pending test class set. The pending test class set is used as a new test class set.

[0072] The determination submodule 3022 is configured to determine a target test class according to the test classes removed from the target test class set when the number of test classes in the target test class set is less than or equal to a preset number threshold.

[0073] Optionally, when the specified object is a class, the execution submodule is used to implement the preset merging step through the following steps:

[0074] Obtain dependency information of the first test class and dependency information of the second test class, wherein the dependency information includes classes that the test class needs to depend on and classes that the test class does not need to depend on.

[0075] The first test class and the second test class are merged according to the dependency information of the first test class and the dependency information of the second test class.

[0076] According to the preset arrangement order, the next test class of the first test class is used as a new first test class.

[0077] Repeat the step of obtaining dependency information of the first test class and the dependency information of the second test class until the next test class of the first test class is used as the new first test class in a preset arrangement order, until the first test class is the last test class in the test class set, and obtain the target test class set.

[0078] Optionally, the execution submodule 3021 is used to:

[0079] It is determined whether there is a conflict between the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class.

[0080] When there is no conflict between the first test class and the second test class, the first test class and the second test class are merged.

[0081] Optionally, the execution submodule 3021 is used to:

[0082] If each class that the first test class needs to depend on and the parent class of the class do not have the same class as the class that the second test class does not need to depend on, it is determined that there is no conflict between the first target test class and the second target test class.

[0083] If each class that the first test class needs to depend on and the parent class of the class have the same class as the class that the second test class does not need to depend on, it is determined that there is a conflict between the first target test class and the second target test class.

[0084] Optionally, the determination submodule 3022 is used to:

[0085] For each test class removed from the target test class set, determine whether the removed test class is generated by merging at least two test classes. If the removed test class is generated by merging at least two test classes, use the removed test class as the target test class.

[0086] Figure 7 is based on Figure 5 The embodiment shown is a block diagram of a test module. Figure 7 As shown, the test module 303 includes:

[0087] The processing submodule 3031 is used to store the target test class and the test classes that have not been merged in the multiple test classes into a preset file to obtain a target test file.

[0088] The testing submodule 3032 is used to test the task to be tested according to the target test file and obtain the test result.

[0089] In summary, the present disclosure first obtains a test file, the test file includes multiple test classes, then merges the test classes in the multiple test classes that have a dependency relationship with the specified object to obtain a target test class, wherein the dependency relationship is used to characterize that the specified object can provide test parameters for the test class, and finally tests the task to be tested according to the target test class to obtain a test result. The present disclosure merges the test classes that have a dependency relationship with the specified object so that the merged target test class can share the specified object, thereby reducing the number of test class files and facilitating management. At the same time, it can reduce the loading time of the test class and the time used to simulate the specified object, thereby reducing the overall running time of the unit test, and thus improving the execution efficiency of the unit test.

[0090] Reference below Figure 8 , which shows an electronic device (eg, Figure 1 The terminal device 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 8 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.

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

[0092] Typically, the following devices may be connected to the I / O interface 605: an input device 606 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 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8The electronic device 600 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.

[0093] 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 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0094] 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.

[0095] 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.

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

[0097] 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: obtains a test file, the test file includes multiple test classes; merges the test classes that have a dependency relationship with a specified object in the multiple test classes to obtain a target test class; the dependency relationship is used to characterize that the specified object can provide test parameters for the test class; according to the target test class, the task to be tested is tested to obtain a test result.

[0098] 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., via the Internet using an Internet service provider).

[0099] 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.

[0100] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, an acquisition module may also be described as a "module for acquiring test files".

[0101] 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.

[0102] 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.

[0103] According to one or more embodiments of the present disclosure, Example 1 provides a testing method, which includes: obtaining a test file, the test file including multiple test classes; merging the test classes that have a dependency relationship with a specified object in the multiple test classes to obtain a target test class; the dependency relationship is used to characterize that the specified object can provide test parameters for the test class; and according to the target test class, testing the task to be tested to obtain a test result.

[0104] According to one or more embodiments of the present disclosure, Example 2 provides a method of Example 1, wherein the test classes in the multiple test classes that have a dependency relationship with the specified object are merged to obtain a target test class, including: looping through a preset set processing step to obtain a target test class set until the number of test classes in the target test class set is less than or equal to a preset number threshold; the preset set processing step includes: obtaining a target test class set through a preset merging step according to a first test class and a second test class in the test class set, the first test class being the current test class, the second test class being the first test class in the test class set, the test class set including test classes in the multiple test classes that have a dependency relationship with the specified object, and the test classes being arranged in a preset arrangement order; when the number of test classes in the target test class set is greater than the preset number threshold, removing the first test class in the target test class set to obtain a pending test class set; using the pending test class set as a new test class set; when the number of test classes in the target test class set is less than or equal to the preset number threshold, determining the target test class according to the test classes removed from the target test class set.

[0105] According to one or more embodiments of the present disclosure, Example 3 provides the method of Example 2, and when the specified object is a class, the preset merging step includes: obtaining dependency information of the first test class and dependency information of the second test class, the dependency information including classes that the test class needs to depend on and classes that the test class does not need to depend on; merging the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class; taking the next test class of the first test class as the new first test class in the preset arrangement order; repeating the steps of obtaining the dependency information of the first test class and the dependency information of the second test class to taking the next test class of the first test class as the new first test class in the preset arrangement order, until the first test class is the last test class in the test class set, and the target test class set is obtained.

[0106] According to one or more embodiments of the present disclosure, Example 4 provides the method of Example 3, which merges the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class, including: determining whether there is a conflict between the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class; and merging the first test class and the second test class if there is no conflict between the first test class and the second test class.

[0107] According to one or more embodiments of the present disclosure, Example 5 provides the method of Example 4, which determines whether there is a conflict between the first test class and the second test class based on the dependency information of the first test class and the dependency information of the second test class, including: if each class that the first test class needs to depend on and the parent class of the class do not have the same class as the classes that the second test class does not need to depend on, then it is determined that there is no conflict between the first target test class and the second target test class; if each class that the first test class needs to depend on and the parent class of the class have the same class as the classes that the second test class does not need to depend on, then it is determined that there is a conflict between the first target test class and the second target test class.

[0108] According to one or more embodiments of the present disclosure, Example 6 provides the method of Example 2, which determines the target test class based on the test class removed from the target test class set, including: for each test class removed from the target test class set, determining whether the test class removed this time is generated by merging at least two of the test classes, if the test class removed this time is generated by merging at least two of the test classes, using the test class removed this time as the target test class.

[0109] According to one or more embodiments of the present disclosure, Example 7 provides a method of any one of Examples 1 to 6, wherein the task to be tested is tested according to the target test class to obtain a test result, including: storing the target test class and a plurality of test classes that have not been merged into a preset file to obtain a target test file; and testing the task to be tested according to the target test file to obtain the test result.

[0110] According to one or more embodiments of the present disclosure, Example 8 provides a testing device, which includes: an acquisition module, used to acquire a test file, wherein the test file includes multiple test classes; a merging module, used to merge the test classes in the multiple test classes that have a dependency relationship with a specified object to obtain a target test class; the dependency relationship is used to characterize that the specified object can provide test parameters for the test class; and a testing module, used to test the task to be tested according to the target test class to obtain a test result.

[0111] According to one or more embodiments of the present disclosure, Example 9 provides a computer-readable medium having a computer program stored thereon, which implements the steps of the methods described in Examples 1 to 7 when executed by a processing device.

[0112] According to one or more embodiments of the present disclosure, Example 10 provides an electronic device, comprising: a storage device on which a computer program is stored; and a processing device for executing the computer program in the storage device to implement the steps of the method described in Examples 1 to 7.

[0113] 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.

[0114] 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.

[0115] Although the subject matter has been described in language specific to structural features and / or method logic 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. Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.

Claims

1. A testing method, characterized in that: The method comprises: Obtain a test file, wherein the test file includes multiple test classes; Merging the test classes that have a dependency relationship with the specified object among the multiple test classes to obtain a target test class; the dependency relationship is used to indicate that the specified object can provide test parameters for the test class; According to the target test class, the task to be tested is tested to obtain a test result; The step of merging the test classes in the plurality of test classes that have a dependency relationship with the specified object to obtain a target test class includes: Execute the preset set processing steps in a loop to obtain a target test class set until the number of test classes in the target test class set is less than or equal to a preset number threshold; The preset set processing step includes: according to the first test class and the second test class in the test class set, obtaining the target test class set through the preset merging step, the first test class is the current test class, the second test class is the first test class in the test class set, the test class set includes multiple test classes in the test classes that have a dependency relationship with the specified object, and the test classes are arranged in a preset arrangement order; when the number of test classes in the target test class set is greater than a preset number threshold, removing the first test class in the target test class set to obtain a pending test class set; and using the pending test class set as a new test class set; When the number of test classes in the target test class set is less than or equal to a preset number threshold, the target test class is determined according to the test classes removed from the target test class set.

2. The method according to claim 1, characterized in that In the case where the designated object is a class, the preset merging step includes: Obtain dependency information of the first test class and dependency information of the second test class, wherein the dependency information includes classes that the test class needs to depend on and classes that the test class does not need to depend on; Merging the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class; According to the preset arrangement order, taking the next test class of the first test class as a new first test class; Repeat the step of obtaining dependency information of the first test class and dependency information of the second test class to the step of taking the next test class of the first test class as the new first test class according to the preset arrangement order, until the first test class is the last test class in the test class set, and obtain the target test class set.

3. The method according to claim 2, characterized in that The merging the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class includes: determining whether there is a conflict between the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class; When there is no conflict between the first test class and the second test class, the first test class and the second test class are merged.

4. The method according to claim 3, characterized in that: The determining whether there is a conflict between the first test class and the second test class according to the dependency information of the first test class and the dependency information of the second test class includes: If each class that the first test class needs to depend on and the parent class of the class do not have the same class as the class that the second test class does not need to depend on, it is determined that there is no conflict between the first test class and the second test class; If each class that the first test class needs to depend on and the parent class of the class have the same class as the class that the second test class does not need to depend on, it is determined that there is a conflict between the first test class and the second test class.

5. The method according to claim 1, characterized in that The determining the target test class according to the test class removed from the target test class set includes: For each test class removed from the target test class set, determine whether the test class removed this time is generated by merging at least two of the test classes. If the test class removed this time is generated by merging at least two of the test classes, use the test class removed this time as the target test class.

6. The method according to any one of claims 1 to 5, characterized in that The step of testing the task to be tested according to the target test class to obtain the test result includes: The target test class and the test classes that have not been merged among the multiple test classes are stored in a preset file to obtain a target test file; The task to be tested is tested according to the target test file to obtain the test result.

7. A testing device, characterized in that: The device comprises: An acquisition module, used to acquire a test file, wherein the test file includes a plurality of test classes; A merging module, used to merge the test classes in the plurality of test classes that have a dependency relationship with the specified object to obtain a target test class; the dependency relationship is used to indicate that the specified object can provide test parameters for the test class; A test module is used to test the task to be tested according to the target test class and obtain the test result; The merging module comprises: An execution submodule, configured to cyclically execute the preset set processing steps to obtain a target test class set, until the number of test classes in the target test class set is less than or equal to a preset number threshold; The preset set processing step includes: according to the first test class and the second test class in the test class set, obtaining the target test class set through the preset merging step, the first test class is the current test class, the second test class is the first test class in the test class set, the test class set includes multiple test classes in the test classes that have a dependency relationship with the specified object, and the test classes are arranged in a preset arrangement order; when the number of test classes in the target test class set is greater than a preset number threshold, removing the first test class in the target test class set to obtain a pending test class set; and using the pending test class set as a new test class set; The determination submodule is configured to determine the target test class according to the test classes removed from the target test class set when the number of test classes in the target test class set is less than or equal to a preset number threshold.

8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processing device, the steps of the method described in any one of claims 1 to 6 are implemented.

9. An electronic device, characterized in that: include: a storage device having a computer program stored thereon; A processing device, configured to execute the computer program in the storage device to implement the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Automatic selection method for test target in object-oriented software under xUnit framework

    CN103309805A