Replies: 1 comment
-
| 
         @jlink answered a related question here: https://stackoverflow.com/questions/58586207/how-to-store-values-in-junit-5-extensions-and-inject-in-parameterized-test#comment103705894_58586208 Perhaps an   | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
With my extensions (not just in this example), I do some initialisation in the
beforeAllmethod and some fine-tuning (e.g. finding execution arguments) in thebeforeEachmethod.I was using
context.getParent()for this: https://github.com/bmarwell/jdtfmt/blob/main/integration-tests/it-extension/src/main/java/io/github/bmarwell/jdtfmt/its/extension/JdtFmtExtension.java#L83However, @sormuras hinted me to
getRoot(): https://docs.junit.org/current/user-guide/#extensions-keeping-stateBlindly using
getParent()seems a little fragile, and not sure if there is a way to search all the layers in between.What is the recommended approach? Is it always true that the
beforeAllcontext is the direct parent ofbeforeEach?Maybe the javadoc should mention such things (when to use which context, when to call getParent/getRoot, which one is fragile, etc.).
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions