Supercharge Your Innovation With Domain-Expert AI Agents!

Unit test method and device, test equipment and storage medium

A unit test and test technology, applied in the test field, can solve the problems of inapplicability, Mock object injection support and poor scalability, etc., to achieve the effect of easy writing and execution, and improved support and scalability

Pending Publication Date: 2021-09-28
东莞市大易产业链服务有限公司
View PDF0 Cites 1 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

The existing technology has poor support and scalability for Mock object injection, and cannot be applied to object (Bean) definitions (such as Dubbo) that are directly registered by some frameworks at Java runtime

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Unit test method and device, test equipment and storage medium
  • Unit test method and device, test equipment and storage medium
  • Unit test method and device, test equipment and storage medium

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0054] figure 1 It is a flow chart of a unit testing method provided by Embodiment 1 of the present invention, and this embodiment is applicable to unit testing. Specifically, the unit testing method can be executed by a unit testing device, which can be realized by means of software and / or hardware, and integrated into a testing device. Further, the test equipment includes, but is not limited to: electronic equipment such as desktop computers, notebook computers, servers, and industrial computers.

[0055] Such as figure 1 As shown, the method specifically includes the following steps:

[0056] S110. Determine a simulated object feature set according to the annotation configuration of the test class of the unit to be tested.

[0057] Wherein, the test class may refer to the class used to execute the test in the unit to be tested. Annotation configuration can refer to performing a feature description on the Bean in the test class, and configuring the Bean corresponding to ...

Embodiment 2

[0066] figure 2 It is a flow chart of a unit testing method provided by Embodiment 2 of the present invention. This embodiment optimizes on the basis of the above embodiments, instantiates objects that do not need to be simulated and creates Spy for objects that do not need to be simulated. The agent process is described in detail. It should be noted that for technical details not exhaustively described in this embodiment, reference may be made to any of the foregoing embodiments.

[0067] Specifically, such as figure 2 As shown, the method specifically includes the following steps:

[0068] S210. Define the post-processing module of the Bean factory through Spring, and create and register the original Bean definition based on the IOC mechanism during the initialization process.

[0069] Among them, the Bean factory post-processing module can refer to a processor that intervenes in the initialization process of the Bean factory. The initialization of the Bean factory can ...

Embodiment 3

[0099] Figure 4 It is a schematic structural diagram of a unit testing device provided by Embodiment 3 of the present invention. The unit testing device provided in this embodiment includes:

[0100] The test configuration module 310 is used to determine the Mock Bean feature set according to the annotation configuration of the test class of the unit to be tested;

[0101] Simulation post-processing module 320, for traversing the original bean definition of Spring registration according to the Mock Bean feature set, to determine the original bean definition that needs Mock; for the original bean definition that needs Mock, create a corresponding Mock Bean definition, And use the Mock Bean definition to replace the original Bean definition that needs Mock;

[0102] The injection module 330 is configured to inject the instance defined by the Mock Bean into the test class through Spring, so that the test module can test the unit to be tested.

[0103] The third embodiment of ...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

The embodiment of the invention discloses a unit test method and device, test equipment and a storage medium. The method comprises the steps of determining a simulation object feature set according to annotation configuration of a test class of a to-be-tested unit; traversing original object definitions registered by Spring according to the simulation object feature set so as to determine original object definitions needing to be simulated; creating a corresponding simulation object definition for the original object definition needing to be simulated, and replacing the original object definition needing to be simulated with the simulation object definition; and injecting an instance defined by the simulation object into the test class through Spring so as to test the to-be-tested unit. According to the technical scheme, before the test method is executed, the original object conforming to the characteristics of the simulation object is specified to be dependent, and instance creation and calling of a real dependent object are replaced, so that Mock writing and execution in the test process are facilitated, and the support degree and expansibility of simulation object instance injection are improved.

Description

technical field [0001] The embodiments of the present invention relate to the technical field of testing, and in particular to a unit testing method, device, testing equipment and storage medium. Background technique [0002] Unit testing refers to checking and verifying the smallest measurable unit in software. The Spring framework is usually used in the unit test process, which is an open source application framework and a lightweight container for managing the life cycle of objects (Bean). Spring Boot further simplifies the entire construction and development process of Spring applications by simplifying configuration. The Mockito support in Spring-Boot-Test is used to realize the dependency injection of mock (Mock) objects in the Spring container. The existing technology has poor support and scalability for Mock object injection, and cannot be applied to object (Bean) definitions (such as Dubbo) that some frameworks directly register at Java runtime. Contents of the ...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
IPC IPC(8): G06F11/36
CPCG06F11/3684G06F11/3688
Inventor 欧燊
Owner 东莞市大易产业链服务有限公司
Features
  • R&D
  • Intellectual Property
  • Life Sciences
  • Materials
  • Tech Scout
Why Patsnap Eureka
  • Unparalleled Data Quality
  • Higher Quality Content
  • 60% Fewer Hallucinations
Social media
Patsnap Eureka Blog
Learn More