giuseppe-trisciuoglio avatar

Langchain4j Testing Strategies

Testing LangChain4j apps means dealing with non-deterministic LLM responses, which makes traditional testing a pain. This skill gives you the full spectrum: mock ChatModel responses with Mockito for fast unit tests, spin up real Ollama instances with Testcontainers for integration tests, and validate complete RAG workflows end-to-end. The code samples show proper health checks and await patterns so your tests don't flake when containers are slow to start. Honestly, the 70/20/10 testing pyramid guidance is the most useful part here. It keeps you from over-relying on expensive integration tests while still catching real issues that mocks miss.

skills.sh installs
3.8K
GitHub stars
369
last updated
Aug 21, 2026

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-testing-strategies --agent claude-code

Installs into .claude/skills of the current project.

Files

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.

Sponsors

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, AI & Agent Building, Java & JVM
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 102
1langgenius avatarfrontend-testinglanggenius/difyUse when writing or changing Vitest or React Testing Library tests under `web/` or `packages/dify-ui/`, or when the user explicitly requests frontend test strat3.8Kskills.sh installs
2forcedotcom avatartesting-agentforceforcedotcom/sf-skillsWrite, run, and analyze structured test suites for Agentforce agents. TRIGGER when: user writes or modifies test spec YAML (AiEvaluationDefinition); runs sf age3.6Kskills.sh installs
3onmax avatarvitestonmax/nuxt-skillsUse when writing unit/integration tests for Vite projects - configure vitest.config.ts, write test suites with describe/it, create mock implementations with vi.3.2Kskills.sh installs
4browserbase avatarui-testbrowserbase/skillsAI-powered adversarial UI testing via the browse CLI. Analyzes git diffs to test only what changed, or explores the full app to find bugs. Tests functional corr3.1Kskills.sh installs
5supabase avatarvitestsupabase/supabaseVitest API and config reference (Jest-compatible) — mocking with vi.*, spies, fake timers, coverage configuration, fixtures, snapshots, and test filtering. Use 2.8Kskills.sh installs
6sergiodxa avatarfrontend-testing-best-practicessergiodxa/agent-skillsTesting best practices for the frontend. Emphasizes E2E tests over unit tests, minimal mocking, and testing behavior over implementation details. Use when writi2.2Kskills.sh installs