blade.ps1

Runs Blade tests in a file or directory.

Syntax

blade.ps1 [-Path] <String[]> [-Name <String>] [-Test <String[]>] [-XmlLogPath <String>] [-PassThru] [-Recurse] [<CommonParameters>]

Description

The blade.ps1 script, located in the root of the Blade module, is the script used to execute Blade tests. Given a path, it runs tests in any PowerShell script that begins with Test- (i.e. that matches the wildcard pattern Test-*.ps1. Tests are functions that that use the Test verb (i.e. whose name match the Test-* wildcard pattern).

When executing tests, blade.ps1 does the following:

By default, Blade returns Blade.TestResult objects for each failed test.

After running all tests, blade.ps1 will write an error if any tests failed, then write a summary of the test run. The results of the last test run is available as a Blade.RunResult object in a global $LastBladeResult variable, e.g.

> .\Blade\blade.ps1 .\Test

   Count Failures   Errors  Ignored Duration        
   ----- --------   ------  ------- --------        
      47        0        0        0 00:00:11.6870000



> $LastBladeResult | Format-List


Count        : 47
Name         : 
Passed       : {Test-ShouldDetectNoErrors, Test-ShouldThrowErrorIfNeedleMissingFromFile, Test-ShouldFailIfFileZeroBytes, Test-ShouldFailIfFileEmpty...}
Failures     : {}
Errors       : {}
IgnoredCount : 0
Duration     : 00:00:11.6870000

If you want Blade to return objects for each test, regarless if it failed or not, use the -PassThru switch.

You can run specific test(s) by passing names to the Test parameter. Do not include the Test- verb/prefix.

blade.ps1 can also save test results as an NUnit XML report, so you can integrate test results into build servers and other reporting tools. Use the XmlLogPath parameter to specify the path to a log file. The file, and its parent directories, will be created if it doesn't exist.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String[]

The paths to search for tests. All files matching Test-*.ps1 will be run.

true false
Name String

The name of the tests being run.

false false
Test String[]

The individual test in the script to run. Defaults to all tests. Do not include the Test- verb/prefix.

false false
XmlLogPath String

Path to the file where XML results should be saved. This file, and its parent directories, will be created if they don't exist.

false false
PassThru SwitchParameter

Return objects for each test run, and a final summary object.

false false False
Recurse SwitchParameter

Recurse through directories under $Path to find tests.

false false False

EXAMPLE 1

.\blade Test-MyScript.ps1

Will run all the tests in the Test-MyScript.ps1 script.

EXAMPLE 2

.\blade Test-MyScript.ps1 -Test MyTest

Will run the MyTest test in the Test-MyScript.ps1 test script.

EXAMPLE 3

blade .\MyModule

Will run all tests in the files which match the Test-*.ps1 wildcard in the .\MyModule directory.

EXAMPLE 4

blade .\MyModule -Recurse

Will run all test in files which match the Test-*.ps1 wildcard under the .\MyModule directory and its sub-directories.