Project Description
PsTest is a lightweight UnitTesting Module for use in PowerShell.

Use all the power of PowerShell to make your UnitTests Fly!

UnitTests are Written In PowerShell as regular functions, identified with the Verb 'UnitTest' (or another verb that you choose yourself)):

<# Sample UnitTest, for Get-ChildItem #>
function UnitTest-Get-ChildItem {
    # arrange
    $path = "."

    # act
    $actual = Get-ChildItem $path

    # assert
    Assert-IsNotEmpty -Actual $actual -Message "Get-ChildItem returned no items"

and saved in a file named .UnitTests.ps1*.

Unit Test are discovered using 'Get-UnitTestFile' (for searching UnitTest files, like 'Get-ChildItem') and 'Get-UnitTest' (for getting UnitTests from files, like 'Get-Content').

Import-Module PsTest

$testFiles = Get-UnitTestFile -Path . -Recurse 
$tests = $testFiles | Get-UnitTest

UnitTests are then run using 'Invoke-UnitTest':

$tests | Invoke-UnitTest

As a result you will recieve the TestResult items, which will be formatted using a custom format:

    TestResults: PsTest.Assert.UnitTests.ps1

          State Duration           Name
          ----- --------           ----
         Passed 00:00:00.0066942   UnitTest-Assert-AreEqual-False
         Passed 00:00:00.0008871   UnitTest-Assert-AreEqual-True
         Passed 00:00:00.0026575   UnitTest-Assert-AreNotEqual-False
         Passed 00:00:00.0002841   UnitTest-Assert-AreNotEqual-True
         Passed 00:00:00.0009127   UnitTest-Assert-Exception-Catches
         Passed 00:00:00.0024734   UnitTest-Assert-Exception-Fails
         Passed 00:00:00.0018512   UnitTest-Assert-Fail-Throws
         Passed 00:00:00.0003367   UnitTest-Assert-IsEmpty-Empty
         Passed 00:00:00.0023150   UnitTest-Assert-IsEmpty-NotEmpty
         Passed 00:00:00.0003309   UnitTest-Assert-IsEmpty-Null
         Passed 00:00:00.0009576   UnitTest-Assert-IsFalse-False
         Passed 00:00:00.0034061   UnitTest-Assert-IsFalse-True
         Passed 00:00:00.0027255   UnitTest-Assert-IsNotEmpty-Empty
         Passed 00:00:00.0006728   UnitTest-Assert-IsNotEmpty-NotEmpty
         Passed 00:00:00.0023259   UnitTest-Assert-IsNotEmpty-Null
         Passed 00:00:00.0005195   UnitTest-Assert-IsNotNull-NotNull
         Passed 00:00:00.0028474   UnitTest-Assert-IsNotNull-Null
         Passed 00:00:00.0033201   UnitTest-Assert-IsNull-NotNull
         Passed 00:00:00.0009063   UnitTest-Assert-IsNull-Null
         Passed 00:00:00.0032649   UnitTest-Assert-IsTrue-False
         Passed 00:00:00.0009192   UnitTest-Assert-IsTrue-True

Last edited Oct 16, 2013 at 8:02 PM by RemcoKapinga, version 9