CN110806967A - Unit testing method and device - Google Patents

Unit testing method and device Download PDF

Info

Publication number
CN110806967A
CN110806967A CN201810885509.7A CN201810885509A CN110806967A CN 110806967 A CN110806967 A CN 110806967A CN 201810885509 A CN201810885509 A CN 201810885509A CN 110806967 A CN110806967 A CN 110806967A
Authority
CN
China
Prior art keywords
configuration file
unit
testing
tested
temporary
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810885509.7A
Other languages
Chinese (zh)
Inventor
裴永平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810885509.7A priority Critical patent/CN110806967A/en
Publication of CN110806967A publication Critical patent/CN110806967A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3696Methods or tools to render software testable

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a unit testing method and a unit testing device, and relates to the technical field of computers. One embodiment of the method comprises: searching in a unit to be tested to determine resources required for testing the unit to be tested; generating a temporary configuration file according to the resources; generating a complete configuration file according to a preset unified configuration file and the temporary configuration file; creating an instance object for testing according to the complete configuration file; and testing the unit to be tested according to the example object for testing. In the embodiment, the example object irrelevant to the unit test is stripped in the unit test, the connection with all external systems is not established any more, and the service of interference is eliminated. The method saves the test time, improves the efficiency, and simultaneously avoids the problems of high error rate and poor universality caused by manually changing the configuration file.

Description

