I’m doing a bunch of things over the next couple of weeks with FitNesse and DbFit, so I’ll be posting tips and tricks from the stuff I’m doing.
Today I had to calculate that a specific amount was updated in the database. Since I’m writing characterization tests, I can’t just modify the database to make things easier. Luckily the way Gojko wrote DbFit, it can help quite a bit.
Let’s say you have a transaction which adds a user to the database, but also updates some Active Users Count table. This isn’t what we were doing, but will make the story work. ;)
Your fixture may look something like:
|MyDoFixture|
|import|
|dbfit.fixture|
|Query|SELECT ActiveUserCount FROM ActiveUsersCount|
|ActiveUserCount?|
|>>countbeforetransaction|
|Add User To Table With Name|Justin Example|
|Query|SELECT ActiveUserCount FROM ActiveUsersCount|
|ActiveUserCount?|
|>>countaftertransaction|
|Query|SELECT (:countaftertransaction - :countbeforetransaction) As DiffCount|
|DiffCount?|
|1|
In other words, the parameters are actually just replaced before the query is run, so you can do things like this to make life easier. There may be a better way, but the problem I had was that the query to get the equivalent of the count above was rather lengthy.