You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2024/04/22 12:25:55 UTC
(sling-site) 01/01: sling-mock/osgi-mock Documentation: Clarify not to use @BeforeAll and not to instantiate context within @BeforeEach methods
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/SLING-12278-mocks-no-before-all
in repository https://gitbox.apache.org/repos/asf/sling-site.git
commit 99cc6522cb7f39efbbf89a2a146d5f55323ec0d3
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Mon Apr 22 14:25:41 2024 +0200
sling-mock/osgi-mock Documentation: Clarify not to use @BeforeAll and not to instantiate context within @BeforeEach methods
---
src/main/jbake/content/documentation/development/osgi-mock.md | 1 +
src/main/jbake/content/documentation/development/sling-mock.md | 1 +
2 files changed, 2 insertions(+)
diff --git a/src/main/jbake/content/documentation/development/osgi-mock.md b/src/main/jbake/content/documentation/development/osgi-mock.md
index 91278ee83..8baa44956 100644
--- a/src/main/jbake/content/documentation/development/osgi-mock.md
+++ b/src/main/jbake/content/documentation/development/osgi-mock.md
@@ -103,6 +103,7 @@ Example:
It is possible to combine such a unit test with a `@ExtendWith` annotation e.g. for
[Mockito JUnit Jupiter Extension][mockito-junit5-extension].
+The OsgiContext has to be defined as non-static field in combination with `@BeforeEach` and `@AfterEach` methods if you want to execute setup or tear down code for each test run. It is not supported to use a static field with `@BeforeAll` and `@AfterAll` methods. You should never try to instantiate a OsgiContext object within a `@BeforeEach` method, this may lead to duplicate context instances.
### JUnit 4: OSGi Context JUnit Rule
diff --git a/src/main/jbake/content/documentation/development/sling-mock.md b/src/main/jbake/content/documentation/development/sling-mock.md
index b88907bc4..aafcbd3e9 100644
--- a/src/main/jbake/content/documentation/development/sling-mock.md
+++ b/src/main/jbake/content/documentation/development/sling-mock.md
@@ -116,6 +116,7 @@ Example:
It is possible to combine such a unit test with a `@ExtendWith` annotation e.g. for
[Mockito JUnit Jupiter Extension][mockito-junit5-extension].
+The SlingContext has to be defined as non-static field in combination with `@BeforeEach` and `@AfterEach` methods if you want to execute setup or tear down code for each test run. It is not supported to use a static field with `@BeforeAll` and `@AfterAll` methods. You should never try to instantiate a SlingContext object within a `@BeforeEach` method, this may lead to duplicate context instances.
### JUnit 4: Sling Context JUnit Rule