Although the test table in Figure 6.1, “DoFixture script looks like a story”
looks nice, it has one serious flaw. Change the test to check that John has 50 dollars at the
end and run it again. You see that the test failed,
but not how much money John actually had.
If you used ColumnFixture
for this, it would print both the expected and actual values.
Having this extra bit of information is
very helpful for troubleshooting.
DoFixture can do something similar: prefix the row content
with
check
and put the expected value in the last cell. Then change the
comparison method to return the actual value, instead of
just
true/false:
Tristan/test/PurchaseTicket.cs
103 public int TicketsInDrawOn(DateTime date)
104 {
105 return SetUpTestEnvironment.drawManager.
106 GetDraw(date).Tickets.Length;
107 }
108 public decimal PoolValueForDrawOnIs(DateTime date)
109 {
110 return SetUpTestEnvironment.drawManager.
111 GetDraw(date).TotalPoolSize;
112 }
113 public decimal AccountBalanceFor(String username)
114 {
115 return SetUpTestEnvironment.playerManager.
116 GetPlayer(username).Balance;
117 }
Run the test again, and FitNesse displays both expected and actual results (see Figure 6.2, “Use the check keyword to see both expected and actual results in case of problems”). The new comparison method even has a bit less code than the old one.
If you just want to see the result of a method or property value
without actually testing anything
(equivalent of an empty cell in
ColumnFixture), prefix the row with
show without
appending anything to the end. FitNesse adds a cell to the test results
showing the current value.
We can use keywords
not
and
reject
to check for errors or failed tests. We
can now
complete our tasks for this chapter by checking what happens
when the player does not have enough money.
16 |Purchase Ticket| 17 |Player|john|Deposits|50|dollars with card|4111111111111111|and expiry date|01/12| 18 |reject|Player|john|buys|10| tickets with numbers|1,3,4,5,8,10| for draw on |01/01/2008| 19 |Check|Pool value for draw on |01/01/2008|is|0| 20 |Check|Account balance for |john|50| 21 |Check|Tickets in draw on |01/01/2008|0| 22 |not|Ticket with numbers|1,3,4,5,8,10| for |100| dollars is registered for player|john| for draw on |01/01/2008|
There is one more interesting
DoFixture
keyword:
note.
Prefix a row with note
to turn it into a comment.




