SpringBoot WebFlux Test – @WebFluxTest

In the tutorial, JavaSampleApproach will show you how to work with SpringBoot WebFlux Tests using @WebFluxTest.

Related posts:
SpringBoot WebFlux Annotation-based RestAPIs
Spring WebClient with Spring Webflux RestAPIs | SpringBoot 2

I. Technologies

– Java: 1.8
– Maven: 3.3.9
– Spring Tool Suite: Version 3.9.0.RELEASE
– Spring Boot: 2.0.0.M4
– Spring Boot Starter Webflux

II. SpringBoot WebFlux Tests

@WebFluxTest helps to test Spring WebFlux controllers with auto-configuring the Spring WebFlux infrastructure, limit scanned beans like {@Controller, @ControllerAdvice, @JsonComponent, WebFluxConfigurer} and never scan @Component beans.

@WebFluxTest will auto-configures WebTestClient to quickly test WebFlux controllers without starting a full HTTP server.

III. Practice

We create a SpringBoot project as below:

SpringBoot WebFlux test - project structure

Step to do:
– Create SpringBoot project
– Define data model
– Implement WebFlux APIs
– Implement Testcases
– Run and check results

1. Create SpringBoot project

– Using SpringToolSuite to create a SpringBoot project with spring-boot-starter-webflux dependency:

2. Define data model

– Define a Customer model:

3. Implement WebFlux APIs

Refer at SpringBoot WebFlux Annotation-based RestAPIs

– Implement a WebFlux RestControllerAPIs:

4. Implement Testcases

5. Run and check results

– Run unit-test as below image:

SpringBoot WebFlux test - run unitest

-> Results:

SpringBoot WebFlux test - results

IV. Sourcecode


By JavaSampleApproach | October 4, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *