Over the last couple of weeks, I've letting coding get ahead of testing. The point of this methodology – with testing proceeding at the same time as coding – is to let the testing inform the coding.
I've decided to get back to it. I'm going to make sure I have tests for each method and constructor. I'm also going to make sure they are in files that are clearly named and have enough comments to follow the intent.
For instance, here is ClassSeatConstructor.ps1:
# Testing Seat Constructor
#
#
# Expected success:
$testSeat = new Seat(60)
# Test the Free property: On creation, should be Free.
$testSeat.Free = $true
if (!($testSeat.Free)) {"FAIL: Free should be True."}
$testSeat.Free = $false
if ($testSeat.Free) {"FAIL: Free should be False."}
# unacceptable values: 0, -1
try {
$testSeat = new Seat(0)
"FAIL: Invalid value did not cause exception."
}
catch {}
try {
$testSeat = new Seat(-1)
"FAIL: Invalid value did not cause exception."
}
catch {}
This script verifies that the constructor works. The initial state of the object has Free = True.
Then it tests to see that two unacceptable values are not permitted.
That test relies on testing code, so I should note that in the script.
What this test doesn't do is verify that the initial value is assigned. That will involve more testing code:
public int getUseTime()
{
return useTime;
}
And the test:
#verify initial state:
#USES TESTING CODE
$testSeat = new Seat(20)
if (!($testSeat.getUseTime() -eq 20)) {"FAIL: Initial state of Seat object should be 20."}
One down, 16 to go.
No comments:
Post a Comment