Welcome › Forums › Pester › Mocking java in powershell
My ps script has the following code:
$WProcess = Start-Process java -ArgumentList "-jar $AgentFile -c $ConfigFile" -RedirectStandardOutput "$consoleOutPath" -RedirectStandardError "$consoleErrPath" -WindowStyle Hidden -Wait -PassThru
I later inspect $WProcess value, as well as validate $consoleOutPath file and $consoleErrPath, which are files.
How can I mock this as I don’t want to actually run the java program? I would like to mock the return value, as well as what gets written to the console.out and console.err files.
Thank you, ahead of time!
If you mock, then the files are not gonna get generated. You can mock Start-Process by just returning a PScustomobject in Mock function.
HasExited = $True
ExitCode = 0