I want to set up powershell script testing but also limit the scope to functions. myscript.ps1
contains internal functions with each their own parameter dependencies also, but I will not test them, only interested in Get-Something
.
- How do I import the function from the script to my test without running the script?
myscript.ps1
<#
.SYNOPSIS
Script with functions.
#>
Param (
[string]$myVar,
[string]$myVar2
)
function Get-SomeThing {
Param (
[string]$myVariable,
[string]$myVariable2
)
$foo = "$($myVariable) $($myVariable2)"
return $foo
}
function Get-SomeThingElse {
Param (
[string]$myVariableAgain,
[string]$myVariableAgain2
)
$bar = Get-SomeThing -myVariable $myVariableAgain -myVariable2 $myVariableAgain2
$foo2 = "$($bar) $($myVariable) $($myVariable2)"
return $foo2
}
Get-SomeThingElse -myVariableAgain $myVar -myVariableAgain2 $myVar2
my.Tests.ps1
Describe 'My Tests' {
BeforeAll {
$myVar = 'Hello'
$myVar2= 'World'
}
It 'Test Hello World' {
(Get-SomeThing -myVariable $myVar -myVariable2 $myVar2) | Should Be 'Hello World'
}
}
directories
Root/
-Tests/
--my.Tests.ps1
-myscript.ps1