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 BackendTest

Runs a test class against the application the build wired: what @SpringBootTest does.

The build generates, for each class carrying this, a wiring of the application’s beans with the class’s test beans added – its TestConfigurations and MockitoBeans – and the code that fills the class’s @Autowired, LocalServerPort and MockitoBean fields. Nothing is looked up by reflection, so the same test runs translated, as a native binary.

One application runs at a time, as one runs per server process, and JUnit runs no two classes carrying this concurrently, even with parallel execution on. Test classes whose configuration is the same – the same test beans, properties, profile and web environment – share it, as Spring caches a context; a class that differs stops it and starts its own.

It is inherited, as @SpringBootTest is: an abstract base class can carry it, with the shared fields and tests, for concrete subclasses to run.

Nested types

enum BackendTest.FeatureA production feature features can add to the test’s application.
enum BackendTest.WebEnvironmentHow a BackendTest reaches the application.

Methods

public abstract BackendTest.WebEnvironment webEnvironment() default WebEnvironment.MOCKHow the application is reached.
public abstract String[] properties() default {}Settings for this test, as key=value, over the module’s application.properties, the profile’s file and the environment: a shell’s PORT or DATABASE_URL does not reach a test that names its own.
public abstract String profile() default "test"The profile.
public abstract Class<?>[] classes() default {}TestConfiguration classes to add.
public abstract BackendTest.Feature[] features() default {}The production features to start the test’s application with.

Method details

webEnvironment

public abstract BackendTest.WebEnvironment webEnvironment() default WebEnvironment.MOCK
How the application is reached. WebEnvironment.MOCK, the default, calls it in the same process through MockMvc; WebEnvironment.RANDOM_PORT serves it on a free port for TestRestTemplate or any HTTP client.

properties

public abstract String[] properties() default {}
Settings for this test, as key=value, over the module’s application.properties, the profile’s file and the environment: a shell’s PORT or DATABASE_URL does not reach a test that names its own.

profile

public abstract String profile() default "test"
The profile. test is a development profile: a database neither the test nor the profile’s file names is an in-memory SQLite one, whatever the environment says, and the generated daos create their tables.

classes

public abstract Class<?>[] classes() default {}
TestConfiguration classes to add. A static nested TestConfiguration class of the test class is added without being listed.

features

public abstract BackendTest.Feature[] features() default {}
The production features to start the test’s application with. None by default: a test application has no management endpoints, MCP endpoint or OpenTelemetry exporters, whatever the module’s settings ask for, so a test that does not exercise them does not pay for them. Name the ones a test verifies, or Feature.AS_PACKAGED for the set the packaged server is built with.