Annotation Interface BeforeTransaction

@Target({METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) @Documented public @interface BeforeTransaction
Test annotation which indicates that the annotated void method should be executed before a transaction is started for a test method configured to run within a transaction via Spring's @Transactional annotation.

Generally speaking, @BeforeTransaction methods must not accept any arguments. However, as of Spring Framework 6.1, for tests using the SpringExtension with JUnit Jupiter, @BeforeTransaction methods may optionally accept arguments which will be resolved by any registered JUnit ParameterResolver extension such as the SpringExtension. This means that JUnit-specific arguments like TestInfo or beans from the test's ApplicationContext may be provided to @BeforeTransaction methods analogous to @BeforeEach methods.

@BeforeTransaction methods declared in superclasses or as interface default methods will be executed before those of the current test class.

This annotation may be used as a meta-annotation to create custom composed annotations.

Sam Brannen
See Also: