This is more a question than it is an issue. Suppose I have a script file that contains some functions in the Begin clause. However, the script has also some actions defined in the Process clause and some mandatory parameters in the Parameters.
Under normal circumstances I would move the functions to a module and test the module for proper functionality of the containing functions. But in this case, that's not possible. Because we need these functions to be in the script file. The script file will later be called with Invoke-Command -FilePath Script.ps1 -ComputerName xxx to run on remote machines where there's no module folder available.
Consider the following example:
Param (
[Parameter(Mandatory)]
[String]$Name
)
Begin {
Function Test-NumberIsFive {
Param (
[Parameter(Mandatory)]
[Int]$Number
)
if ($Number -eq 5) {
$true
}
}
}
Process {
(0..10).ForEach({ Test-NumberIsFive -Number $_ })
}
What is the best way to test the function Test-NumberIsFive without invoking the script?
This is more a question than it is an issue. Suppose I have a script file that contains some functions in the
Beginclause. However, the script has also some actions defined in theProcessclause and some mandatory parameters in theParameters.Under normal circumstances I would move the functions to a module and test the module for proper functionality of the containing functions. But in this case, that's not possible. Because we need these functions to be in the script file. The script file will later be called with
Invoke-Command -FilePath Script.ps1 -ComputerName xxxto run on remote machines where there's no module folder available.Consider the following example:
What is the best way to test the function
Test-NumberIsFivewithout invoking the script?