Execution-Based Feedback for Accurate LLM Unit Test Generation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current large language models (LLMs) struggle with generating accurate and controlled unit tests due to issues such as hallucination, incorrect type errors, and uncontrolled generation, which hinder the quality of automatically generated code tests.

Innovation Solution

A framework that utilizes a self-correction feedback loop and synthetic data generation technique to fine-tune LLMs, enabling them to learn from error feedback and correct mistakes, thereby improving the quality of generated unit tests.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If LLMs are used to generate unit tests automatically, then productivity is improved, but manufacturing precision deteriorates due to hallucination and type errors

Engineering Contradiction:
Improvetest generation speedVSAvoidtest correctness
Core Design Contradiction:
ProductivityVSManufacturing precision

Solution Approach 1:

The patent implements a feedback mechanism where execution results of generated tests are fed back to the LLM. When a test fails or produces unexpected results, the LLM receives this feedback and generates corrected test cases, iteratively improving test quality while maintaining automated generation

Inventive Principle:
Principle #23Feedback

Solution Approach 2:

The patent replaces the LLM's probabilistic guessing mechanism with deterministic execution-based validation. Instead of relying solely on the LLM's predictive capabilities, the system uses actual code execution results to verify and correct generated tests, substituting statistical inference with empirical verification

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

2Ease of operation

If LLMs generate tests based on probabilities, then ease of operation is improved, but reliability deteriorates due to uncontrolled generation

Engineering Contradiction:
Improveautomatic test generationVSAvoidgeneration control
Core Design Contradiction:
Ease of operationVSReliability

Solution Approach 1:

The patent applies preliminary constraints by defining specific test templates, parameter types, and validation rules before the LLM generates tests. These pre-established structures guide the LLM's probabilistic generation to produce only valid, controlled test cases while maintaining ease of automatic generation

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The execution-based feedback loop monitors generated tests and provides correction signals to the LLM, ensuring that probabilistic generation remains within acceptable boundaries and reliably produces valid test cases

Inventive Principle:
Principle #23Feedback

3Device complexity

If LLMs guess next characters instead of computing, then device complexity is reduced, but measurement precision deteriorates due to mathematical reasoning errors

Engineering Contradiction:
Improvemodel simplicityVSAvoidcomputation accuracy
Core Design Contradiction:
Device complexityVSMeasurement precision

Solution Approach 1:

The patent introduces an intermediary execution environment between the LLM's probabilistic output and the final test result. The LLM generates test cases based on character prediction, but the execution environment acts as an intermediary to validate and correct computational accuracy through actual code execution

Inventive Principle:
Principle #24Intermediary (Mediator)

Data Source

PatentUS20250245487A1Execution-based feedback-enhanced large language model for test generation
Publication Date: 2025.07.31 ORACLE INT CORP
  • US20250245487A1 patent drawing
  • US20250245487A1 patent drawing
  • US20250245487A1 patent drawing

AI summary

Techniques for automatically generating tests using a large language model (LLM) are provided. In one technique, a set of positive training samples for training a first LLM is stored. Based on that set, a set of correction training samples is generated, each sample including an error from processing a faulty test of particular code. A second LLM is trained based on those samples. A first test, of code, that was generated by the first LLM is received. A first result of processing the first test is generated. In response to determining that the first result indicates an error in processing the first test, a first correction prompt is generated based on the first result. The first correction prompt is input into the second LLM that outputs a second test that is a corrected version of the first test. A second result of processing the second test is generated.