Skip to content

Configuration Lifecycle

Tim Ward edited this page Jan 22, 2024 · 2 revisions

The osgi-test ConfigurationExtension provides automated management of Configurations, and tries to make sure that each test starts in the same state regardless of the order in which they are run by resetting the configurations.

The following order of precedence applies to configuration declarations, with later definitions overriding earlier ones:

  1. Configurations declared at the class level using @WithConfiguration/@WithFactoryConfiguration
  2. Configurations declared on @BeforeAll methods using @WithConfiguration/@WithFactoryConfiguration
  3. Configurations injected into @BeforeAll methods using @InjectConfiguration
  4. Configurations declared on @BeforeEach methods using @WithConfiguration/@WithFactoryConfiguration
  5. Configurations injected into @BeforeEach methods using @InjectConfiguration
  6. Configurations declared on @Test methods using @WithConfiguration/@WithFactoryConfiguration
  7. Configurations injected into @Test methods using @InjectConfiguration

It is not meaningful to annotate @BeforeEach, @AfterEach, @BeforeAll or @AfterAll methods using @WithConfiguration/@WithFactoryConfiguration and this will trigger a test configuration error.

  • Configurations defined or injected at the @Test level will be deleted or reset immediately after test execution
  • Configurations defined or injected at the @BeforeEach level will be deleted or reset immediately after any @AfterEach methods have completed
  • Configurations defined or injected at the @BeforeAll and class level will be deleted or reset immediately after any @AfterAll methods have completed
  • Any manual modifications to configurations injected using @InjectConfiguration will persist until the deletion or reset of the configuration, as defined above