PSUnit PowerShell Unit Testing Framework – Getting Started Guide – Running Unit Tests – Version 2 Beta 1

by Klaus Graefensteiner 7. August 2009 09:46


I am glad to announce that the first official release of PSUnit is now available for download on Codeplex This release is a fully functional unit testing framework that lets you write and execute unit tests in PowerShell. It also provides a nice test result reporting feature. The Beta release is missing some convenience features, like an automatic deployment of an PowerShell module. Instead there are a few manual steps required to deploy the framework successfully. To increase the usability in the near future I am also extending the PSUnit integration with the PowerShell ISE.

Note: This release of PSUnit requires PowerShell 2.0 CTP3 or later! Click here to download this version of PowerShell

Note: For information about how to install PSUnit read the following blog post: Installing PSUnit

Note: For information about how to write unit tests with PSUnit read the following blog post: Writing unit tests for PSUnit

Running PSUnit tests

Running the test script from the ISE

The easiest way to run PSUnit unit tests is to open a test file in the PowerShell ISE and select the Custom\Run Unit Tests command (PowerShell 2.0 CTP3) or the Add-On\Execute Unit Tests command (PowerShell 2.0 RTM). Make sure that the unit tests script is the currently selected script.

Running PSUnit unit tests from the PowerShell ISE

Figure 1: Running the current PSUnit unit test script via PowerShell ISE custom menu command

The default implementation of the custom menu command is going to execute the current unit test script. At the end it automatically opens the test result report in the default browser. The progress of the test run will be displayed in the output window of the ISE. Depending on the debug settings of your PowerShell runtime the output can contain just a table of the test result messages or a detailed list of debug statements and the test result statements.

Here is the command that the ISE menu is hooked up to:

   1: PSUnit.Run.ps1 -PSUnitTestFile $($psISE.CurrentFile.FullPath) -ShowReportInBrowser

Note: Debug or production mode can be enabled by either calling the functions Set-DebugMode or Set-ProductionMode


Figure 2: Test run in the ISE with debug enabled


Figure 3: Test run in the ISE with debug disabled

Running the test script form PowerShell.exe

The same statement can also be executed from the PowerShell CMD shell console. Open PowerShell.exe and enter the following command:

   1:  PSUnit.Run.ps1 -PSUnitTestFile (Join-Path -Path $env:PSUNIT_HOME -ChildPath "Samples\Interpolate-Records.Test.ps1") -ShowReportInBrowser

The following screenshot shows the output in the case where debug is not enabled:


Figure 3: Test run in the PowerShell.exe CMD shell

PSUnit-Run.ps1 parameters

The script that executes the test is called PSUnit-Run.ps1. It has three parameters that determine its behavior:


This parameter is required and specifies the name of script file that contains the PSUnit unit tests. Here is an example:

   1:  PSUnit.Run.ps1 -PSUnitTestFile (Join-Path -Path $env:PSUNIT_HOME -ChildPath "Samples\Interpolate-Records.Test.ps1")


The Category parameter specifies the category of tests to filter out and execute. By default all tests are executed and therefore the name of the default Category is “All”. In the example here only tests that have the Category_ParameterValidation parameter will be executed. Click here for more details.

   1:  PSUnit.Run.ps1 -PSUnitTestFile (Join-Path -Path $env:PSUNIT_HOME -ChildPath "Samples\Interpolate-Records.Test.ps1") -Category "ParameterValidation"


Figure 4: Running only a subset of tests by specifying the Category parameter


The ShowReportInBrowser switch parameter will, if set, automatically open the test result report in the default browser. Here is an example command:

   1:  PSUnit.Run.ps1 -PSUnitTestFile (Join-Path -Path $env:PSUNIT_HOME -ChildPath "Samples\Interpolate-Records.Test.ps1") -ShowReportInBrowser

The test results report

By default each test run will generate a detailed test result report in the PSUNIT_HOME folder.


Figure 5: Test result reports

Test report name

The name of the test result reports contains the following information:

  • Name of the script file that contains the unit test functions
  • The date and time of the start of the test run
  • The test result (T=Total number of tests, P=Passed, F=Failed, S=Skipped)

Test report content

A test report contains information about the test environment, the actual test result and detailed error information:


Figure 6: At last the test result report

Questions and Comments

Any feedback is welcome. Either leave a comment here on my blog or add a discussion item on the PSUnit Codeplex site: In upcoming posts I am going to provide details about the structure of the framework.

Tags: ,

PowerShell | PSUnit | Test Automation


8/16/2009 11:36:39 AM #


Pingback from

Episode 80 – Klaus Graefensteiner «  PowerScripting Podcast |

9/3/2009 12:11:49 AM #



Klaus United States |

9/3/2009 12:14:11 AM #



Klaus United States |

9/3/2009 12:16:19 AM #


Cool nested comments work.

Klaus United States |

9/3/2009 1:04:35 AM #


Pingback from

PSUnit PowerShell Unit Testing Framework – Getting Started Guide – Running Unit Tests – Version 2 Beta 1 - Technology - TechBlog |

9/13/2009 11:37:10 AM #


Pingback from

Episode 83 – with Pragma Systems «  PowerScripting Podcast |

Comments are closed

About Klaus Graefensteiner

I like the programming of machines.

Add to Google Reader or Homepage

LinkedIn FacebookTwitter View Klaus Graefensteiner's profile on Technorati
Klaus Graefensteiner

Klaus Graefensteiner
works as Developer In Test and is founder of the PowerShell Unit Testing Framework PSUnit. More...

Open Source Projects

PSUnit is a Unit Testing framwork for PowerShell. It is designed for simplicity and hosted by Codeplex.
BlogShell is The tool for lazy developers who like to automate the composition of blog content during the writing of a blog post. It is hosted by CodePlex.



Powered by:

Creative Commons License

© Copyright 2015, Klaus Graefensteiner.

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Theme design:
This blog theme was designed and is copyrighted 2015 by Klaus Graefensteiner

Page rendered at 5/28/2015 10:54:37 AM (PST Pacific Standard Time UTC DST -7)