@BeforeAll support


Support for @BeforeAll annotation.

If you have a project with a lot of test classes and test methods and if your context object is complex this can improve the speed of test execution.

Otherwise, the context object or some other objects are created for each test method.


Stefan Seifert
September 26, 2019, 7:55 PM

currently @BeforeAll is not supported because if the context is not "immutable" - each unit test can write data to the repository, and thus the next unit test in the same class starts with a "dirty" repository which may impact the reproducibility of the tests.

but if you are aware of this problems and make sure this does not happen (e.g. doing writing to the repository only in the BeforeAll method) it might by useful to have @BeforeAll support. just do not see it as "silver bullet" to solve all performance problems by switching all @Before methods to @BeforeAll.

i will think about it and make some experiments if i find a bit time the next weeks. PRs welcome

Stefan Seifert
September 26, 2019, 7:58 PM

we might think about some way to "reset" a context object to it's initial state without the need to completely recreate it - but this may be not so easy as it not only affects the repository, but also OSGi services and other thinks registered via the context.

Daniel Strmecki
September 29, 2019, 7:52 AM

Hi Stefan, I completely agree with what you said in your first comment. In our case the boost in execution time is 200-250% (measured by calling all test cases from only one test method on a class level). So I am fine with leaving it up to developers to decide weather they can reuse the context object on class level or not.

Regarding your second comments, that would be really nice to have, but also just having a shared object would be a great start.

Stefan Seifert
January 23, 2020, 12:50 PM

we have a PR for this from : https://github.com/wcm-io/wcm-io-testing/pull/15

it has some open issues but looks like a good start

Stefan Seifert
January 29, 2020, 1:11 PM


Stefan Seifert


Matija Kovacek




Fix versions

Affects versions