You might have heard of the recently added support for PowerShell development inside Visual Studio. This extension provides several features, with support for the Pester testing framework being one of them.

However, it seems that sometimes the Visual Studio 2013 just does not recognise your test scripts (even when they are named like SomeScript.Tests.ps1).

As a quick workaround you can create an external tool under the Tools menu and invoke Pester manually. You can do this by defining an External Tools... with the following options:

  • Title
  • Command
  • Arguments
    -command "$item = (Get-Item -Path $(TargetPath)); CD $item.Directory; Invoke-Pester;"
  • [Optional] Initial directory
  • Use Output window
  • Treat output as Unicode
  • Prompt for Arguments
  • [Inactive] Close on exit

With in the test script we could load our module under test like this (with the help of BeforeEach):

Describe "Do-Nothing" {
  Context "Function Returns Nothing" {

    BeforeEach {
      Write-Verbose "Before-Each";
      Import-Module "..PoSHModulebinDebugPoSHModule.dll" -Verbose;

    It "Should Return Nothing" {

      # Act
      $r = Do-Nothing;

      # Assert
      $r | Should Be $null;

You can then run Pester by selecting Invoke-Pester from the Tools menu. The command will change to the project directory and invoke all tests (i.e. all files that match this filter: *.Tests.ps1). The test result is shown on the Output window (but without colouring and highlighting):

Describing Do-Nothing
   Context Function Returns Nothing
VERBOSE: Before-Each
VERBOSE: Loading module from path '..\PoSHModule\bin\Debug\PoSHModule.dll'.
VERBOSE: Importing cmdlet 'Do-Nothing'.
    [+] Should Return Nothing 498ms
Tests completed in 498ms
Passed: 1 Failed: 0 Skipped: 0 Pending: 0

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.