Mocking java in powershell

Welcome Forums Pester Mocking java in powershell

Viewing 2 reply threads
  • Author
    • #214149
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      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!

      • This topic was modified 4 months, 1 week ago by sclieu78.
    • #215163
      Senior Moderator
      Topics: 9
      Replies: 1265
      Points: 4,582
      Helping Hand
      Rank: Community Hero

      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
    • #236500
      Topics: 0
      Replies: 1
      Points: 5
      Rank: Member
Viewing 2 reply threads
  • You must be logged in to reply to this topic.