You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Stefan Seifert (Jira)" <ji...@apache.org> on 2024/04/22 11:52:00 UTC
[jira] [Comment Edited] (SLING-12278) Improve handling of late instantiated context in SlingContextExtension/OsgiContextExtension
[ https://issues.apache.org/jira/browse/SLING-12278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17839626#comment-17839626 ]
Stefan Seifert edited comment on SLING-12278 at 4/22/24 11:51 AM:
------------------------------------------------------------------
the way the current junit 5 implemention is done in sling-mock, osgi-mock and aem-mock dates back to the time of JUnit 5.0 ([PR #5|https://github.com/wcm-io/wcm-io-testing/pull/5]), and i've never investigated much further if this is nowadays still the best way to do an junit 5 extension. it seems the programmatic extension registration was introduced in junit 5.1.
i currently cannot oversee how much benefit a switch or additional support of programmatic extension registration would bring - in any case it would be a lot of work to make sure it all works as expected, and we cannot remove the current way to register it for backwards compatibility.
so for now, i will only extend the documentation to make sure context objects are not created e.g. in BeforeEach/BeforeAll methods.
was (Author: sseifert@pro-vision.de):
the way the current junit 5 implemention is done in sling-mock, osgi-mock and aem-mock dates back to the time of JUnit 5.0 ([PR #5|[https://github.com/wcm-io/wcm-io-testing/pull/5]),] and i've never investigated much further if this is nowadays still the best way to do an junit 5 extension. it seems the programmatic extension registration was introduced in junit 5.1.
i currently cannot oversee how much benefit a switch or additional support of programmatic extension registration would bring - in any case it would be a lot of work to make sure it all works as expected, and we cannot remove the current way to register it for backwards compatibility.
so for now, i will only extend the documentation to make sure context objects are not created e.g. in BeforeEach/BeforeAll methods.
> Improve handling of late instantiated context in SlingContextExtension/OsgiContextExtension
> -------------------------------------------------------------------------------------------
>
> Key: SLING-12278
> URL: https://issues.apache.org/jira/browse/SLING-12278
> Project: Sling
> Issue Type: Improvement
> Components: Testing
> Affects Versions: Testing OSGi Mock 3.4.2, Testing Sling Mock 3.5.0
> Reporter: Konrad Windszus
> Priority: Major
>
> Currently neither in https://sling.apache.org/documentation/development/osgi-mock.html#junit-5-osgi-context-junit-extension nor in https://sling.apache.org/documentation/development/sling-mock.html#junit-5-sling-context-junit-extension it is mentioned that the context must not be instantiated in {{@BeforeAll}} or {{@BeforeEach}} as at that point in time the extension has already instantiated another context. Those two contexts may lead to subtle issues (for example if resources are only added in the second context). For a concrete example look at https://github.com/wcm-io/io.wcm.testing.aem-mock/issues/37.
> In the best case the JUnit5 extension never creates a context (but only uses the existing instance) or at least creation should be deferred until the Before methods have been executed.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)