Unit testing method and system

A unit test and sub-unit technology, applied in software testing/debugging, error detection/correction, instruments, etc., can solve problems such as failure to meet test code coverage requirements, and achieve the effect of ensuring code quality

Active Publication Date: 2020-04-14
HEFEI GOCOM INFORMATION &TECH CO LTD
View PDF4 Cites 0 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0003] However, when there are statements in the function under test that access private member fields, or if the function itself is a private function, it cannot be accessed because of the protection level restriction, so it cannot directly modify the parameter value of the method in the test case, which cannot meet the requirements of the test code. Coverage requirements, but in order to ensure the validity of the code, unit testing is essential

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 testing method and system
  • Unit testing method and system
  • Unit testing method and system

Examples

Experimental program
Comparison scheme
Effect test

Embodiment Construction

[0050] To further illustrate the features of the present invention, please refer to the following detailed description and accompanying drawings of the present invention. The attached drawings are for reference and description only, and are not intended to limit the protection scope of the present invention.

[0051] like figure 1 As shown, this embodiment discloses a unit testing method for unit testing a function or private function containing private members, including the following steps S1 to S3:

[0052] S1. Find the test file where the original test case is located, and add a reference to the reflected namespace in the header of the test file;

[0053] S2. Use reflection to access private members or private functions and write new test cases;

[0054] S3. According to the new test case, execute the unit test code and generate a test report.

[0055] Specifically, as figure 2 As shown in the figure, when unit testing a function containing private members, the above ...

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 discloses a unit testing method and system, and belongs to the technical field of software unit testing. The method comprises the following steps: searching for a test file where an original test case is located, and adding a reference of a reflected namespace to the head of the test file; writing a new test case by using the reflection access private member or private function; andexecuting the unit test code according to the new test case, and generating a test report. A unit test case is compiled by viewing and calling classes and methods of a program set by utilizing C# reflection, dynamically creating instances of types by utilizing reflection, binding the types to an existing object or obtaining the types from the existing object and calling methods of the types or accessing fields and attributes of the types, so that the unit test coverage rate requirement is met.

Description

technical field [0001] The invention relates to the technical field of software unit testing, in particular to a unit testing method and system. Background technique [0002] When doing C# unit testing in VS2012, the principle for modifying test cases to meet test coverage is: for the execution path, each independent path in the module is required to be tested; each statement in the module is executed at least once to satisfy each Branches are covered at least once. [0003] However, when there is a statement that accesses private member fields in the function under test, or it is a private function, it cannot be accessed because of the protection level restriction, so it is impossible to directly modify the parameter value of the method in the test case, which cannot meet the requirements of the test code. Coverage requirements, but in order to ensure the validity of the code, unit testing is essential. SUMMARY OF THE INVENTION [0004] The purpose of the present invent...

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
Patent Type & Authority Applications(China)
IPC IPC(8): G06F11/36
CPCG06F11/3676G06F11/3684Y02D10/00
Inventor 魏臻程磊汤俊方莹徐自军胡庆新程运安徐伟黄鹏
Owner HEFEI GOCOM INFORMATION &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