This demo uses FasterXML/jackson-core, a real open-source Java library.
The goal is to show the full workflow:
- target one low-coverage class
- generate a JUnit test
- run Maven validation
- repair failures when needed
- leave reviewable coverage and run artifacts
git clone https://github.com/zemeng2015/JTestGen.git
cd JTestGen
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e .
git clone https://github.com/FasterXML/jackson-core.git C:\tmp\jackson-coreSet your API key:
$env:OPENAI_API_KEY="..."Optional readiness check:
java-testgen doctor C:\tmp\jackson-coreOptional target scan without calling an LLM:
java-testgen scan C:\tmp\jackson-core --top 5 --verify-arg=-DskipITsOptional model override:
$env:OPENAI_MODEL="gpt-4o-mini"If Maven is already on your PATH, run:
java-testgen run C:\tmp\jackson-core `
--target-class tools.jackson.core.io.DataOutputAsStream `
--test-suffix GeneratedTest `
--target-coverage 0.80 `
--verify-arg=-DskipITsIf Maven is not on your PATH, pass the executable explicitly:
java-testgen run C:\tmp\jackson-core `
--target-class tools.jackson.core.io.DataOutputAsStream `
--test-suffix GeneratedTest `
--target-coverage 0.80 `
--maven-command C:\tmp\apache-maven-3.9.11\bin\mvn.cmd `
--verify-arg=-DskipITsFor a pilot audit, you can also process up to three automatically selected targets and write a patch:
java-testgen run C:\tmp\jackson-core `
--max-targets 3 `
--test-suffix GeneratedTest `
--target-coverage 0.80 `
--patch-output C:\tmp\jtestgen-jackson-core.patch `
--verify-arg=-DskipITsSelected target: tools.jackson.core.io.DataOutputAsStream with 55.56% line coverage
Repairing DataOutputAsStreamGeneratedTest, attempt 1/3
Generated test passed
Generation report
- Target class: tools.jackson.core.io.DataOutputAsStream
- Class line coverage: 55.56% -> 100.00%
- Class covered lines: 5/9 -> 9/9
- Project line coverage: 81.72% -> 81.75%
When presenting JTestGen, do not describe it as "AI generated a test." The stronger message is:
JTestGen turns a Java coverage gap into a Maven-passing, reviewable test improvement artifact.
Show these four things:
- the target class and baseline coverage
- the generated test file
- Maven pass/fail logs and repair attempts
summary.mdorreport.htmlwith before/after coverage- optional
generated.patchor--patch-outputfile for code review
Each run writes observability artifacts under the target project:
.jtestgen/runs/<run-id>/
report.json
summary.md
report.html
prompt.initial.system.txt
prompt.initial.user.txt
prompt.repair.1.system.txt
prompt.repair.1.user.txt
maven.baseline.log
maven.test.0.log
maven.test.1.log
maven.final.log
generated.initial.java
generated.repair.1.java
generated.final.java
generated.patch
These files make the LLM workflow inspectable and reproducible.
The demo writes a generated test into the target repo. If you want to reset jackson-core afterward:
cd C:\tmp\jackson-core
git status
git clean -fd .jtestgen
git restore src/test/javaSee also: