Use SpringBootContextLoader for tests annotated with @WebMvcTest

Previously, tests annotated with @WebMvcTest would use Spring
Framework’s WebDelegatingSmartContextLoader. This meant that
SpringApplication was not used to create the application context. One
effect of this was that Spring Boot’s logging system was not initialized
and large quantities of debug log output was produced due to Logback’s
default behaviour.

This commit updates WebMvcTestContextBootstrapper so that it uses
SpringBootContextLoader. This aligns the behaviour of @WebMvcTest
with the behaviour of @SpringBootTest and @DataJpaTest.

Closes gh-5847
This commit is contained in:
Andy Wilkinson 2016-05-04 17:15:16 +01:00
parent e58bef5f2b
commit 79b81a95c8

View File

@ -17,10 +17,8 @@
package org.springframework.boot.test.autoconfigure.web.servlet;
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
import org.springframework.test.context.ContextLoader;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContextBootstrapper;
import org.springframework.test.context.web.WebDelegatingSmartContextLoader;
import org.springframework.test.context.web.WebMergedContextConfiguration;
/**
@ -30,12 +28,6 @@ import org.springframework.test.context.web.WebMergedContextConfiguration;
*/
class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
protected Class<? extends ContextLoader> getDefaultContextLoaderClass(
Class<?> testClass) {
return WebDelegatingSmartContextLoader.class;
}
@Override
protected MergedContextConfiguration processMergedContextConfiguration(
MergedContextConfiguration mergedConfig) {