-
Notifications
You must be signed in to change notification settings - Fork 5
Your Own Style Tests
Jon Wagner edited this page Feb 18, 2013
·
2 revisions
Perhaps you don't like TDD- or BDD-Style Tests. You can make your own test framework with the Test-Case function.
In fact, TestFixture, TestCase, TestScope, Describing, Given, and It all just call Test-Case.
function Describing {
Test-Case "Describing" @args @PSBoundParameters -Group
}
function Given {
Test-Case "Given" @args @PSBoundParameters -Group
}
function It {
Test-Case "It" @args @PSBoundParameters
}
Test-Case just defines a test block that is either a group or a case. It gets that from the -Group switch. The first parameter is just the name output to the test log so things look pretty. You could just as easily make a PowerShell test framework like this:
TestScript "script.ps1" {
TestFunction "myfunction" {
TestCase "does something" {
}
}
}
You can have Setup/TearDown in any test group. Setup/TearDown is automatically executed once per inner test context (i.e. inner group or inner case). You cannot have a Setup/TearDown in a test case. For that, just use try/finally.