Unit testing method and device
Technical Field
The invention relates to the technical field of computers, in particular to a unit testing method and device.
Background
In the process of program development, developers need to frequently perform unit test on codes to ensure the robustness and integrity of written codes and improve the code quality. In the existing network (web) project engineering, the main mode of unit testing is to use Spring to realize the automatic injection of objects, and to control a specific testing unit by combining with Junit.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
1. a large number of example objects irrelevant to the test of the unit to be tested are created, the test time is consumed, and the test efficiency is reduced.
2. The start-up of the system is very cumbersome and time consuming in the unit test, since the start-up and operation of the system depends on more middleware and external systems.
3. After the system is started, because the connection with the external system is established and all functions are started, the system starts to serve as a server, and the unit test is easily interfered.
4. Before the unit test, the configuration file is manually changed, so that the system is started only aiming at a certain unit test, the error rate is easily improved, and the changed configuration file has poor universality and cannot improve the efficiency.
Disclosure of Invention
In view of this, embodiments of the present invention provide a unit testing method and apparatus, which can solve the problem of long testing time caused by a large number of unrelated instance objects generated by starting the whole system in unit testing; and simultaneously, the problem of interference to the test caused by establishing all connections with an external system is solved.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a unit testing method including: searching in a unit to be tested to determine resources required for testing the unit to be tested, and generating a temporary configuration file according to the resources; generating a complete configuration file according to a preset unified configuration file and the temporary configuration file; creating an instance object for testing according to the complete configuration file; and testing the unit to be tested according to the example object for testing.
Optionally, the searching in the unit to be tested to determine the resources required for testing the unit to be tested includes: searching layer by layer in the unit to be tested by using a recursive algorithm, thereby determining resources required by testing the unit to be tested; wherein the resources include: instance objects, middleware services, database services upon which the unit to be tested depends.
Optionally, generating a temporary configuration file according to the resource includes: obtaining a dependency relationship among the resources according to the resources required by testing the unit to be tested; and generating a temporary configuration file according to the dependency relationship.
Optionally, generating a complete configuration file according to a preset unified configuration file and the temporary configuration file, including: analyzing whether the path, the text format and the grammar of the temporary configuration file are correct, and reading a preset unified configuration file if the path, the text format and the grammar of the temporary configuration file are correct; and establishing connection with the Spring framework, and generating a complete configuration file which can be identified by the Spring framework according to the uniform configuration file and the temporary configuration file.
Optionally, creating an instance object for testing according to the complete configuration file includes: and instantiating the complete configuration file by utilizing a Spring framework to create an instance object for testing.
Optionally, before searching in the unit to be tested, the method further includes: reading a root configuration file of the unit to be tested; starting a unit to be tested according to the root configuration file; wherein the root configuration file comprises all configuration items required for starting the unit to be tested.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a unit testing apparatus including: the system comprises a searching module, a converting module, an instance creating module and an instance executing module; the search module is configured to: searching in a unit to be tested to determine resources required for testing the unit to be tested, and generating a temporary configuration file according to the resources; the conversion module is configured to: generating a complete configuration file according to a preset unified configuration file and the temporary configuration file; the create instance module to: creating an instance object for testing according to the complete configuration file; the execution instance module is to: and testing the unit to be tested according to the example object for testing.
Optionally, the search module is further configured to: searching layer by layer in the unit to be tested by using a recursive algorithm, thereby determining resources required by testing the unit to be tested; wherein the resources include: instance objects, middleware services, database services upon which the unit to be tested depends.
Optionally, the search module is further configured to: obtaining a dependency relationship among the resources according to the resources required by testing the unit to be tested; and generating a temporary configuration file according to the dependency relationship.
Optionally, the conversion module is configured to: analyzing whether the path, the text format and the grammar of the temporary configuration file are correct, and reading a preset unified configuration file if the path, the text format and the grammar of the temporary configuration file are correct; and establishing connection with the Spring framework, and generating a complete configuration file which can be identified by the Spring framework according to the uniform configuration file and the temporary configuration file.
Optionally, the create instance module is configured to: and instantiating the complete configuration file by utilizing a Spring framework to create an instance object for testing.
Optionally, the apparatus further comprises an initiating module, configured to: reading a root configuration file of the unit to be tested; starting a unit to be tested according to the root configuration file; wherein the root configuration file comprises all configuration items required for starting the unit to be tested.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided an electronic apparatus including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the unit testing method provided by the embodiment of the invention.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a computer readable medium having stored thereon a computer program which, when executed by a processor, implements a unit testing method according to an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: because the technical means of creating the instance object pertinently according to the instance object, the middleware service and the like which the unit to be tested depends on is adopted, the instance object irrelevant to the unit test is stripped in the unit test, all connections with an external system are not established any more, and the service of interference is eliminated. The method saves the testing time of unit testing, improves the efficiency, and simultaneously avoids the problems of high error rate and poor universality caused by manually changing the configuration file.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic flow chart of a prior art unit test method;
FIG. 2 is a schematic diagram of a basic flow of a unit testing method according to an embodiment of the invention;
FIG. 3 is a schematic diagram of a preferred flow of a unit testing method according to an embodiment of the invention;
FIG. 4 is a schematic diagram of the basic modules of a unit testing apparatus according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of the operation of a search module according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of the operation of a conversion module according to an embodiment of the present invention;
FIG. 7 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 8 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The following is an explanation of technical terms that may be used in the present invention:
SC-Junit: a simple context unit test component;
SCJ-Search: a simple context unit test component searcher;
SCJ-Transfer: the simple context unit tests the component converter;
spring: a design level framework of open source code;
junit: a Java language unit test framework;
jsf (j Service framework): a high performance service framework;
JMQ: providing a message middleware platform for reliably transferring messages and data;
XSD: XML schema Definition, XML structure Definition;
zookeeper: a distributed, open source distributed application orchestrates services.
With the development of software technology towards low coupling direction such as componentization and service decoupling and the increase of services provided by software systems, the system itself is made to depend on more middleware and external systems for starting and working. Such a system start mode is not problematic and is necessary for normally starting a software system to provide services, but when used in unit testing, it is problematic and cumbersome to make the system extremely heavy and time-consuming. When the system is started, since a connection is established with an external system and all functions are turned on, the system starts serving the functions serving as a server. This is undesirable for developers who want to purposefully do unit testing and not be disturbed by other services. If the configuration file is changed manually, the system is started only aiming at a certain unit test, and developers need to do a lot of configuration file changing work before the unit test, so that although the starting time is reduced, the error rate is improved, meanwhile, the system is not universal, and the efficiency cannot be improved.
FIG. 1 is a flow chart of a prior art unit test method. As shown in fig. 1, first, a Spring test component is added to a unit to be tested and a root configuration file (i.e. a start configuration file) is specified; starting a unit test; creating all instances under the configuration file; the execution instance, unit testing begins. Wherein, all the examples under the configuration file are created, a large number of example objects irrelevant to the test unit are created. Taking the waybill system as an example, the number of created example objects is more than 500, and generally, no more than 10 example objects are used in unit test; in addition, the testing process may consume a large amount of network connection time during registration of middleware such as JSF, JMQ, etc., Zookeeper, monitoring system, etc., and most of the established network services are not used in unit testing.
Fig. 2 is a schematic diagram of a basic flow of a unit testing method according to an embodiment of the present invention, as shown in fig. 2, an embodiment of the present invention provides a unit testing method, including:
s201, searching in a unit to be tested to determine resources required by testing the unit to be tested; generating a temporary configuration file according to the resources;
s202, generating a complete configuration file according to a preset unified configuration file and the temporary configuration file;
s203, creating an example object for testing according to the complete configuration file;
and S204, testing the unit to be tested according to the example object for testing.
The embodiment of the invention adopts the method of establishing the instance object according to the pertinence of the resource depended by the unit to be tested, and the instance object irrelevant to the unit test is stripped in the unit test, so that the connection with all external systems is not established any more, and the service of interference is eliminated. The method saves the test time, improves the efficiency, and simultaneously avoids the problems of high error rate and poor universality caused by manually changing the configuration file.
In the embodiment of the present invention, the searching in the unit to be tested to determine the resource required for testing the unit to be tested includes: searching layer by layer in the unit to be tested by using a recursive algorithm to determine resources required by testing the unit to be tested; wherein the resources include: instance objects, middleware services, database services upon which the unit to be tested depends. And taking the resource directly depended by the unit to be tested as a first resource and the resource directly depended by the first resource as a second resource, and continuing searching layer by layer until the last layer is searched, namely, the next resource without direct dependence is searched. By utilizing a recursive algorithm, the nesting dependence is searched, namely all resources required by the unit to be tested for testing are searched layer by layer, all the resources required by the testing can be ensured to be searched, and the accuracy of the testing result is improved.
In the embodiment of the present invention, generating a temporary configuration file according to the resource includes: obtaining a dependency relationship among the resources according to the resources required by testing the unit to be tested; and generating a temporary configuration file according to the dependency relationship. The embodiment of the invention generates the temporary configuration file by utilizing the dependency relationship among the resources, improves the accuracy of the test result, ensures that no configuration item irrelevant to the unit to be tested exists in the configuration file, reduces the possibility of creating an irrelevant instance object and improves the test efficiency.
In the embodiment of the present invention, generating a complete configuration file according to a preset unified configuration file and the temporary configuration file includes: analyzing whether the path, the text format and the grammar of the temporary configuration file are correct, and reading a preset unified configuration file if the path, the text format and the grammar of the temporary configuration file are correct; and establishing connection with the Spring framework, and generating a complete configuration file which can be identified by the Spring framework according to the uniform configuration file and the temporary configuration file. Spring is a design level framework for open source code. The unified configuration file comprises a plurality of fixed configuration items such as public configuration, parameters and the like. The configuration file of the embodiment of the invention has no configuration item irrelevant to the unit to be tested, thereby reducing the possibility of creating an irrelevant instance object, generating a complete configuration file which can be identified by a Spring framework, facilitating the Spring to generate the instance object and improving the testing efficiency.
In the embodiment of the present invention, creating an instance object for testing according to the complete configuration file includes: and instantiating the complete configuration file by utilizing a Spring framework to create an instance object for testing. No instance object which is irrelevant to the unit test is generated, and no connection is established with redundant external systems, so that the test time is saved, and the interference rate and the error rate are reduced.
In the embodiment of the present invention, before searching in the unit to be tested, the method further includes: reading a root configuration file of a unit to be tested; the root configuration file is a unit starting configuration file and comprises all configuration items required for starting the unit to be tested; and starting the unit to be tested according to the root configuration file. The root configuration file in a general sense is an application system starting configuration file, and the root configuration file is used for starting the application system and comprises all configuration items for starting the application system. Whereas the root profile in the embodiments of the present invention is only responsible for starting the part of the system that is relevant to the unit under test. The starting time of the system in the unit test is reduced, and the efficiency of the unit test is improved.
FIG. 3 is a schematic diagram of a preferred flow of a unit testing method according to an embodiment of the invention. As shown in fig. 3, a set root profile is added to a unit to be tested; starting a unit test; searching resources required by the unit test to generate a complete configuration file; creating an instance (namely a resource) under the newly generated configuration file; the unit test was started according to the examples.
FIG. 4 is a schematic diagram of the basic modules of a unit testing apparatus according to an embodiment of the present invention. As shown in fig. 4, an embodiment of the present invention provides a unit testing apparatus 400, including: a search module 401, a conversion module 402, a create instance module 403, and an execute instance module 404;
a search module 401 configured to: searching in a unit to be tested to determine resources required for testing the unit to be tested, and generating a temporary configuration file according to the resources;
a conversion module 402 for: generating a complete configuration file according to a preset unified configuration file and the temporary configuration file;
a create instance module 403 to: creating an instance object for testing according to the complete configuration file;
an execute instance module 404 to: and testing the unit to be tested according to the example object for testing.
The embodiment of the invention adopts the method of establishing the instance object according to the pertinence of the resource depended by the unit to be tested, and the instance object irrelevant to the unit test is stripped in the unit test, so that the connection with all external systems is not established any more, and the service of interference is eliminated. The method saves the test time, improves the efficiency, and simultaneously avoids the problems of high error rate and poor universality caused by manually changing the configuration file.
In this embodiment of the present invention, the searching module 401 is further configured to: searching layer by layer in the unit to be tested by using a recursive algorithm, and circularly traversing the dependent resources to determine the resources required by testing the unit to be tested; wherein the resources include: instance objects, middleware services, database services. By utilizing a recursive algorithm, the nesting dependence is searched, namely all resources required by the unit to be tested for testing are searched layer by layer, all the resources required by the testing can be ensured to be searched, and the accuracy of the testing result is improved.
In this embodiment of the present invention, the searching module 401 is further configured to: obtaining a dependency relationship among the resources according to the resources required by testing the unit to be tested; and generating a temporary configuration file according to the dependency relationship. The embodiment of the invention generates the temporary configuration file by utilizing the dependency relationship among the resources, improves the accuracy of the test result, ensures that no configuration item irrelevant to the unit to be tested exists in the configuration file, reduces the possibility of creating an irrelevant instance object and improves the test efficiency.
In this embodiment of the present invention, the conversion module 402 is configured to: analyzing whether the path, the text format and the grammar of the temporary configuration file are correct, and reading a preset unified configuration file if the path, the text format and the grammar of the temporary configuration file are correct; and establishing connection with the Spring framework, and generating a complete configuration file which can be identified by the Spring framework according to the uniform configuration file and the temporary configuration file. The configuration file of the embodiment of the invention has no configuration item irrelevant to the unit to be tested, thereby reducing the possibility of creating an irrelevant instance object, generating a complete configuration file which can be identified by a Spring framework, facilitating the Spring to generate the instance object and improving the testing efficiency.
In this embodiment of the present invention, the create instance module 403 is configured to: and instantiating the complete configuration file by utilizing a Spring framework to create an instance object for testing. No instance object which is irrelevant to the unit test is generated, and no connection is established with redundant external systems, so that the test time is saved, and the interference rate and the error rate are reduced.
In the embodiment of the present invention, the apparatus further includes a starting module, and the starting module is configured to: reading a root configuration file of a unit to be tested; the root configuration file is a starting configuration file of the unit and comprises all configuration items required for starting the unit to be tested; and starting the unit to be tested according to the root configuration file. The root profile in the embodiment of the present invention is only responsible for starting the part of the system related to the unit to be tested. The starting time of the system in the unit test is reduced, and the efficiency of the unit test is improved.
FIG. 5 is a schematic diagram of the operation of a search module according to an embodiment of the present invention. As shown in fig. 5:
① after the unit test is started (unit startup), the Search module (i.e., SCJ-Search, where SCJ is SimpleContext-Junit, simple context unit test component) is notified that the unit test is started, e.g., SCJ-Search is notified that A is started.
②, SCJ-Search searches the target file for the resources needed by the file;
③, returning the needed resources after the search is finished;
SCJ-Search firstly searches in A and returns resources B and C depended by A; searching in B and C respectively, and returning a resource D depended on by B and a resource E depended on by C; and D and E have no dependent resources, so that the search is not returned and ended.
④ determining the direct dependency relationship of resources, A depends on resources B and C, resource B depends on resource D, and resource C depends on resource E
⑤, after the dependency relationship Search is finished, the SCJ-Search collects the searched resources and the dependency relationship thereof and creates a temporary configuration file.
FIG. 6 is a schematic diagram of the operation of a conversion module according to an embodiment of the present invention. As shown in fig. 6, the conversion module (i.e., SCJ-Transfer) may include:
an analyzer to: analyzing a temporary configuration file created by the SCJ-Search, analyzing the correctness of a path, a text format, grammar and the like of the file, and informing a configuration generator after analysis;
a unified configurator to: reading a unified configuration file including common configuration, parameters and the like involved in unit testing, and informing a configuration generator of a read result;
a configuration generator to: after all configurations (temporary and unified configurations) are received, a configuration file which can be identified by the Spring is generated and delivered to the Spring to create a resource according to the Spring syntax requirement.
FIG. 7 illustrates an exemplary system architecture 700 to which the unit testing method or unit testing apparatus of embodiments of the present invention may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 705 over a network 704, to receive or send messages or the like. Various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like, may be installed on the terminal devices 701, 702, and 703.
The terminal devices 701, 702, 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 705 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 701, 702, and 703. The background management server can analyze and process the received data such as the product information query request and feed back the processing result such as the target push information to the terminal equipment.
It should be noted that the unit testing method provided by the embodiment of the present invention is generally executed by the server 705, and accordingly, the unit testing apparatus is generally disposed in the server 705.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides an electronic device and a computer readable medium according to the embodiment of the invention.
The electronic device of the embodiment of the invention comprises: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the unit testing method provided by the embodiment of the invention.
A computer-readable medium of an embodiment of the present invention has a computer program stored thereon, which when executed by a processor implements a unit testing method as provided by an embodiment of the present invention.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 8, the computer system 800 includes a Central Processing Unit (CPU)801 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data necessary for the operation of the system 800 are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program executes the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 801.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor, comprising: the system comprises a searching module, a converting module, an instance creating module and an instance executing module. The names of these modules do not in some cases constitute a limitation on the modules themselves, for example, an execute instance module may also be described as a "module for testing the unit according to an instance object".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: s201, searching in a unit to be tested to determine resources required by testing the unit to be tested, and generating a temporary configuration file according to the resources; s202, generating a complete configuration file according to a preset unified configuration file and the temporary configuration file; s203, creating an example object for testing according to the complete configuration file; and S204, testing the unit to be tested according to the example object for testing.
The embodiment of the invention adopts the method of establishing the instance object according to the pertinence of the resource depended by the unit to be tested, and the instance object irrelevant to the unit test is stripped in the unit test, so that the connection with all external systems is not established any more, and the service of interference is eliminated. The method saves the test time, improves the efficiency, and simultaneously avoids the problems of high error rate and poor universality caused by manually changing the configuration file.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (14)

