Testing Reactive REST Endpoints in spring-boot-examples
This test suite demonstrates unit testing of a Spring WebFlux controller using WebTestClient. It validates the basic functionality of a reactive REST endpoint through non-blocking request handling and response verification.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
ityouknow/spring-boot-examples
spring-boot-webflux/src/test/java/com/neo/HelloTests.java
package com.neo;
import com.neo.web.HelloController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
@RunWith(SpringRunner.class)
@WebFluxTest(controllers = HelloController.class)
public class HelloTests {
@Autowired
WebTestClient client;
@Test
public void getHello() {
client.get().uri("/hello").exchange().expectStatus().isOk();
}
}