Annotation Type WebMvcTest
@Documented
@Inherited
@Retention(RUNTIME)
@Target(TYPE)
@ResourceLock("com.codename1.backend.test.BackendTest")
public @interface WebMvcTest
Tests controllers without the rest of the application: what Spring's
@WebMvcTest does.
The build wires the controllers this names -- every controller when it names
none -- with what serves their requests: the @ControllerAdvice and
@RestControllerAdvice classes, and the HandlerInterceptor and
ExceptionResolver components. No service, repository or database is
built. Whatever a controller needs beyond that comes from the test, as a
MockitoBean, a TestConfiguration bean, or a class named in includes().
A dependency nothing supplies fails the build, naming the controller and the
type it asked for, so a slice never starts half wired.
The test reaches the controllers through MockMvc, in process.
@WebMvcTest(GreetingApi.class)
class GreetingApiSliceTest {
@Autowired MockMvc mvc;
@MockitoBean Greetings greetings;
...
}
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]TestConfigurationclasses to add, asBackendTest.classes().Class<?>[]The same asvalue(), for a test that reads better naming it.Class<?>[]Components and configurations of the application to wire into the slice as well -- what Spring's@Importadds to one.The profile, asBackendTest.profile().String[]Settings for this test, askey=value, asBackendTest.properties().Class<?>[]The controllers to test; every controller of the module when empty.
-
Element Details
-
value
-
controllers
-
includes
Class<?>[] includesComponents and configurations of the application to wire into the slice as well -- what Spring's@Importadds to one. Each must be a bean class of the module.- Default:
{}
-
properties
-
profile
-
classes
-