Skip to content
Jon Wagner edited this page Feb 18, 2013 · 1 revision

A Quick Tour of PSate

PSate lets you write your PowerShell test cases in a TDD- or BDD-style syntax, including

TDD-style (see TDD-Style Tests):

TestFixture "Calculator" {
	TestSetup {
		$x = 1
		$y = 2
	}

    TestCase "Adds" {
        $x + $y | Should Be 3
    }

    TestCase "Subtracts" {
        $x - $y | Should Be -1
    }
}

BDD-style (see BDD-Style Tests):

Describing "Calculator" {
	Given "1 and 2" {
		TestSetup {
			$x = 1
			$y = 2
		}

        It "Adds" {
            $x + $y | Should Be 3
        }

        It "Subtracts" {
            $x - $y | Should Be -1
        }
    }
}

You can group your test cases any way you want, and nest the grouping as much as you want.

If you name your test scripts with ".Tests.ps1", you can also run them with Invoke-Tests (see Running Tests with Invoke-Tests:

  • Test1.Tests.ps1
  • Test2.Tests.ps1

The following will run all of the test files and output the results

Invoke-Tests .

Since we are in PowerShell, we will probably be dealing with files and folders. PSate can manage temp folders, files, and registry entries for you automatically. See Temporary Files and Resources.

Auto-tempfile support:

Describing "FileStuff" {
    Given "nothing" {
        It "can create a test file" {
            # create a file
            $file = New-TestFile

            # do something with it

			# automatically cleaned up
        }
    }
}