Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

@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;
    ...
}

Methods

public abstract Class<?>[] value() default {}The controllers to test; every controller of the module when empty.
public abstract Class<?>[] controllers() default {}The same as value, for a test that reads better naming it.
public abstract Class<?>[] includes() default {}Components and configurations of the application to wire into the slice as well – what Spring’s @Import adds to one.
public abstract String[] properties() default {}Settings for this test, as key=value, as BackendTest.properties.
public abstract String profile() default "test"The profile, as BackendTest.profile.
public abstract Class<?>[] classes() default {}TestConfiguration classes to add, as BackendTest.classes.

Method details

value

public abstract Class<?>[] value() default {}
The controllers to test; every controller of the module when empty.

controllers

public abstract Class<?>[] controllers() default {}
The same as value, for a test that reads better naming it.

includes

public abstract Class<?>[] includes() default {}
Components and configurations of the application to wire into the slice as well – what Spring’s @Import adds to one. Each must be a bean class of the module.

properties

public abstract String[] properties() default {}
Settings for this test, as key=value, as BackendTest.properties.

profile

public abstract String profile() default "test"
The profile, as BackendTest.profile.

classes

public abstract Class<?>[] classes() default {}