1. A method of unit testing, comprising:
searching in a unit to be tested to determine resources required for testing the unit to be tested, and generating a temporary configuration file according to the resources;
generating a complete configuration file according to a preset unified configuration file and the temporary configuration file;
creating an instance object for testing according to the complete configuration file;
and testing the unit to be tested according to the example object for testing.
2. The method of claim 1, wherein said searching among the units under test to determine the resources required to test the units under test comprises:
searching layer by layer in the unit to be tested by using a recursive algorithm, thereby determining resources required by testing the unit to be tested;
wherein the resources include: instance objects, middleware services, database services upon which the unit to be tested depends.
3. The method of claim 1, wherein generating a temporary configuration file from the resources comprises:
obtaining a dependency relationship among the resources according to the resources required by testing the unit to be tested;
and generating a temporary configuration file according to the dependency relationship.
4. The method of claim 1, wherein generating a complete configuration file according to a preset unified configuration file and the temporary configuration file comprises:
analyzing whether the path, the text format and the grammar of the temporary configuration file are correct, and reading a preset unified configuration file if the path, the text format and the grammar of the temporary configuration file are correct;
and establishing connection with the Spring framework, and generating a complete configuration file which can be identified by the Spring framework according to the uniform configuration file and the temporary configuration file.
5. The method of claim 4, wherein creating instance objects for testing from the complete configuration file comprises:
and instantiating the complete configuration file by utilizing a Spring framework to create an instance object for testing.
6. The method of claim 1, wherein prior to searching among the units under test, further comprising:
reading a root configuration file of a unit to be tested, and starting the unit to be tested according to the root configuration file;
wherein the root configuration file comprises all configuration items required for starting the unit to be tested.
7. A unit testing apparatus, comprising: the system comprises a searching module, a converting module, an instance creating module and an instance executing module;
the search module is configured to: searching in a unit to be tested to determine resources required for testing the unit to be tested, and generating a temporary configuration file according to the resources;
the conversion module is configured to: generating a complete configuration file according to a preset unified configuration file and the temporary configuration file;
the create instance module to: creating an instance object for testing according to the complete configuration file;
the execution instance module is to: and testing the unit to be tested according to the example object for testing.
8. The apparatus of claim 1, wherein the search module is further configured to:
searching layer by layer in the unit to be tested by using a recursive algorithm, thereby determining resources required by testing the unit to be tested;
wherein the resources include: instance objects, middleware services, database services upon which the unit to be tested depends.
9. The apparatus of claim 1, wherein the search module is further configured to:
obtaining a dependency relationship among the resources according to the resources required by testing the unit to be tested;
and generating a temporary configuration file according to the dependency relationship.
10. The apparatus of claim 1, wherein the conversion module is configured to:
analyzing whether the path, the text format and the grammar of the temporary configuration file are correct, and reading a preset unified configuration file if the path, the text format and the grammar of the temporary configuration file are correct;
and establishing connection with the Spring framework, and generating a complete configuration file which can be identified by the Spring framework according to the uniform configuration file and the temporary configuration file.
11. The apparatus of claim 4, wherein the create instance module is configured to:
and instantiating the complete configuration file by utilizing a Spring framework to create an instance object for testing.
12. The apparatus of claim 1, further comprising an activation module to:
reading a root configuration file of a unit to be tested;
starting a unit to be tested according to the root configuration file;
wherein the root configuration file comprises all configuration items required for starting the unit to be tested.
13. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN201810885509.7A 2018-08-06 2018-08-06 Unit testing method and device Pending CN110806967A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810885509.7A CN110806967A (en) 2018-08-06 2018-08-06 Unit testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810885509.7A CN110806967A (en) 2018-08-06 2018-08-06 Unit testing method and device

