Mock Method and device for unit test of C++
A unit test and sub-process technology, applied in the computer field, can solve problems such as joining and not being able to be implemented on the Linux platform
- Summary
- Abstract
- Description
- Claims
- Application Information
AI Technical Summary
Problems solved by technology
Method used
Image
Examples
Embodiment 1
[0037] In this embodiment, a method of Mocking the C++ unit test is provided, figure 1 It is a flowchart of a method for Mocking a C++ unit test according to an embodiment of the present invention, such as figure 1 As shown, the process includes the following steps:
[0038] Step S102, before the mocked function is called, modify the first instruction of the mocked function to a jmp instruction;
[0039] Step S104, when the mocked function is called and executed, directly jump to the substitute function corresponding to the jmp instruction for execution.
[0040] Through the above steps, before referencing the Mocked function to run, Mock the function that needs to be shielded, modify it when the program is running, restore it to achieve Mock, and will not pollute the project code, which solves the need for Mock processing in the prior art Intrusive" testing code or technical problems that cannot be implemented on the Linux platform.
[0041] Optionally, the execution subje...
Embodiment 2
[0064] In this embodiment, a device for mocking a C++ unit test is also provided, and the device is used to implement the above embodiments and preferred implementation modes, and those that have already been explained will not be repeated. As used below, the term "module" may be a combination of software and / or hardware that realizes a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementations in hardware, or a combination of software and hardware are also possible and contemplated.
[0065] Figure 5 It is a structural block diagram of a device for Mocking a C++ unit test according to an embodiment of the present invention, such as Figure 5 As shown, the device includes:
[0066] The modification module 50 is used to modify the first instruction of the mocked function into a jmp instruction before the mocked function is called;
[0067] The jump module 52 is configured to directly jump to th...
Embodiment 3
[0073] This embodiment describes the application in detail in conjunction with specific examples:
[0074] This embodiment is implemented based on the ptrace system call in the Linux system, and can perform dynamic Mock processing on non-virtual functions at the assembly or binary level. In the whole process, before the child process calls the Mocked function, notify the parent process to modify the Mocked function; the first instruction of the modified Mocked function is the jmp instruction, that is, jump to the Mocked function; after running the Mocked function , restore the modified data.
[0075] The steps for using this technical solution include:
[0076] S11. Introduce this technical solution through source code, and integrate the source code into the unit test code of the project. That is, it is compiled together with the project code.
[0077] S12, before the unit test is run, the assemblemock::Setup function is generally called directly in the main function to ini...
PUM

Abstract
Description
Claims
Application Information

- R&D
- Intellectual Property
- Life Sciences
- Materials
- Tech Scout
- Unparalleled Data Quality
- Higher Quality Content
- 60% Fewer Hallucinations
Browse by: Latest US Patents, China's latest patents, Technical Efficacy Thesaurus, Application Domain, Technology Topic, Popular Technical Reports.
© 2025 PatSnap. All rights reserved.Legal|Privacy policy|Modern Slavery Act Transparency Statement|Sitemap|About US| Contact US: help@patsnap.com