Skip to content

Commit b4fc7b4

Browse files
asaikalisbrannen
authored andcommitted
Document that @transactional is not supported on test lifecycle methods
This commit adds a tip clarifying that TestNG's @BeforeClass and @BeforeSuite methods can not be annotated with Spring's @transactional annotation. Closes: gh-456
1 parent 0652e4b commit b4fc7b4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/docs/asciidoc/testing.adoc

+9
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,15 @@ hierarchy runs within a transaction. Test methods that are not annotated with
35243524
Furthermore, tests that are annotated with `@Transactional` but have the `propagation`
35253525
type set to `NOT_SUPPORTED` are not run within a transaction.
35263526

3527+
[TIP]
3528+
====
3529+
When using TestNG `@BeforeClass`,`@BeforeSuite` methods can not be used with the
3530+
`@Transactional` annotation, as they are considered non transactional methods by the
3531+
the spring text contetxt framework. However, you can inject a `PlatfromTransactionManager`
3532+
or a `TransactionTemplate` and use it within `@BeforeClass` method to perform a
3533+
transaction.
3534+
====
3535+
35273536
Note that <<testcontext-support-classes-junit4,
35283537
`AbstractTransactionalJUnit4SpringContextTests`>> and
35293538
<<testcontext-support-classes-testng, `AbstractTransactionalTestNGSpringContextTests`>>

0 commit comments

Comments
 (0)