Mock Environment Variable

瀏覽次數:908 次
跳到第一則未讀訊息

Dave Wiard

未讀,
2016年10月6日 上午10:58:352016/10/6
收件者:Pester
We have a function that does nothing more than check the value of [System.Environment]::OSVersion.Version for specific values and returns a $true/$false result. I saw a post on Stack Overflow that demonstrated how to do this but it does not appear to work for all variables. When I tried to set the OSVersion value within a Pester test I received the error below.

    [-] Error occurred in Context block 327ms
     
SetValueException: 'OSVersion' is a ReadOnly property.
     
RuntimeException: 'OSVersion' is a ReadOnly property.

Is there a way to mock these system environment variables or is this a function that simply cannot be tested using mocked values?

Dave Wyatt

未讀,
2016年10月6日 下午3:28:462016/10/6
收件者:Dave Wiard、Pester
You can write a function that just returns the value of an environment variable (which doesn't really much testing), then mock that.

--
You received this message because you are subscribed to the Google Groups "Pester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pester+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Wiard

未讀,
2016年10月12日 下午6:06:192016/10/12
收件者:Pester
Thanks, Dave. This is probably what we'll end up doing. For now I've moved on to other, larger, issues with our current Pester suite.
回覆所有人
回覆作者
轉寄
0 則新訊息