Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your Spring AI tests are slow, flaky, and cost money. Here's how to make them deterministic.

You wire up Spring AI, the ChatClient fluent API feels great, your feature works. Then you sit down to write a test — and every good option is bad. A test that calls a real model is: Slow. A hosted call is a second or two; run it on every branch and it adds up. Run inference locally (Ollama + Testcontainers) and a cold call is ~47 s. Either way it's not a loop you run on save. Expensive. Every…

Spring AI integration tests can be slow, flaky, and costly due to the need for real model calls, which can take seconds or even minutes per test run. This becomes expensive as the number of developers and CI jobs increases. Additionally, the same prompt can yield different answers over time, making tests unreliable. Current workarounds like Mockito or WireMock/MockWebServer either require manual effort to build custom responses or fail to test the actual model calls.

A solution called Spring AI Test Tools was developed to address these issues. It allows tests to run against a real model initially, recording the interaction as a cassette file, and then replaying it instantly for subsequent runs. This approach eliminates network calls, tokens spent, and ensures deterministic results. The library provides a simple way to enable caching with a single property file change, and it integrates seamlessly with Spring AI without needing to modify tests.

The tool verifies various aspects of the model calls, such as tool/function calling, streaming, structured output, and embeddings. It is designed to work with Java 21, Spring Boot 4.0.0, and Spring AI 2.0.0.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Nvidia's Risky Business

Article URL: https://stratechery.com/2026/nvidias-risky-business/ Comments URL: https://news.ycombinator.com/item?id=49255710 Points: 228 # Comments: 96

More from Tuesday 11 August →