1

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?

1 Answer 1

2

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 {
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

blue_man I tried this but my code is visiting beforeEach method. did you find any solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.