Automated Mock Object Generation for Unit Testing

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Generating and maintaining mock objects for unit testing is tedious and time-consuming, as developers need to constantly update mock objects whenever the interface or methods of real program objects change.

Innovation Solution

Automatically generating mock objects from descriptions of real objects by parsing the interface and method sets, replicating the interface, and simulating the method set, allowing for dynamic substitution and customization to enhance testing efficiency.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If mock objects are manually created and maintained to achieve isolation in unit testing, then testing reliability is improved, but development time and maintenance effort increase significantly

Engineering Contradiction:
Improvetesting reliabilityVSAvoiddevelopment time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The system automatically generates mock objects by copying the interface structure from real program objects. The mock object generation logic parses the real object's interface definition and creates a corresponding mock object with the same interface but with simulated method implementations, eliminating manual copying effort while maintaining interface compatibility for isolated testing.

Inventive Principle:
Principle #26Copying

Solution Approach 2:

The mock object generation system is self-service in that it automatically generates mock objects from real object definitions without requiring manual intervention. When the real program object changes, the system automatically detects the changes and regenerates the corresponding mock objects, making the maintenance process autonomous and reducing developer workload.

Inventive Principle:
Principle #25Self-service

2Adaptability or versatility

If mock objects are manually updated whenever real objects change to maintain interface consistency, then interface compatibility is improved, but maintenance complexity increases

Engineering Contradiction:
Improveinterface compatibilityVSAvoidmaintenance complexity
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The system implements feedback by monitoring changes in real program objects and automatically triggering mock object regeneration. When the real object's interface or methods are modified, the system detects these changes and propagates them to the corresponding mock objects, ensuring interface compatibility is maintained through automatic feedback loops rather than manual synchronization.

Inventive Principle:
Principle #23Feedback

Solution Approach 2:

The system performs preliminary action by proactively generating mock objects before they are needed for testing. By automatically creating mock objects from real object definitions in advance and continuously synchronizing them, the system ensures interface compatibility is already established before testing begins, eliminating the need for last-minute manual updates.

Inventive Principle:
Principle #10Preliminary action

3Measurement precision

If comprehensive mock objects with full functionality are created, then testing accuracy is improved, but mock object complexity and bug risk increase

Engineering Contradiction:
Improvetesting accuracyVSAvoidmock object complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The system applies local quality by creating mock objects with selective functionality. Instead of replicating all real object behaviors, the mock object generation logic allows customization of which methods are simulated and which are left as stubs. This enables testing accuracy for specific critical paths while keeping the mock object structure simple and manageable.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The system copies only the essential interface structure from real objects rather than duplicating entire implementation details. The mock objects replicate the interface definition and method signatures needed for testing, while using simplified simulated implementations that capture only the necessary behavior for isolated testing, reducing complexity while maintaining testing accuracy.

Inventive Principle:
Principle #26Copying

Data Source

PatentUS10747648B2Mock object generation
Publication Date: 2020.08.18 HOME BOX OFFICE INC
  • US10747648B2 patent drawing
  • US10747648B2 patent drawing
  • US10747648B2 patent drawing

AI summary

Techniques are provided for automatically generating a mock object from a description of a real object, such as for use in testing. Mock object generation logic parses the description to determine interface(s) of the real object, which are replicated in the mock object, and to determine method(s) of the real object, which are simulated in the mock object. The mock object generation logic may generate a description of the mock object that is then compiled into the mock object for execution. Data types may be validated so that the arguments and/or return values from the mock object meet the expectations of a calling object.