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
master
Adib Saikali 11 years ago committed by Sam Brannen
parent 0652e4b485
commit b4fc7b410b
  1. 9
      src/docs/asciidoc/testing.adoc

@ -3524,6 +3524,15 @@ hierarchy runs within a transaction. Test methods that are not annotated with
Furthermore, tests that are annotated with `@Transactional` but have the `propagation` Furthermore, tests that are annotated with `@Transactional` but have the `propagation`
type set to `NOT_SUPPORTED` are not run within a transaction. type set to `NOT_SUPPORTED` are not run within a transaction.
[TIP]
====
When using TestNG `@BeforeClass`,`@BeforeSuite` methods can not be used with the
`@Transactional` annotation, as they are considered non transactional methods by the
the spring text contetxt framework. However, you can inject a `PlatfromTransactionManager`
or a `TransactionTemplate` and use it within `@BeforeClass` method to perform a
transaction.
====
Note that <<testcontext-support-classes-junit4, Note that <<testcontext-support-classes-junit4,
`AbstractTransactionalJUnit4SpringContextTests`>> and `AbstractTransactionalJUnit4SpringContextTests`>> and
<<testcontext-support-classes-testng, `AbstractTransactionalTestNGSpringContextTests`>> <<testcontext-support-classes-testng, `AbstractTransactionalTestNGSpringContextTests`>>

Loading…
Cancel
Save