[hemmerling] Scripting Languages for Windows 3/3 - Testing with Windows PowerShell

Windows Powershell - Script Testing

Static Testing

"ScriptCop" - Coding Rules Checker

The Tool
Resources

Dynamic Testing

Jester by Misha Bergal

  • Though not suggested by the author in his example code, Jester may be installed in the Powershell module directory.
  • Installation:
    • Installation by NuGet:
      1. Download “Jester” to your local directory by “NuGet install Jester”.
      2. Copy the directory “Jester.0.0.1” to the PowerShell module directory
      3. Rename the directory “Jester.0.0.1” it to “Jester”.
    • Installation by GitHub:
      1. Download the archive “Jester-master.zip” from GitHub to a local directory.
      2. Unzip the archive “Jester-master.zip”, so that the directory “Jester-master” is created.
      3. Copy the directory “Jester-master\src” to the PowerShell module directory.
      4. Rename the directory “src” it to “Jester”.
    • Last step of Installation: Add to “Microsoft.PowerShellISE_profile.ps1”:
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Bypass
Unblock-File C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Jester\*.ps1
Import-Module Jester

Using NUnit for PowerShell Script Testing

PSTest by Knut Kristian Johansen
Some other NUnit based Tools

Pester - BDD Framework for Windows PowerShell

Tools
Tips & Tricks
  • Installation:
    • Installation by NuGet:
      1. Download “Pester.3.3.9” to your local directory by “NuGet install Pester”.
      2. Copy the directory “tools” to the PowerShell module directory
      3. Rename the directory “tools” it to “Pester”.
    • Installation by GitHub:
      1. Download the archive “Pester-master.zip” from GitHub to a local directory.
      2. Unzip the archive “Pester-master.zip”, so that the directory “Pester-master” is created.
      3. Copy the directory “Pester-master” to the PowerShell module directory.
      4. Rename the directory “Pester-master” it to “Pester”.
    • Last step of installation: Add to “Microsoft.PowerShellISE_profile.ps1”:
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Bypass
Unblock-File C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Pester\Functions\*.ps1
Unblock-File C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Pester\Functions\Assertions\*.ps1 
Import-Module Pester

PSUnit by Klaus Graefensteiner

Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Bypass
.  C:\Users\Administrator\Documents\windowspowershell\profile.ps1
. PSUnit.ISE.ps1
  • Preparation for operation:
    • Create batch files to execute the test runner “PSUnit.Run.ps1” ( which is by installation in your system path PATH ), e.g. batch file “run_darth.bat” with the script instructions
      • “powershell PSUnit.Run.ps1 .\Darth-Enumerator.Test.ps1”.
  • Logging:
    • Logging files ( e.g. “PSUnitTestReport_Darth-Enumerator.Test.ps1_2015-06-03-19-45-03_T43P37F6S0.html” ) are created by default in the installation directory :-(, i.e. not in the user directory ( e.g. “C:\users\<username>\PSUnitTest” ).

PSUnit by lidingshan

  • Installation by GitHub:
    1. Download the archive “PSUnit-master.zip” from GitHub to a local directory.
    2. Unzip the archive “PSUnit-master.zip”, so that the directory “Pester-master” is created.
    3. Copy the directory “PSUnit-master” to the PowerShell module directory.
    4. Rename the directory “PSUnit-master” it to “PSUnit”.
  • Right now, PSUnit cannot handle the comments in test scripts. So even if one function has been commented, like ”# function test_add()”, PSUnit will still run this test.

PSUnitTesting by Leonard Erwine

  • Installation by GitHub:
    1. Download the archive “PSUnitTesting-master.zip” from GitHub to a local directory.
    2. Unzip the archive “PSUnitTesting-master.zip”, so that the directory “Pester-master” is created.
    3. Copy the directory “PSUnitTesting-master” to the PowerShell module directory.
    4. Rename the directory “PSUnitTesting-master” it to “Pester”.
  • Preparation for operation:
    • Create batch files to execute the test runner “ModuleTests.ps1”, e.g. for Windows
      • A batch file “RunTests.bat” with the script instructions
        • “powershell -file ”.\Code\ModuleTests.ps1” %1 -ExecutionPolicy Bypass”.
      • You must call the application by “RunTests.bat MyScript.ps1” to test your script “MyTest.ps1”.
      • Unfortunately, no test scripts are provided... :-(.

Test Run by James McCaffrey

Code & Tutorial
Resources

Whatif

Windows Powershell based Testing of Software and Hardware

 
en/wscripting03.html.txt · Last modified: 2017/10/20 13:01 (external edit) · []
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki