All Projects → pester → Pester

pester / Pester

Licence: other
Pester is the ubiquitous test and mock framework for PowerShell.

Programming Languages

powershell
5483 projects
C#
18002 projects

Projects that are alternatives of or similar to Pester

TestBox
TestBox is a next generation testing framework for ColdFusion (CFML) that is based on BDD (Behavior Driven Development) for providing a clean obvious syntax for writing tests. It also includes MockBox, our mocking and stubbing framework.
Stars: ✭ 54 (-97.94%)
Mutual labels:  tdd, bdd, mocking
Gunit
GUnit - Google.Test/Google.Mock/Cucumber on steroids
Stars: ✭ 156 (-94.05%)
Mutual labels:  mock, tdd, bdd
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (-99.01%)
Mutual labels:  mock, tdd, mocking
List Of Testing Tools And Frameworks For .net
✅ List of Automated Testing (TDD/BDD/ATDD/SBE) Tools and Frameworks for .NET
Stars: ✭ 303 (-88.44%)
Mutual labels:  mock, tdd, bdd
Gock
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
Stars: ✭ 1,185 (-54.77%)
Mutual labels:  mock, mocking, assertions
chai
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Stars: ✭ 7,842 (+199.31%)
Mutual labels:  tdd, bdd, assertions
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (-85.69%)
Mutual labels:  mock, tdd, bdd
Should.js
BDD style assertions for node.js -- test framework agnostic
Stars: ✭ 1,908 (-27.18%)
Mutual labels:  tdd, bdd, assertions
Moka
A Go mocking framework.
Stars: ✭ 53 (-97.98%)
Mutual labels:  mock, tdd, mocking
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-98.44%)
Mutual labels:  tdd, bdd, assertions
Clj Fakes
An isolation framework for Clojure/ClojureScript.
Stars: ✭ 26 (-99.01%)
Mutual labels:  tdd, mocking, assertions
Httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module
Stars: ✭ 1,930 (-26.34%)
Mutual labels:  mock, tdd, mocking
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-95.27%)
Mutual labels:  tdd, bdd, assertions
Python Mocket
a socket mock framework - for all kinds of socket animals, web-clients included
Stars: ✭ 209 (-92.02%)
Mutual labels:  mock, tdd, mocking
Mockito
Most popular Mocking framework for unit tests written in Java
Stars: ✭ 12,453 (+375.31%)
Mutual labels:  mock, mocking
Ts Auto Mock
Typescript transformer to unlock automatic mock creation for interfaces and classes
Stars: ✭ 204 (-92.21%)
Mutual labels:  mock, mocking
Mocktail
A mock library for Dart inspired by mockito
Stars: ✭ 172 (-93.44%)
Mutual labels:  mock, mocking
Karma
Spectacular Test Runner for JavaScript
Stars: ✭ 11,591 (+342.4%)
Mutual labels:  tdd, bdd
Expekt
BDD assertion library for Kotlin
Stars: ✭ 163 (-93.78%)
Mutual labels:  bdd, assertions
Mockery
A mock code autogenerator for Golang
Stars: ✭ 3,138 (+19.77%)
Mutual labels:  mock, mocking

Pester

💵 I am spending most of my weekends making this happen. These release notes for example took multiple days to write and update. Consider sponsoring me or sponsoring Pester, please.

🌵 Documentation is available at https://pester.dev/docs/quick-start.

📦🔐 Pester is now signed. -SkipPublisherCheck should no longer be used to install from PowerShell Gallery on Windows 10.

👩👨 We are looking for contributors! All issues labeled help wanted are up for grabs. They further split up into good first issue that are issues I hope are easy to solve. Bad first issue where I expect the implementation to be problematic or needs to be proposed and discussed beforehand. And the rest which is somewhere in the middle. If you decide to pick up an issue please comment in the issue thread so others don't waste their time working on the same issue as you. There is also contributor's guide that will hopefully help you.

Pester is the ubiquitous test and mock framework for PowerShell.

BeforeAll {
    # your function
    function Get-Planet ([string]$Name='*')
    {
        $planets = @(
            @{ Name = 'Mercury' }
            @{ Name = 'Venus'   }
            @{ Name = 'Earth'   }
            @{ Name = 'Mars'    }
            @{ Name = 'Jupiter' }
            @{ Name = 'Saturn'  }
            @{ Name = 'Uranus'  }
            @{ Name = 'Neptune' }
        ) | foreach { [PSCustomObject]$_ }

        $planets | where { $_.Name -like $Name }
    }
}

