Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Felix Becker
    I can’t get the TestDrive to work, is that because of running on macOS or am I just using it wrong?
    Get-PSDrive : Cannot find drive. A drive with the name 'TestDrive' does not exist.
    At /usr/local/microsoft/powershell/6.0.0-beta.9/Modules/Pester/4.0.8/Functions/TestDrive.ps1:36 char:14
    +     $Path = (& $SafeCommands['Get-PSDrive'] -Name TestDrive).Root
    +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (TestDrive:String) [Get-PSDrive], DriveNotFoundException
        + FullyQualifiedErrorId : GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand
        [-] Error occurred in Describe block 1.3s
          ParameterBindingValidationException: Cannot bind argument to parameter 'Path' because it is null.
          at Clear-TestDrive, /usr/local/microsoft/powershell/6.0.0-beta.9/Modules/Pester/4.0.8/Functions/TestDrive.ps1: line 37
          at DescribeImpl, /usr/local/microsoft/powershell/6.0.0-beta.9/Modules/Pester/4.0.8/Functions/Describe.ps1: line 175
          at Describe, /usr/local/microsoft/powershell/6.0.0-beta.9/Modules/Pester/4.0.8/Functions/Describe.ps1: line 84
          at <ScriptBlock>, /Users/felix/git/ps-nvmw/nvm.Tests.ps1: line 3
          at <ScriptBlock>, /usr/local/microsoft/powershell/6.0.0-beta.9/Modules/Pester/4.0.8/Pester.psm1: line 802
          at Invoke-Pester<End>, /usr/local/microsoft/powershell/6.0.0-beta.9/Modules/Pester/4.0.8/Pester.psm1: line 817
          at <ScriptBlock>, <No file>: line 1
    appreciate your help!
    Pester looks awesome, can’t believe PowerShell has a BDD-style testing framework better than most non-scripting languages
    Johan Ljunggren
    Not tried that. What does $TestDrive contain once you are inside a Describe-block? Is it a Windows or *nix path?
    Felix Becker
    I don’t even get into the Describe block
    The error is raised inside Pester

    Hi All, I am looking for feedback on a VS extension for Pester.

    It is located here:

    The current version has a Test Toolwindow, a Coverage Toolwindow and shows the line hits in misses in the editor.

    Any comments and suggestions are appreciated.
    Jakub Jareš
    @felixfbecker figured it out? TestDrive PSDrive is setup when $Pester is setup.
    Felix Becker
    I was able to run the tests with pester/Pester#925
    Jakub Jareš
    @jonkeda looks promising, will try later :)
    @felixfbecker thought so, saw your comment before, but just wanted to confirm with you :)
    Felix Becker
    Didn’t actually end up using TestDrive though. Just got rid of the error
    currently trying to get codecov working
    Felix Becker
    got it
    Jakub Jareš
    Is it possible to mock the call operator &?
    I’m not sure. I never have. But I have mocked commands called by the call operator.
    Hello! I'm sort of confused about a problem i'm running into.
    Basically, I'm getting odd behavior when I'm trying to assert that an array is either Empty/Null or NOT empty/null
    as an example, see that code.
    test-PesterPipelineIssue /Users/me/testingDir/testPester.txt | Should beNullOrEmpty
    if you change that line to "should not beNullOrEmpty"` you'll see the behavior change, which i really don't understand.
    (also, sorry if I'm asking in the wrong place. Please let me know if I should move my question to a different location!)
    aaaand nevermind. I nuked my install of psc and pester and resintalled and now I'm getting different behavior
    Hi Folks,
    Pester gives code coverage for lines, do we have a way to get the same for functions ?
    Jakub Jareš
    @kvprasoon No, I don't think there is an option for that.
    $Thanks @nohwnd
    hello, anybody used the BeforeEachScenario -Tags statement as described in https://kevinmarquette.github.io/2017-04-30-Powershell-Gherkin-advanced-features/#beforeeachscenario. I get the following error: "The expression after '&' in a pipeline element produced an object that was not valid."
    Hello, anybody mocked get-environment variable function either user or machine
    I have a function to get environment variable, where I have used Get-EnvironmentVariable function to get the value. While writing pester test, I want to mock [System.Environment]::Get-EnvironmentVariable('XXXX', 'User') inorder to test empty scenario and with value scenrio. Can anyone help on this
    Johan Ljunggren
    @routhrirajan Don't think it is possible to mock that, easiest it to make a wrapper (powershell function) for the method [System.Environment]::GetEnvironmentVariable() and mock that. Another way might be to make a stub class and load with Add-Type, but not sure it works in this case since the type is already loaded.
    Thanks @johlju I will try with the suggested options. Let you know if it helps
    Chris Forbes
    Hi everyone. How do I test a module that has RequiredModules in the manifest. if the dependent modules are not installed, the tests will fail.
    Chris Forbes
    Or this may be due to fully qualified function names, I'm not sure.
    Sotiris Nanopoulos
    Hey @nohwnd I want to take a stab at this pester/Pester#301 . Is it ok? Is there anyone working on something conflicting with this?
    Rushikesh Vyas

    Hey guys I am trying to use Pester (4.8.1) for our azure devops pipeline CI build. I have a "publish test" task and
    this is what I am doing right now
    Invoke-Pester -Script $testFilePath -OutputFile $outputFilePath -OutputFormat 'NUnitXML' -CodeCoverage $psFiles -CodeCoverageOutputFile $codeCoverageOutputFIlePath -EnableExit

    My questions is: Is there a way I can put the result in a variable using passthru and and still save all the outputs in the specified files? I want the task to fail if any tests fail but I also have following tasks that shows test result and I want to see which tests failed. With -EnableExit fail it fails the testing task but it skips publishing test result task too

    Heber Alejandro
    Hello everyone! how can I send parameters for each test case in a suite? currently I had just one test case to call and I do it like this Invoke-Pester -Script @{Path = 'C:\Turing\Test\Frida-launcher.ps1'; Parameters = @{frida_process_id = '807028544'; frida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}} -OutputFile "frida-results.xml" -OutputFormat "NUnitXML" but I don't know how to do it for every test case in the suite :(. Thanks for any help :)
    is there a way to escape special characters in gherkin step names?
    i found that trying to use parenthesis or square brackets causes it to stop matching the names of the steps in the features to the names of the actual steps
    I tried escaping these with backslash and and the backtick but still can't get it to work
    Carl in 't Veld
    is there a way to define functions in the scope of a unit test that can be called from a MockWith code block?
    @kitforbes I have a related requirement. I have a custom module that is requiring AzureAD and AD to be imported. But obviously these are very large and I want to leave them out. I just mock all the Azure calls. Currently the only way I manage this is to exclude the required modules from the custom module's manifest psd1 file
    Andy AO
    hello everyone
    I don't feel very active here. There are only 69 members.
    Michael Ablassmeier
    How is it possible to use Variables for Describe and It blocks in V5? It is not necessarily the -TestCases parameter that helps me out. Im testing various command line tools, each test tool goes into its own file (command.Tests.ps1) so it would be neat to use the "command" as variable from the filename in the it and Describe copes (Descript "test ${command}" ..)
    Using BeforeAll with $global:command="foo" is problematic because if pester is called with -Path on a directory with multiple tests. the global variable overrides during execution all other files too,.. i had weird behavior.
    Daniel Groh

    I have a function which uses some Azure Cli commands, for example:

        $appRegistration = az ad app create `
            --display-name $name `
            --reply-urls $replyUrls `
            --oauth2-allow-implicit-flow true `
            --available-to-other-tenants false `
            -o json | 

    How can I mock az ad app create and assert the parameters with Assert-MockCalled? I don't find anything about that

    Marc van Gorp
    Mocking an executable is not possible. At least not to my knowledge.
    In this scenario I create a 'wrapper' function that calls the executable. This 'wrapper' function can be mocked.
    function Invoke-AzureCli {
        switch ($isWindows) {
            $True {
                $AssertPath = Test-Path -Path 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd'
            $False {
                switch ($IsLinux) {
                    $true {
                        $AssertPath = Test-Path -Path '/usr/bin/az'
                    Default { throw "Unsuported operating system detected '$PSVersionTable.OS'" }
        if ($AssertPath -eq $False) {
            throw "Azure CLI not found!`nThis function requires Azure CLI to be available on this system.`nhttps://docs.microsoft.com/en-us/cli/azure/install-azure-cli"
        az $args
        if ($LASTEXITCODE -ne 0) {
            throw 'Execution failed'