Skip to content

Test-PSModule (by PSModule)

Actions
Test a PowerShell module before publishing the module to the PowerShell Gallery
v2.1.5
Latest
Verified creator
Star (2)

Verified

GitHub has manually verified the creator of the action as an official partner organization. For more info see About badges in GitHub Marketplace.

Test-PSModule

Test PowerShell modules with Pester and PSScriptAnalyzer.

This GitHub Action is a part of the PSModule framework. It is recommended to use the Process-PSModule workflow to automate the whole process of managing the PowerShell module.

Specifications and practices

Test-PSModule enables:

How it works

The action runs the following the Pester test framework:

  • PSScriptAnalyzer tests
  • PSModule framework tests
  • If TestType is set to Module:
    • The module manifest is tested using Test-ModuleManifest.
    • The module is imported.
    • Custom module tests from the tests directory in the module repository are run.
    • CodeCoverage is calculated.
  • If TestType is set to SourceCode:
    • The source code is tested with:
      • PSScriptAnalyzer for best practices, using custom settings.
      • PSModule.SourceCode for other PSModule standards.
  • The action returns a passed output that is true if all tests pass, else false.
  • The following reports are calculated and uploaded as artifacts:
    • Test suite results.
    • Code coverage results.

The action fails if any of the tests fail or it fails to run the tests. This is mitigated by the continue-on-error option in the workflow.

How to use it

To use the action, create a new file in the .github/workflows directory of the module repository and add the following content.

Workflow suggestion - before module is built
name: Test-PSModule

on: [push]

jobs:
  Test-PSModule:
    name: Test-PSModule
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Initialize environment
        uses: PSModule/Initialize-PSModule@main

      - name: Test-PSModule
        uses: PSModule/Test-PSModule@main
        with:
          Path: src
          TestType: SourceCode
Workflow suggestion - after module is built
name: Test-PSModule

on: [push]

jobs:
  Test-PSModule:
    name: Test-PSModule
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Initialize environment
        uses: PSModule/Initialize-PSModule@main

      - name: Test-PSModule
        uses: PSModule/Test-PSModule@main
        with:
          Path: outputs/modules
          TestType: Module

Usage

Inputs

Name Description Required Default
Path The path to the code to test. true
TestType The type of tests to run. Can be either Module or SourceCode. true
Name The name of the module to test. The name of the repository is used if not specified. false
TestsPath The path to the tests to run. false tests
StackTraceVerbosity Verbosity level of the stack trace. Allowed values: None, FirstLine, Filtered, Full. false Filtered
Verbosity Verbosity level of the test output. Allowed values: None, Normal, Detailed, Diagnostic. false Detailed
Debug Enable debug output. 'false' false
Verbose Enable verbose output. 'false' false
Version Specifies the version of the GitHub module to be installed. The value must be an exact version. false
Prerelease Allow prerelease versions if available. 'false' false

Outputs

Name Description Possible values
passed If the tests passed. true, false

PSModule tests

The PSModule framework tests verifies the following coding practices that the framework enforces:

  • Script filename and function/filter name should match.

Tools

Test-PSModule (by PSModule) is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Test a PowerShell module before publishing the module to the PowerShell Gallery
v2.1.5
Latest

Verified

GitHub has manually verified the creator of the action as an official partner organization. For more info see About badges in GitHub Marketplace.

Test-PSModule (by PSModule) is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.