Introduction

I am glad to announce that the first official release of PSUnit is now available for download on Codeplex http://www.psunit.org/Release/ProjectReleases.aspx. 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.

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.

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.

Category

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.

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: http://www.psunit.org/Thread/List.aspx. In upcoming posts I am going to provide details about the structure of the framework.