I am upgrading an internal tool based on JUnit 4 to JUnit 5. Therefore I have to write an extension for the test execution. The task of the extension should be to ensure the correct state of external application (start it if it is not running etc.). To perform this task serveral parameter (from the commandline) are needed.
Can I store these parameters in the extension context? And if so, how can I access it before the actual tests run starts?
Can I store these parameters in the extension context?
You could, but a better option would simply be to access them as "configuration parameters" -- for example, via org.junit.jupiter.api.extension.ExtensionContext.getConfigurationParameter(String)
.
And if so, how can I access it before the actual tests run starts?
You can access them via the aforementioned ExtensionContext.getConfigurationParameter(String)
method within a BeforeAllCallback
extension.
If you want that custom extension to be executed before all test classes without the user having to register the extension explicitly, you could have the extension registered automatically. See the User Guide for details.