Annotation Type BackendTest


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

  • Element Details

    • webEnvironment

      How the application is reached. BackendTest.WebEnvironment.MOCK, the default, calls it in the same process through MockMvc; BackendTest.WebEnvironment.RANDOM_PORT serves it on a free port for TestRestTemplate or any HTTP client.
      Default:
      MOCK
    • properties

      String[] properties
      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.
      Default:
      {}
    • profile

      String profile
      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.
      Default:
      "test"
    • classes

      Class<?>[] classes
      TestConfiguration classes to add. A static nested TestConfiguration class of the test class is added without being listed.
      Default:
      {}