Closure Testing via Annotation-Based Code Insertion

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional methods for testing closures implemented by anonymous functions are inefficient and insecure, as they require code adjustments that violate the purpose of using closures, increase testing workload, and may expose internal interfaces or data, making white-box testing difficult and risky.

Innovation Solution

A method and device for closure testing that involves acquiring an identification of the closure, generating code to be inserted, searching for and adding annotations to determine the closure, and testing the modified closure, allowing internal functions or data to be accessed externally without altering the source code's effective content, thus improving testing efficiency and security.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of operation

If code adjustments are made to expose internal methods or data to external objects for white-box testing, then testing capability is improved, but security and encapsulation are compromised

Engineering Contradiction:
Improvetesting capabilityVSAvoidsecurity
Core Design Contradiction:
Ease of operationVSReliability

Solution Approach 1:

The patent introduces an intermediary mechanism (annotation system and code insertion tool) that mediates between the testing requirements and the closure's encapsulation. The annotation @test allows external test code to access internal closure functions and data without modifying the closure's source code or compromising its security. The system inserts bridging code that creates controlled access paths from external test objects to internal closure elements.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Ease of operation

If code adjustments are made to enable white-box testing of each closure, then testing access is improved, but workload increases

Engineering Contradiction:
Improvetesting accessVSAvoidtesting efficiency
Core Design Contradiction:
Ease of operationVSProductivity

Solution Approach 1:

The patent creates a universal testing mechanism that can be applied to any closure implemented by an anonymous function. The annotation @test and the automated code insertion system provide a multi-functional solution that works across different closure implementations without requiring custom adjustments for each case. This universal approach eliminates the need for repetitive manual code modifications.

Inventive Principle:
Principle #6Universality (Multi-functionality)

Solution Approach 2:

The system enables self-service testing by automatically generating the necessary bridging code based on the @test annotation. The code insertion tool automatically creates the access mechanisms between external test objects and internal closure elements, eliminating the need for manual code adjustment and subsequent verification testing.

Inventive Principle:
Principle #25Self-service

3Ease of operation

If code adjustments are made to expose closure internals for testing, then testing capability is improved, but additional verification testing is required

Engineering Contradiction:
Improvetesting capabilityVSAvoidverification testing time
Core Design Contradiction:
Ease of operationVSLoss of time

Solution Approach 1:

The annotation system acts as an intermediary that clearly marks which closures are intended for testing, allowing the code insertion tool to automatically generate appropriate access code. This automated process eliminates the need for manual verification testing that would otherwise be required to ensure the adjusted code functions correctly.

Inventive Principle:
Principle #24Intermediary (Mediator)

4Ease of operation

If internal interfaces or data are exposed for testing, then testing access is improved, but security risks increase

Engineering Contradiction:
Improvetesting accessVSAvoidsecurity risks
Core Design Contradiction:
Ease of operationVSObject-affected harmful factors

Solution Approach 1:

The system introduces an intermediary layer through the annotation mechanism and automated code insertion. This intermediary allows controlled access to internal closure elements only when explicitly marked with @test, maintaining security for all other closures. The bridging code creates isolated access paths that do not compromise the overall encapsulation security model.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent applies local quality by making testing access available only at specific locations marked with the @test annotation, rather than globally exposing all closure internals. This localized approach allows testing where needed while maintaining security elsewhere, creating different access qualities in different parts of the codebase.

Inventive Principle:
Principle #3Local quality

Data Source

PatentUS9507693B2Method, device and computer-readable storage medium for closure testing
Publication Date: 2016.11.29 TENCENT TECHNOLOGY (SHENZHEN) CO LTD
  • US9507693B2 patent drawing
  • US9507693B2 patent drawing
  • US9507693B2 patent drawing

AI summary

A method for closure testing is disclosed. The method includes: acquiring an identification of a closure to be tested; generating code to be inserted based on the identification of the closure to be tested; searching and obtaining a corresponding annotation based on the identification of the closure to be tested, and determining a closure corresponding to the identification of the closure to be tested based on the annotation; adding the generated code to be inserted to the searched closure; and testing the closure added the code to be inserted. In addition, the present disclosure also discloses a device for closure testing. For the above method and device for closure testing, it reduces the burden of the tester and improves testing efficiency, and the source code published to the network need not to make an internal interface in a closure be exposed for testing, which improves the security of the program.