Replies: 1 comment
-
If it's not used for generating tests then I'd place it in a root-level One limitation: You wouldn't be able to pass the variable to the However, using Alternative: |
Beta Was this translation helpful? Give feedback.
-
Hello All,
I'm curious what the standard is when you have data from your BeforeDiscovery ScriptBlocks that aren't meant to be used as fuel for the -ForEach parameters but rather Generic shared data objects that might be reused across multiple Context including ones where -ForEach is being used.
Something like
Sorry for the contrived example but seems there should be some kind of parameter that like -TestCases and -ForEach allows you to pass a HashTable, or possibly array of objects and make it available across all cycles of that Context or Test something like -Data
If there already is a parameter that does this I'm missing I'm happy to be shown it.
I do understand I could have just duplicated the SharedData into my Tests
but that just seems like a quick way for your test code to balloon out of control with anything beyond a trivial shared data like shown here.
I also know i can use the
$script:
scope to access these objects but that has ramifications if I have two Test files with the same$script:
lines defining variables, when test are run independently everything is fine, but when run in an `Invoke-Pester where the entire collection of tests are run since discovery is run on all files before they execute the first test that defines that variable is now working off the last test that defined that scoped variableRight now I'm solving the problem by something like
But that to me seems like I'm kind of bending the rules of what the -ForEach parameter is meant for
Maybe I'm overthinking it, just curious what other people do.
Beta Was this translation helpful? Give feedback.
All reactions