Publications (1)

Publication Number Publication Date
CN110806967A true CN110806967A (en) 2020-02-18

Family

ID=69487210

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810885509.7A Pending CN110806967A (en) 2018-08-06 2018-08-06 Unit testing method and device

Country Status (1)

Country Link
CN (1) CN110806967A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111338944A (en) * 2020-02-21 2020-06-26 北京字节跳动网络技术有限公司 Remote Procedure Call (RPC) interface test method, device, medium and equipment
CN113448853A (en) * 2021-06-30 2021-09-28 东莞市大易产业链服务有限公司 Unit testing method, unit testing device, testing equipment and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102609352A (en) * 2011-01-19 2012-07-25 阿里巴巴集团控股有限公司 Parallel testing method and parallel testing server
CN102831066A (en) * 2012-09-19 2012-12-19 深圳中兴网信科技有限公司 Integration test device and method
CN104317722A (en) * 2014-11-13 2015-01-28 中国建设银行股份有限公司 Unit testing method and device based on Junit
CN104536899A (en) * 2015-01-20 2015-04-22 成都益联科创科技有限公司 Software deploying and maintaining method based on intelligent cluster
CN105915529A (en) * 2016-05-19 2016-08-31 微梦创科网络科技(中国)有限公司 Message generation method and device
CN106569943A (en) * 2015-10-09 2017-04-19 北京北方微电子基地设备工艺研究中心有限责任公司 Hardware testing method and hardware testing system for equipment
CN106874202A (en) * 2017-02-14 2017-06-20 网易无尾熊(杭州)科技有限公司 Method, device and readable storage medium storing program for executing for unit testing
CN107766230A (en) * 2016-08-19 2018-03-06 阿里巴巴集团控股有限公司 A kind of method and apparatus tested based on configuration file

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102609352A (en) * 2011-01-19 2012-07-25 阿里巴巴集团控股有限公司 Parallel testing method and parallel testing server
CN102831066A (en) * 2012-09-19 2012-12-19 深圳中兴网信科技有限公司 Integration test device and method
CN104317722A (en) * 2014-11-13 2015-01-28 中国建设银行股份有限公司 Unit testing method and device based on Junit
CN104536899A (en) * 2015-01-20 2015-04-22 成都益联科创科技有限公司 Software deploying and maintaining method based on intelligent cluster
CN106569943A (en) * 2015-10-09 2017-04-19 北京北方微电子基地设备工艺研究中心有限责任公司 Hardware testing method and hardware testing system for equipment
CN105915529A (en) * 2016-05-19 2016-08-31 微梦创科网络科技(中国)有限公司 Message generation method and device
CN107766230A (en) * 2016-08-19 2018-03-06 阿里巴巴集团控股有限公司 A kind of method and apparatus tested based on configuration file
CN106874202A (en) * 2017-02-14 2017-06-20 网易无尾熊(杭州)科技有限公司 Method, device and readable storage medium storing program for executing for unit testing

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111338944A (en) * 2020-02-21 2020-06-26 北京字节跳动网络技术有限公司 Remote Procedure Call (RPC) interface test method, device, medium and equipment
CN111338944B (en) * 2020-02-21 2023-09-08 北京字节跳动网络技术有限公司 Remote Procedure Call (RPC) interface testing method, device, medium and equipment
CN113448853A (en) * 2021-06-30 2021-09-28 东莞市大易产业链服务有限公司 Unit testing method, unit testing device, testing equipment and storage medium

