Doc. usage of JSR-250 lifecycle annotations in TCF
The reference manual previously did not mention the applicability of JSR-250 lifecycle annotations within the TestContext framework. The lacking documentation here has lead to misunderstandings of the support provided for @PostConstruct and @PreDestroy in test classes. The testing chapter of the reference manual has therefore been updated to explicitly define the limited support for these annotations. Also introduced Jsr250LifecycleTests for empirical verification of the expected behavior. Issue: SPR-4868
This commit is contained in:
@@ -841,6 +841,32 @@ public void testProcessWithoutTransaction() {
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<note>
|
||||
<title>JSR-250 Lifecycle Annotations</title>
|
||||
|
||||
<para>In the Spring TestContext Framework
|
||||
<interfacename>@PostConstruct</interfacename> and
|
||||
<interfacename>@PreDestroy</interfacename> may be used with standard
|
||||
semantics on any application components configured in the
|
||||
<interfacename>ApplicationContext</interfacename>; however, these
|
||||
lifecycle annotations have limited usage within an actual test
|
||||
class.</para>
|
||||
|
||||
<para>If a method within a test class is annotated with
|
||||
<interfacename>@PostConstruct</interfacename>, that method will be
|
||||
executed before any <emphasis>before</emphasis> methods of the
|
||||
underlying test framework (e.g., methods annotated with JUnit's
|
||||
<interfacename>@Before</interfacename>), and that will apply for
|
||||
every test method in the test class. On the other hand, if a method
|
||||
within a test class is annotated with
|
||||
<interfacename>@PreDestroy</interfacename>, that method will
|
||||
<emphasis role="bold">never</emphasis> be executed. Within a test
|
||||
class it is therefore recommended to use test lifecycle callbacks
|
||||
from the underlying test framework instead of
|
||||
<interfacename>@PostConstruct</interfacename> and
|
||||
<interfacename>@PreDestroy</interfacename>.</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="integration-testing-annotations-junit">
|
||||
|
||||
Reference in New Issue
Block a user