Skip to content

Commit 4608bfa

Browse files
Document that extensions should be stateless
The "Registering Extensions" page did not mention how often an extension is instantiated or that a single instance is typically reused across tests. Add a short section clarifying that no assumptions should be made about extension instantiation, that extensions should be stateless, and that state should be kept in the ExtensionContext.Store, linking to "Keeping State in Extensions".
1 parent 9cd9a3c commit 4608bfa

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎documentation/modules/ROOT/pages/extensions/registering-extensions.adoc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,13 @@ programmatically via `@RegisterExtension` or `@ExtendWith` on fields in a subcla
492492
NOTE: A specific extension implementation can only be registered once for a given
493493
extension context and its parent contexts. Consequently, any attempt to register a
494494
duplicate extension implementation will be ignored.
495+
496+
[[registration-instances]]
497+
== Extension Instances and State
498+
499+
You should not make any assumptions about when or how often the JUnit Platform instantiates
500+
a registered extension. In particular, a single extension instance is typically reused
501+
across multiple tests, so an extension should be _stateless_. Any state that needs to be
502+
kept between invocations should be stored in the `{ExtensionContext_Store}` rather than in
503+
instance fields, so that it is scoped correctly and does not leak between tests. See
504+
xref:extensions/keeping-state-in-extensions.adoc[Keeping State in Extensions] for details.

0 commit comments

Comments
 (0)