@@ -41,6 +41,10 @@ Depending on the labels in the pull requests, the workflow will result in differ
4141 - This produces a json based report that is used to later evaluate the results of the tests.
4242- [ Test module] ( ./.github/workflows/Test-ModuleLocal.yml )
4343 - Import and tests the module in parallel (matrix) using Pester tests from the module repository.
44+ - Supports setup and teardown scripts:
45+ - ** BeforeAll.ps1** : Runs once before all test matrix jobs to set up test environment (e.g., deploy infrastructure, download test data)
46+ - ** AfterAll.ps1** : Runs once after all test matrix jobs complete to clean up test environment (e.g., remove test resources, cleanup databases)
47+ - Setup/teardown scripts are automatically detected in test directories and executed with the same environment variables as tests
4448 - This produces a json based report that is used to later evaluate the results of the tests.
4549- [ Get test results] ( ./.github/workflows/Get-TestResults.yml )
4650 - Gathers the test results from the previous steps and creates a summary of the results.
@@ -257,6 +261,46 @@ Build:
257261| `Verbose` | `boolean` | Whether to enable verbose output. | `false` | `false` |
258262| `WorkingDirectory` | `string` | The path to the root of the repo. | `false` | `.` |
259263
264+ # ## Setup and Teardown Scripts
265+
266+ The workflow supports automatic execution of setup and teardown scripts for module tests :
267+
268+ # ### BeforeAll.ps1
269+ - **Location**: Place in your test directories (e.g., `tests/BeforeAll.ps1`)
270+ - **Purpose**: Runs once before all test matrix jobs to prepare the test environment
271+ - **Use cases**: Deploy test infrastructure, download test data, initialize databases, configure services
272+ - **Environment**: Has access to the same environment variables as your tests (secrets, GitHub token, etc.)
273+
274+ # ### AfterAll.ps1
275+ - **Location**: Place in your test directories (e.g., `tests/AfterAll.ps1`)
276+ - **Purpose**: Runs once after all test matrix jobs complete to clean up the test environment
277+ - **Use cases**: Remove test resources, cleanup databases, stop services, upload artifacts
278+ - **Environment**: Has access to the same environment variables as your tests
279+
280+ **Example BeforeAll.ps1:**
281+ ` ` ` powershell
282+ Write-Host "Setting up test environment..."
283+ # Deploy test infrastructure
284+ # Download test data
285+ # Initialize test databases
286+ Write-Host "Test environment ready!"
287+ ` ` `
288+
289+ **Example AfterAll.ps1:**
290+ ` ` ` powershell
291+ Write-Host "Cleaning up test environment..."
292+ # Remove test resources
293+ # Cleanup databases
294+ # Stop services
295+ Write-Host "Cleanup completed!"
296+ ` ` `
297+
298+ **Notes:**
299+ - Scripts are automatically detected and executed if present
300+ - Each unique test directory path is processed only once
301+ - Scripts run with PowerShell and have access to PSModuleHelpers
302+ - If no scripts are found, the workflow continues normally
303+
260304# ## Secrets
261305
262306The following secrets are used by the workflow. They can be automatically provided (if available) by setting the `secrets : inherit`
0 commit comments