This project is a Python-based prototype tool designed to automate the adaptation and integration of existing Java unit test cases from one software fork into another. It leverages Large Language Models (LLMs) to diagnose integration failures and suggest code modifications to make test cases compatible with the target project. This tool includes comprehensive metrics tracking and performance analysis capabilities. This tool is being developed as part of a Bachelor thesis.
The tool follows these main steps:
-
Input:
- A specific Java unit test case (as source code).
- The target Java project's relevant source code (Unit Under Test - UUT).
- Supports both local dummy projects and real dataset processing.
- Designed with the Mukelabai et al. ASE 2023 benchmark dataset in mind.
-
Pre-Build Validation:
- Validates that the target project builds correctly before adaptation.
- Automatically attempts to fix common build configuration issues (pom.xml).
- Records pre-build success/failure in metrics.
-
Initial Adaptation Attempt:
- Places the source test case into the target project with correct package structure.
- Attempts initial compilation.
-
Iterative Build & LLM Analysis:
- Supports multiple adaptation attempts (configurable, default: 3).
- On build failure:
- Parses Maven error messages with detailed categorization.
- Constructs context-aware prompts for LLM analysis.
- Extracts clone type classifications (Type-1 through Type-4) from LLM responses.
- Applies suggested fixes and retries compilation.
-
Comprehensive Metrics Tracking:
- Tracks success rates, error types, execution times, and LLM usage.
- Records clone classifications and adaptation attempt patterns.
- Generates detailed performance reports and summaries.
- Programming Language: Python (3.10+)
- LLM APIs:
- Google Gemini API (
google-generativeai)
- Google Gemini API (
- Data Processing:
requests(for GitHub API interaction)- JSON-based metrics storage and analysis
- Environment Management:
python-dotenv(for API keys)venv(for virtual environments)
- Java Build System Interaction:
subprocess(to invoke Maven for compiling and testing Java projects)
- Metrics & Analysis:
- Built-in performance tracking and statistical analysis
Testcase-Adaptation-LLM/
|-- .env # For API keys (GITIGNORED)
|-- .gitignore
|-- adaptation_metrics.json # Generated metrics and performance data
|-- CONTEXT.md # Detailed project context for AI assistants
|-- create_dummy_projects.py # Script to set up dummy Java projects for testing
|-- dummy_java_projects/ # Dummy Java projects (ProjectA, ProjectB) (GITIGNORED)
| |-- ProjectA/
| |-- ProjectB/
|-- requirements.txt # Python dependencies
|-- src/ # Main source code
| |-- main.py # Orchestrates the workflow
| |-- llm_analyzer.py # Functions for LLM interaction and prompt construction
| |-- java_env_manager.py # Functions to manage Java build/test execution
| |-- utils.py # Utility functions (error parsing, code extraction)
| |-- metrics_tracker.py # Comprehensive metrics tracking and analysis
| |-- process_dataset.py # Dataset processing for batch operations
| |-- test_apis.py # Scripts for testing LLM API connections
|-- data/ # Dataset and project storage
| |-- projects/ # Cloned target projects
|-- README.md # This file
- Categorizes Maven compilation errors (cannot find symbol, package does not exist, etc.)
- Extracts specific error details (symbol names, locations, types)
- Handles environment errors and unknown error types gracefully
- Context-aware prompt construction including:
- Original test case code
- Target class implementation
- Build configuration (pom.xml)
- Specific error details
- Automatic extraction of Java code blocks from LLM responses
- Clone type classification extraction (Type-1 through Type-4)
- Adaptation Success Rates: Overall and per-attempt success tracking
- Error Analysis: Distribution of error types and patterns
- LLM Usage Metrics: Response lengths and classification accuracy
- Timing Analysis: Execution time statistics and bottleneck identification
- Build Configuration: Pre-build failures and automatic fixes applied
- GitHub API integration for fetching source test cases
- Support for processing benchmark datasets
- Batch processing capabilities for multiple test case adaptations
-
Clone the repository:
git clone <repository-url> cd Testcase-Adaptation-LLM
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up API Keys:
- Create a
.envfile in the project root (Testcase-Adaptation-LLM/.env). - Add your API keys to the
.envfile:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
- Ensure
.envis listed in your.gitignorefile (it is, by default).
- Create a
-
Create Dummy Java Projects (for testing):
python create_dummy_projects.py
The main workflow is orchestrated by src/main.py. You can configure it to use either dummy projects or real dataset:
cd src
python main.pyIn main.py, set USE_DUMMY_PROJECTS = True for testing with dummy projects, or False for real dataset processing.
For real dataset processing:
-
Clone target repositories:
mkdir -p data/projects git clone https://github.com/dbrambilla/jesque.git data/projects/jesque
-
Configure source and target:
- Edit the repository and file paths in
main.py - The tool will automatically fetch source test cases from GitHub
- Edit the repository and file paths in
After running adaptations, view comprehensive metrics:
python -c "from metrics_tracker import global_metrics; global_metrics.print_summary()"Metrics are automatically saved to adaptation_metrics.json with detailed statistics including:
- Success rates and attempt distributions
- Error type categorization
- Clone classification results
- Performance timing analysis
{
"summary": {
"total_adaptations": 2,
"successful_adaptations": 2,
"success_rate": 1.0,
"classification_distribution": {
"Type-2": 1
},
"success_by_attempt": {
"1": 1,
"2": 1
},
"error_type_distribution": {
"cannot find symbol": 1
},
"average_execution_time_seconds": 18.49
}
}The tool supports up to 3 adaptation attempts by default, using iterative LLM feedback to refine solutions.
Automatically detects and attempts to fix common Maven build issues, particularly pom.xml configuration problems.
Extracts and records clone type classifications (Type-1 through Type-4) from LLM responses for research analysis.
Direct integration with GitHub API for fetching source test cases from repositories, enabling seamless dataset processing.
- The tool is designed for the Mukelabai et al. ASE 2023 benchmark evaluation.
- Comprehensive metrics collection enables detailed performance analysis and research insights.
- The architecture supports extension to additional LLM providers and build systems.
- Error parsing is specifically tuned for Maven/Java compilation errors.
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is currently unlicensed. (Consider adding an OSI approved license like MIT or Apache 2.0).