Similar Documents

Publication Publication Date Title
US11934287B2 (en) Method, electronic device and computer program product for processing data
CN113760948A (en) Data query method and device
CN111221869A (en) Method and device for tracking database transaction time and analyzing database lock
CN113448869B (en) Method and device for generating test case, electronic equipment and computer readable medium
CN110806967A (en) Unit testing method and device
CN108959294B (en) Method and device for accessing search engine
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN111488286B (en) Method and device for independently developing Android modules
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN110825622A (en) Software testing method, device, equipment and computer readable medium
CN113127335A (en) System testing method and device
CN112416747A (en) Test case execution method, device, equipment and medium
CN116069725A (en) File migration method, device, apparatus, medium and program product
CN111026629A (en) Method and device for automatically generating test script
CN112783903B (en) Method and device for generating update log
CN113268417B (en) Task execution method and device
CN112559001A (en) Method and device for updating application
CN113688152B (en) System function self-checking method and device
CN113342633B (en) Performance test method and device
CN113835893B (en) Data processing method, device, equipment, storage medium and program product
CN115563183B (en) Query method, query device and program product
CN112181937B (en) Method and device for transferring data
CN116701152A (en) Database performance determining method, device, equipment and medium
CN113760921A (en) Method and device for creating dictionary value
CN113778847A (en) Test report generation method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination