langchain4j-testing-strategies
Provides unit test, integration test, and mock AI patterns for LangChain4j applications. Creates mock LLM responses, tests retrieval chains, validates RAG workflows, and implements Testcontainers-based integration tests for Java AI services
Install / Use
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-testing-strategiesInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
AutomationSupported Platforms
Our assessment of langchain4j-testing-strategies
langchain4j-testing-strategies scores 83/100 on our quality scale, 2152nd of 2,885 Automation skills we index.
Its SKILL.md is 7.1 KB long, well organised into 19 sections with 7 code examples: a thorough specification that gives an agent plenty to work with.
It has 353 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated 26 days ago, so langchain4j-testing-strategies is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
langchain4j-testing-strategies compared with similar skills
All 4 of these similar skills score higher than langchain4j-testing-strategies; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| langchain4j-testing-strategies (this skill)by giuseppe-trisciuoglio | 83 | 353 | 26d ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 92.6k | 21d ago | CLAUDE.md |
| Scraplingby D4Vinci | 100 | 86.0k | today | MCP Server |
| rufloby ruvnet | 100 | 74.0k | today | MCP Server |
| algorithmic-artby anthropics | 100 | 177.9k | 14d ago | SKILL.md |
Frequently asked questions
- How do I install langchain4j-testing-strategies?
- Run
npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-testing-strategies. The install tabs above show the steps for each supported agent. - Which AI agents does langchain4j-testing-strategies work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is langchain4j-testing-strategies safe to use?
- It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is langchain4j-testing-strategies still maintained?
- The repository was last updated 26 days ago, so langchain4j-testing-strategies is actively maintained.
Skill content
View source on GitHubname: langchain4j-testing-strategies description: Provides unit test, integration test, and mock AI patterns for LangChain4j applications. Creates mock LLM responses, tests retrieval chains, validates RAG workflows, and implements Testcontainers-based integration tests for Java AI services. Use when unit testing AI services, integration testing LangChain4j components, mocking AI models, or testing LLM-based Java applications. allowed-tools: Read, Write, Edit, Bash, Glob, Grep
LangChain4J Testing Strategies
Overview
Patterns for unit testing with mocks, integration testing with Testcontainers, and end-to-end validation of RAG systems, AI Services, and tool execution.
When to Use
- Unit testing AI services: When you need fast, isolated tests for services using LangChain4j AiServices
- Integration testing LangChain4j components: When testing real ChatModel, EmbeddingModel, or RAG pipelines with Testcontainers
- Mocking AI models: When you need deterministic responses without calling external APIs
- Testing LLM-based Java applications: When validating RAG workflows, tool execution, or retrieval chains
Instructions
1. Unit Testing with Mocks
Use mock models for fast, isolated testing. See references/unit-testing.md.
ChatModel mockModel = mock(ChatModel.class);
when(mockModel.generate(any(String.class)))
.thenReturn(Response.from(AiMessage.from("Mocked response")));
var service = AiServices.builder(AiService.class)
.chatModel(mockModel)
.build();
2. Configure Testing Dependencies
Setup Maven/Gradle dependencies. See references/testing-dependencies.md.
langchain4j-test- Guardrail assertionstestcontainers- Containerized testingmockito- Mock external dependenciesassertj- Fluent assertions
3. Integration Testing with Testcontainers
Test with real services. See references/integration-testing.md.
@Testcontainers
class OllamaIntegrationTest {
@Container
static GenericContainer<?> ollama = new GenericContainer<>(
DockerImageName.parse("ollama/ollama:0.5.4")
).withExposedPorts(11434);
@Test
void shouldGenerateResponse() {
// Verify container is healthy
assertTrue(ollama.isRunning());
await().atMost(30, TimeUnit.SECONDS)
.until(() -> ollama.getLogs().contains("API server listening"));
ChatModel model = OllamaChatModel.builder()
.baseUrl(ollama.getEndpoint())
.build();
// Verify model responds before running tests
assertDoesNotThrow(() -> model.generate("ping"));
String response = model.generate("Test query");
assertNotNull(response);
}
}
4. Advanced Features
Streaming, memory, error handling patterns in references/advanced-testing.md.
5. Testing Workflow
Follow the testing pyramid from references/workflow-patterns.md:
- 70% Unit Tests: Fast, isolated with mocks
- 20% Integration Tests: Real services with health checks
- 10% End-to-End Tests: Complete workflows
70% Unit Tests ─ Mock ChatModel, guardrails, edge cases
20% Integration Tests ─ Testcontainers, vector stores, RAG
10% End-to-End Tests ─ Complete user journeys
Troubleshooting
- Container fails to start: Check Docker daemon is running, verify image exists, increase timeout
- Model not responding: Verify baseUrl is correct, check container logs, ensure model is loaded
- Test timeout: Increase
@Timeoutduration for slow models, check container resource limits - Flaky tests: Add retry logic or health checks before assertions
Examples
Unit Test
@Test
void shouldProcessQueryWithMock() {
ChatModel mockModel = mock(ChatModel.class);
when(mockModel.generate(any(String.class)))
.thenReturn(Response.from(AiMessage.from("Test response")));
var service = AiServices.builder(AiService.class)
.chatModel(mockModel)
.build();
String result = service.chat("What is Java?");
assertEquals("Test response", result);
}
Integration Test with Testcontainers
@Testcontainers
class RAGIntegrationTest {
@Container
static GenericContainer<?> ollama = new GenericContainer<>(
DockerImageName.parse("ollama/ollama:0.5.4")
);
@BeforeAll
static void waitForContainerReady() {
await().atMost(60, TimeUnit.SECONDS)
.until(() -> ollama.getLogs().contains("API server listening"));
}
@Test
void shouldCompleteRAGWorkflow() {
assertTrue(ollama.isRunning());
var chatModel = OllamaChatModel.builder()
.baseUrl(ollama.getEndpoint())
.build();
var embeddingModel = OllamaEmbeddingModel.builder()
.baseUrl(ollama.getEndpoint())
.build();
var store = new InMemoryEmbeddingStore<>();
var retriever = EmbeddingStoreContentRetriever.builder()
.chatModel(chatModel)
.embeddingStore(store)
.embeddingModel(embeddingModel)
.build();
var assistant = AiServices.builder(RagAssistant.class)
.chatLanguageModel(chatModel)
.contentRetriever(retriever)
.build();
String response = assistant.chat("What is Spring Boot?");
assertNotNull(response);
assertTrue(response.contains("Spring"));
}
}
Best Practices
- Use
@BeforeEach/@AfterEachfor test isolation - Never call real APIs in unit tests; use mocks
- Include
@Timeoutfor external service calls - Test both success and error handling scenarios
- Validate response coherence and edge cases
Common Patterns
Mock Strategy
ChatModel mockModel = mock(ChatModel.class);
when(mockModel.generate(anyString())).thenReturn(Response.from(AiMessage.from("Mocked")));
when(mockModel.generate(eq("Hello"))).thenReturn(Response.from(AiMessage.from("Hi")));
when(mockModel.generate(contains("Java"))).thenReturn(Response.from(AiMessage.from("Java")));
Assertion Helpers
assertThat(response).isNotNull().isNotEmpty();
assertThat(response).containsAll(expectedKeywords);
assertThat(response).doesNotContain("error");
Reference Documentation
- Testing Dependencies - Maven/Gradle configuration
- Unit Testing - Mock models, guardrails
- Integration Testing - Testcontainers, real services
- Advanced Testing - Streaming, memory, error handling
- Workflow Patterns - Test pyramid, best practices
Constraints and Warnings
- AI responses are non-deterministic; use mocks for reliable unit tests
- Avoid real API calls in tests to prevent costs and rate limiting
- Integration tests require Docker; use container health checks
- RAG tests need properly seeded embedding stores
- Mock-based tests cannot guarantee actual LLM behavior; supplement with integration tests
- Use test-specific configuration profiles; never affect production data
Related Skills
Agent-Reach
92.6kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Scrapling
86.0k🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
ruflo
74.0k🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
