2017-10-11 04:12:12 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[[testing]]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								= Testing
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-29 21:44:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								[.small]#<<web-reactive.adoc#webflux-test,Same in Spring WebFlux>>#
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-11 04:12:12 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								This section summarizes the options available in `spring-test` for Spring MVC applications.
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 02:24:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								**Servlet API Mocks**
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 02:24:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Mock implementations of Servlet API contracts for unit testing controllers, filters, and
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								other web components. See <<testing.adoc#mock-objects-servlet,Servlet API>> mock objects
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								for more details.
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 02:24:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								**TestContext Framework**
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 02:24:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								Support for loading Spring configuration in JUnit and TestNG tests including efficient
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								caching of the loaded configuration across test methods and support for loading a
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`WebApplicationContext` with a `MockServletContext`.
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-11 04:12:12 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								See <<testing.adoc#testcontext-framework,TestContext Framework>> for more details.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								**Spring MVC Test**
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-11 04:12:12 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								A framework, also known as `MockMvc`, for testing annotated controllers through the
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-29 21:44:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								`DispatcherServlet`, i.e. supporting annotations and complete with Spring MVC
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								infrastructure, but without an HTTP server. See
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								<<testing.adoc#spring-mvc-test-framework,Spring MVC Test>> for more details.
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 02:24:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								**Client-side REST**
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-11 04:12:12 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								`spring-test` provides a `MockRestServiceServer` that can be used as a mock server for
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								testing client-side code that internally uses the `RestTemplate`.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								See <<testing.adoc#spring-mvc-test-client,Client REST Tests>> for more details.
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-29 21:44:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								**WebTestClient**
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-29 21:44:53 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-07 01:16:31 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								`WebTestClient` was built for testing WebFlux applications but it can also be used for
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end-to-end integration testing, to any server, over an HTTP connection. It is a
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								non-blocking, reactive client and well suited for testing asynchronous and streaming
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								scenarios.
							 |