WebTestClient logo

WebTestClient

Open Source

Spring's reactive web test client for testing Spring WebFlux endpoints with fluent assertions.

Visit website

Pricing

Free / Open source

Type

Automation

Languages

Java, Kotlin

// VERDICT

Reach for WebTestClient when you're testing Spring WebFlux or MVC endpoints and want a fluent, in-framework client with no external server. Skip it when you're not on Spring or want a standalone API-testing tool.

Best for

Spring's reactive, fluent client for testing WebFlux and Spring MVC endpoints - in-framework HTTP testing without a running server.

Avoid when

You're not on Spring, or you want a standalone or GUI API client.

CI/CD fit

JUnit · Maven · Gradle · Spring Boot Test · GitHub Actions

Languages

Java · Kotlin

Team fit

Spring/JVM teams · Backend SDET teams · Reactive (WebFlux) teams

Setup

Easy

Maintenance

Low

Learning

Intermediate

Licence

Free / Open source

// BEST FOR

  • Testing Spring WebFlux and Spring MVC endpoints from within the framework
  • Binding directly to the application context - no running server needed
  • A fluent request/exchange/expect assertion style
  • Reactive, non-blocking testing aligned with WebFlux
  • Living inside Spring Boot test slices alongside other Spring tests
  • Asserting status, headers and JSON bodies fluently

// AVOID WHEN

  • Your application isn't built on Spring
  • You want a standalone or GUI API client
  • You need to test arbitrary external APIs, not your Spring app
  • Non-Spring teammates must own the tests
  • Cross-language contract testing is the goal (Pact)
  • You want a tool decoupled from the Spring test lifecycle

// QUICK START

# Add spring-boot-starter-test, bind WebTestClient to the context, then:
./gradlew test

// ALTERNATIVES TO CONSIDER

ToolChoose it when
REST AssuredYou want a framework-agnostic Java API-testing DSL.
OkHttp3You want a general-purpose JVM HTTP client rather than a Spring test client.
SuperTestYou're in JS/Node rather than the JVM.

// FEATURES

  • Fluent API for sending requests and asserting responses
  • Native support for reactive WebFlux endpoints
  • Bind to a controller, application context, or running server
  • JSON path and XPath response body assertions
  • Integrates with Spring Boot test slices

// PROS

  • First-class for Spring WebFlux testing — no extra dependencies
  • Reactive types (Mono/Flux) handled natively
  • Works with both mock and real server modes
  • Tight integration with @WebFluxTest

// CONS

  • Spring-specific — irrelevant outside the JVM Spring world
  • Steeper than REST-assured for non-reactive APIs
  • Documentation assumes Spring familiarity

// EXAMPLE QA WORKFLOW

  1. Add the Spring Boot test starter

  2. Bind WebTestClient to the application context or a controller

  3. Write fluent request/exchange/expect assertions

  4. Cover status, headers and JSON body expectations

  5. Keep tests in Spring Boot test slices

  6. Run in the normal Maven/Gradle test step in CI

// RELATED QA.CODES RESOURCES