Issue
I am setting some properties as below when I launch the Junit Tests programmatically.
LauncherDiscoveryRequestBuilder
.request()
.selectors(selectMethod("com.example#testMethod()"))
.configurationParameter("My_Param","Hello")
.build()
Is there a way to access My_Param
from the test method?
Solution
I believe you can use the ExtensionContext.getConfigurationParameter()
method.
From JUnit 5.1.0 release notes:
Extensions for JUnit Jupiter can now access JUnit Platform configuration parameters at runtime via the new getConfigurationParameter(String key) method in the ExtensionContext API.
The obvious way to access the ExtensionContext
would be to implement an extension.
An alternative would be to implement one of the lifecycle callbacks directly in the test:
public class YourTest implements BeforeEachCallback {
@Override
public void beforeEach(ExtensionContext context) throws Exception {
}
}
Answered By - Arho Huttunen
Answer Checked By - Robin (JavaFixing Admin)