# Pester tests
Describe 'Get-Planet' {
  It "Given no parameters, it lists all 8 planets" {
    $allPlanets = Get-Planet
    $allPlanets.Count | Should -Be 8
  }

  Context "Filtering by Name" {
    It "Given valid -Name '<Filter>', it returns '<Expected>'" -TestCases @(
      @{ Filter = 'Earth'; Expected = 'Earth' }
      @{ Filter = 'ne*'  ; Expected = 'Neptune' }
      @{ Filter = 'ur*'  ; Expected = 'Uranus' }
      @{ Filter = 'm*'   ; Expected = 'Mercury', 'Mars' }
    ) {
      param ($Filter, $Expected)

      $planets = Get-Planet -Name $Filter
      $planets.Name | Should -Be $Expected
    }

    It "Given invalid parameter -Name 'Alpha Centauri', it returns `$null" {
      $planets = Get-Planet -Name 'Alpha Centauri'
      $planets | Should -Be $null
    }
  }
}

Save this code example in a file named Get-Planet.Tests.ps1, and run Invoke-Pester Get-Planet.Tests.ps1, or just press F5 in VSCode.

Learn how to start quick with Pester in our docs.

The example above also has an annotated and production ready version here.

Installation

Pester runs on Windows, Linux, MacOS and anywhere else thanks to PowerShell. It is compatible with Windows PowerShell 3, 4, 5, 6 and 7.

Pester 3 comes pre-installed with Windows 10, but we recommend updating, by running this PowerShell command as administrator:

Install-Module -Name Pester -Force

Not running Windows 10 or facing problems? See the full installation and update guide.

Features

Test runner

Pester runs your tests and prints a nicely formatted output to the screen.

test run output

Command line output is not the only output option, Pester also integrates with Visual Studio Code, Visual Studio, and any tool that can consume nUnit XML output.

Assertions

Pester comes with a suite of assertions that cover a lot of common use cases. Pester assertions range from very versatile, like Should -Be, to specialized like Should -Exists. Here is how you ensure that a file exists:

Describe 'Notepad' {
    It 'Exists in Windows folder' {
        'C:\Windows\notepad.exe' | Should -Exist
    }
}

Learn more about assertions in our documentation.

Mocking

Pester has mocking built-in. Using mocks you can easily replace functions with empty implementation to avoid changing the real environment.

function Remove-Cache {
    Remove-Item "$env:TEMP\cache.txt"
}

Describe 'Remove-Cache' {
    It 'Removes cached results from temp\cache.text' {
        Mock -CommandName Remove-Item -MockWith {}

        Remove-Cache

        Should -Invoke -CommandName Remove-Item -Times 1 -Exactly
    }
}

Learn more about Mocking here.

Code coverage

Pester can measure how much of your code is covered by tests and export it to JaCoCo format that is easily understood by build servers.

JaCoCo code coverage report

Learn more about code coverage here.

Build server integration

Pester integrates nicely with TFS, AppVeyor, TeamCity, Jenkins and other CI servers.

Testing your scripts, and all pull requests on AppVeyor is extremely simple. Just commit this appveyor.yml file to your repository, and select your repository on the AppVeyor website:

version: 1.0.{build}
image:
  - Visual Studio 2017
  - Ubuntu
install:
  - ps: Install-Module Pester -Force -Scope CurrentUser
build: off
test_script:
  - ps: Invoke-Pester -EnableExit

See it in action here! If you do not need to test your scripts against PowerShell Core, just simply remove the entire line mentioning Ubuntu.

Pester itself is built on AzureDevOps, and distributed mainly via PowerShell gallery.

Build Status latest version downloads

Further reading

Do you like what you see? Learn how to use Pester with our quick start guide.

Got questions?

Got questions or you just want to get in touch? Use our issues page or one of these channels:

Pester Twitter Pester on StackOverflow Testing channel on Powershell Slack or try github discussions GitHub discussions.

Sponsored by

Pester is sponsored by Octopus Deploy.

Octopus deploy

As well as all the great folks on OpenCollective and GitHub.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. Contribute code.

Financial Contributors on Open Collective

Become a financial contributor and help us sustain our community. Contribute to Pester Open Collective.

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. Contribute

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].