0

MainFunction which i want to check writing another script.

In short i just want to check certain part of the mainfunctiona and go back to pester.

param(
[int]$jobCardID = $(Throw '-jobCardID is required'),            # VSTS Job Card ID
[string]$filePath = $(Throw '-filePath is required'),           # Relative path to the file to test
[string]$step = $(Throw '-step is required'),                   # Step (verification / approval)
[string]$status = $null,                                        # Status (Approved / Rejected)
[string]$jenkinsJobID = $(Throw '-jenkinsJobID is required')    # Jenkins Job ID`enter code here`
)
$ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
Write-Output ("INFO: Script root path is {0}" -f $ScriptPath)
. "$ScriptPath\Helpers\Jenkins.ps1"
. "$ScriptPath\Helpers\MetaData.ps1"
. "$ScriptPath\Helpers\VSTS.ps1"
. "$ScriptPath\STA_AOI.ps1"

#region Variables Setup
$Passed = $true
$Errors = @()
$ManualCheck = @()
$ManualCheckNotRequired = $true
$SectionDelimiter = '{0}' -f ("-" * 112)
# End Variables Setup

Pester script for middle part of the function.

 Context "checking internal metadata parameters" {
    #test1 start
    it "ScriptPath returns correct location as well as region scripts" {

        $Params = @{
            jobCardID = 9223
            filePath = '..\..\..\DataFiles\Test\Verification test\AOI\Staging\ctrPassTest.L5X'
            step = 'verification'
            status = ''
            jenkinsJobID = '321'
        }
        . ./Mainfunction.ps1 @Params #Can I put any condition here that will only allow to go up to 15 lines in actual function. 
        $ScriptPath | Should -be $PSScriptRoot
        "$ScriptPath\Helpers\Jenkins.ps1" | should -Exist
        "$ScriptPath\Helpers\MetaData.ps1" | should -Exist
        "$ScriptPath\Helpers\VSTS.ps1" | should -Exist
        "$ScriptPath\STA_AOI.ps1" | should -Exist
    } 

So the question is how can i send my process from mainfunction.ps1 line 14 to back in test function to confirm some information. I dont want to check after line 14 in mainfunction.

  • This isn't how Pester is meant to work. It isn't about testing an arbitrary portion of your code - it is for 'unit' testing, where the units are clearly defined code blocks (functions/methods). If you need to step out of the test to check something mid-way, then your code, test or both should be re-written. As I mentioned in [your other question](https://stackoverflow.com/questions/54547181/pester-should-only-checks-function-up-to-certain-lines) on this, you should 'isolate' and test specific code paths by mocking and careful parameter selection. – boxdog Feb 06 '19 at 09:08
  • The main reason is that I cannot change in the main function and cannot check whole function at one go. I am happy to mock which I will do it in further script. – Radhik Patel Feb 06 '19 at 23:28

0 Answers0