Skip to content

Is there any reason why using [Parameter()] on It block parameters in parameterised tests, breaks the tests? #2043

Answered by fflaten
plastikfan asked this question in Q&A
Discussion options

You must be logged in to vote

It's because the use of ParameterAttribute will make the scriptblock advanced (like [CmdLetBinding()]) which doesn't allow arguments by default. So it fails to bind some of the hard-coded values Pester passes to the It-scriptblock, in this case the object for the current testcase.

I'm not really sure why the param-block is in the README-example tbh. You don't really need it for normal usage. All the testcase parameters are made available both as named variables and the current testcase-object/dictionary itself can be accessed through $_.

Any reason you need the ParameterAttributes? If not I'd remove them or maybe even the whole param-block.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@fflaten
Comment options

@plastikfan
Comment options

@plastikfan
Comment options

@fflaten
Comment options

@plastikfan
Comment options

Answer selected by plastikfan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants