Replication package for paper Test vs Mutant: Adversarial LLM Agents for Robust Unit Test Generation. (Accepted by ISSTA 2026)
initial_generate_testcase() -> initial_generate_mutant()
| |
Compile & run tests Run mutation testing
| |
+--- Iterative Enhancement Loop (up to 4 rounds) ---+
| TC_ENHANCE (new tests for survived mutants) |
| MT_ENHANCE (new mutants for uncovered lines) |
| Alternating: TC -> MT -> TC -> MT |
+----------------------------------------------------+
|
bug_detection_ourgen() -> Compare fixed vs buggy version
Convergence targets: Mutation Score >= 70%, Coverage >= 95%, max 4 enhancement rounds.
- Java JDK 8+
- Defects4J v2.1.0 (install and add to
PATH) - Ant / Maven (for Defects4J builds)
- Git
pip install openai langchain javalang tenacity httpx tqdm# For the main Defects4J pipeline (model.py):
export DEEPSEEK_API_KEY="your-deepseek-api-key"
# Or use any OpenAI-compatible API by passing api_key and base_url to LLMWrapper
# For the Python evaluation pipeline (python_eval/):
export LLM_API_KEY="your-api-key"
export LLM_BASE_URL="https://api.deepseek.com"
export LLM_MODEL="deepseek-chat"Follow the Defects4J installation guide to install v2.1.0. Ensure defects4j is on your PATH.
git clone https://github.com/rjust/defects4j.git
cd defects4j
git checkout v2.1.0
cpanm --installdeps .
./init.sh
export PATH=$PATH:$(pwd)/framework/binApply the included patch to add JUnit 5, Mockito, and other required changes to Defects4J:
cd /path/to/defects4j
git apply /path/to/defects4j_setup.patchThis patch makes the following changes:
-
framework/projects/defects4j.build.xml-- Adds 7 JAR dependencies to the build classpath (compilation and test execution):<property name="junit5-api.jar" value="/path/to/lib/junit-jupiter-api-5.9.3.jar"/> <property name="junit5-engine.jar" value="/path/to/lib/junit-jupiter-engine-5.9.3.jar"/> <property name="junit5-platform.jar" value="/path/to/lib/junit-platform-commons-1.9.3.jar"/> <property name="mock-junit.jar" value="/path/to/lib/mockito-junit-jupiter-4.11.0.jar"/> <property name="objnesis.jar" value="/path/to/lib/objenesis-3.2.jar"/> <property name="mockito.jar" value="/path/to/lib/mockito-core-4.11.0.jar"/> <property name="byte-buddy.jar" value="/path/to/lib/byte-buddy-1.14.4.jar"/>
Important: After applying the patch, update the JAR paths in
defects4j.build.xmlto point to the absolute path of thelib/directory in your replication package. -
framework/core/Utils.pm-- Adds-mflag to tar extraction to prevent permission errors (Cannot utime: Operation not permitted) when the working directory is not owned by the current user.
Edit download.py to specify the projects and bug counts you need, then run:
python download.pyThis checks out fixed versions to ./defects4j_fixed/{Project}/{Project}_{id}_fixed/ and buggy versions to ./defects4j_bug/{Project}/{Project}_{id}_bug/.
Edit generate.py line 15 to set your LLM:
llm = Deepseek(api_key="your-api-key", model="deepseek-chat")The model.py file provides GPT and Deepseek wrapper classes. Both read API keys from environment variables if available.
# Edit generate.py to set project name and bug range, then:
python generate.pyKey parameters in generate.py:
projname-- Defects4J project (e.g.,'Math','Chart','Closure')max_workers-- number of parallel threads- Bug range in
ThreadPoolExecutor-- e.g.,range(0, 106)for Math
Chart, Cli, Closure, Codec, Collections, Compress, Csv, Gson, JacksonCore, JacksonDatabind, JacksonXml, Jsoup, JxPath, Lang, Math, Mockito, Time
- Logs:
AdverTest_*.log - Mutants (raw):
./Mutants/{source}/raw/{Project}-{id}.json - Mutants (tested):
./Mutants/{source}/tested/{Project}-{id}_test.json - Test archives:
./defects4j_fixed/{Project}/{Project}_{id}_fixed/gentest/
The python_eval/ directory contains a port of AdverTest for Python projects, targeting SWE-bench instances.
-
Place the dataset files in
python_eval/data/. -
Set API keys:
export LLM_API_KEY="your-api-key" export LLM_BASE_URL="https://api.deepseek.com"
cd python_eval
python generate_tests.py --model deepseek-chat --instance <instance_id>bash run_harness.sh| File | Description |
|---|---|
generate.py |
Main orchestrator with parallel execution |
function.py |
Patch parsing, test/mutant generation, mutation testing |
model.py |
LLM wrappers (Deepseek, GPT) with retry logic |
enhance_testcase.py |
TC_ENHANCE: generates new tests for survived mutants |
enhance_mutants.py |
MT_ENHANCE: generates new mutants for uncovered lines |
test.py |
Bug detection: runs tests on fixed vs buggy versions |
coverage.py |
Parses Cobertura XML for coverage metrics |
extract.py |
Java class structure parsing via javalang AST |
testIniGenPrompt.py |
Prompt construction, test extraction, compile & run |
compress.py |
Archives generated test directories |
config.py |
Shared logging configuration |
copy_files.py |
Copies generated test archives to output directories |
download.py |
Downloads Defects4J fixed and buggy project versions |
| File | Description |
|---|---|
generate_tests.py |
Main test generation for Python projects |
prompt.py |
Prompt templates for Python test generation |
mutant.py |
Mutation logic for Python code |
enhance.py |
Enhancement rounds (TC + MT) |
coverage_py.py |
Python coverage parsing |
diff_builder.py |
Builds diffs for SWE-bench predictions |
validate.py |
Test validation and syntax checking |
compile_results.py |
Results compilation |
run_extra_rounds.py |
Run additional enhancement rounds |
run_harness.sh |
SWE-bench evaluation harness |
Generated tests from baseline methods and AdverTest for the case study section in the paper. Contains test examples from five tools:
AdverTest/-- Tests generated by AdverTestChatUniTest/-- Tests generated by ChatUniTestEvosuite/-- Tests generated by EvoSuiteHITS/-- Tests generated by HITSRandoop/-- Tests generated by Randoop
JUnit 5 (5.9.3), Mockito 4 (4.11.0), ByteBuddy (1.14.4), Objenesis (3.2) -- added to Defects4J build classpath for test compilation.