Method and device for generating Mock base during unit test

A technology of unit testing and method body, applied in software testing/debugging and other directions, can solve problems such as poor maintainability and low reliability of Mock library, and achieve the effect of improving efficiency, saving manpower and material costs, and maintaining good maintainability.

Inactive Publication Date: 2013-01-02
ADVANCED NEW TECH CO LTD
View PDF3 Cites 26 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0006] The technical problem to be solved by this application is to provide a method for generating a Mock library in a unit test, to solve the problems o

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
  • Method and device for generating Mock base during unit test
  • Method and device for generating Mock base during unit test
  • Method and device for generating Mock base during unit test

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0110] Corresponding to the method provided in Example 1 of a method for generating a Mock library in a unit test of the present application, see Figure 5 , the present application also provides a device embodiment 1 for generating a Mock library in a unit test. In this embodiment, the device may include:

[0111] The obtaining original class module 501 is used to obtain each original class that needs to be Mocked in the source code to be tested.

[0112] Obtaining a class parameter module 502, configured to obtain class parameters of each original class through reflection, where the class parameters include: method name, parameter type and return value type.

[0113] The generating module 503 is configured to generate each Mock class corresponding to the original class according to the class parameters.

[0114] refer to Figure 6 As shown, the generating module 503 may specifically include:

[0115] The first generation submodule 601 is configured to generate the class h...

Embodiment 2

[0128] Corresponding to the method provided in Example 1 of a method for generating a Mock library in a unit test of the present application, see Figure 8 , the present application also provides a device embodiment 2 for generating a Mock library in a unit test. In this embodiment, the device also needs to include:

[0129] The throwing module 801 is configured to execute the process of throwing an exception when the Mock method needs to throw an exception.

[0130] And, the testing module 802 is configured to perform unit testing according to the Mock library.

[0131] In this embodiment, when the method needs to throw an exception, the process of throwing an exception can be executed, which meets the different needs in practice. At the same time, the unit test is performed based on the Mock library generated by the embodiment of the present application, which can also improve the unit test. s efficiency.

[0132] The device described in this embodiment can be integrated i...

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 invention provides a method, a device and a system for generating a Mock base during a unit test. The method comprises the following steps of: acquiring each original class to be subjected to Mock of a source code to be tested; acquiring class parameters of each original class through reflection, wherein the class parameters comprise a method name, a parameter type and a returned value type; generating each Mock class corresponding to the original class according to the class parameters; and taking a set consisting of all Mock classes to form the Mock base. By the method and the device disclosed by the embodiment of the invention, the Mock base can be automatically generated, so that a large amount of labors and a large amount of resources are saved; under the condition that the requirement on the quality of codes is relatively high, the forming efficiency of the Mock base can be greatly improved; and furthermore, the reliability can be improved.

Description

technical field [0001] The present application relates to the field of software testing, in particular to a method and device for generating a Mock library in unit testing. Background technique [0002] Unit testing is the lowest level of testing activity to be performed during software development, in which an independent unit of software is tested in isolation from the rest of the program. Therefore, unit testing should not only be used in a one-time development process as an aid to error-free coding, unit testing must also be repeatable, whether it is during the software modification process or after porting to a new operating environment. In the unit test process, for some objects that are not easy to construct or obtain, you can create a virtual object for testing. This virtual object is called a Mock object. Mock objects are substitutes for actual objects during unit testing. [0003] The Mock object is the instantiation of the Mock class. In the prior art, the code ...

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
Inventor 冯照临刘中胜
Owner ADVANCED NEW TECH CO LTD
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products