-
Notifications
You must be signed in to change notification settings - Fork 5
BDD Style Tests
PSate has the concept of Test Groups and Test Cases, in TDD-Style tests, a "group" is a TestScope
, Describing
, or Given
block, and a "case" is an It
block. You can define your first test case like this:
Describing "Calculator" {
Given "two numbers" {
It "adds them" {
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 Given is a group, you can add multiple test cases to it.
Describing "Calculator" {
Given "two numbers" {
It "adds them" {
1 + 1 | Should Be 2
}
It "subtracts them" {
1 - 1 | Should Be 0
}
}
}
You can also group Describing blocks with a TestScope, if you want to group things. See Filtering Tests with Invoke-Tests for some reasons why you would do this.
Describing "Calculator" {
Given "two numbers" {
It "adds them" {
1 + 1 | Should Be 2
}
It "subtracts them" {
1 - 1 | Should Be 0
}
}
Given "one number" {
It "negates it" {
-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.
Describing "Calculator" {
Given "two numbers" {
# Setup
$x = 1
$y = 2
It "adds them" {
$x + $y | Should Be 3
}
It "subtracts them" {
$x - $y | Should Be -1
}
}
}