-
Notifications
You must be signed in to change notification settings - Fork 5
TDD Style Tests
PSate has the concept of Test Groups and Test Cases, in TDD-Style tests, a "group" is a TestFixture
, and a "case" is a TestCase
. You can define your first test case like this:
TestFixture "Calculator" {
TestCase "Adds" {
1 + 1 | Should Be 2
}
}
NOTE: Should is from PShould. You should get it.
PSate will run the code in your test case. If it throws an assertion/exception, the test case fails. If there is no exception, the test case passes. The name of the case is used to identify the case in the output, as well as for test case filtering (see Filtering Tests with Invoke-Tests).
Since TestFixture is a group, you can add multiple test cases to it.
TestFixture "Calculator" {
TestCase "Adds" {
1 + 1 | Should Be 2
}
TestCase "Subtracts" {
1 - 1 | Should Be 0
}
}
You can also nest fixtures, if you want to group things. See Filtering Tests with Invoke-Tests for some reasons why you would do this.
TestFixture "Calculator" {
TestFixture "Binary Operations" {
TestCase "Adds" {
1 + 1 | Should Be 2
}
TestCase "Subtracts" {
1 - 1 | Should Be 0
}
}
TestFixture "Unary Operations" {
TestCase "Negative" {
-1 | Should Be (0 - 1)
}
}
}
You might also want to do some Setup/TearDown for your case, like creating files, etc. See Setup and TearDown for more information on this.
TestFixture "Calculator" {
# Setup
$x = 1
$y = 2
TestCase "Adds" {
$x + $y | Should Be 3
}
TestCase "Subtracts" {
$x - $y | Should Be -1
}
}