r/SpringAIDev • • 23h ago

Discussion Regression tests for Spring AI features that don't break randomly: repeated runs, pass-rate baselines, record/replay

1 Upvotes

A normal test runs once and passes or fails. An LLM answer can pass 7 times out of 10, so a strict assertion either breaks the build at random or someone turns it off. I kept hitting this with Spring AI, so I built a small JUnit 5 extension for it.

How it works:

  • @EvalTest(runs = 10) runs a test several times and reports the pass rate with a 95% confidence interval
  • The result is compared with a baseline file in your repo. The build fails only when the pass rate really drops (Fisher exact test), so 9/10 then 8/10 is treated as noise, but 10/10 then 5/10 fails
  • RecordingChatModel records real model answers once and replays them in CI, so normal builds are offline and free
  • Datasets (JSONL/CSV), scores between 0 and 1, parallel runs, token cost tracking, and Spring Boot autoconfiguration that wraps your ChatModel bean

It's on Maven Central (0.2.0), Java 21, Spring AI 1.0.

https://github.com/rrezartprebreza/spring-ai-eval-baseline

I'd like feedback from anyone testing LLM features in Java, especially on the default thresholds.