Michael Domashchenko
Michael Domashchenko

Reputation: 1480

Calling methods on System Under Test

When using DoFixture I can set a domain object as System Under Test which allows me to call methods on that object instead of the fixture itself.

Unfortunately, if such a method requires more than one parameter I have to separate those parameters with empty cells because otherwise fitnesse/fitSharp uses odd/even cells to build up the method name. I can see how this makes my tests to resemble plain English better, but it's not really feasible to start renaming domain object methods just to satisfy test framework requirements.

For example, say I want to call method Entry AddEntry(string name, string description) and store the result as symbol e1. If I try the following table:

|name|e1|add entry|sample name|sample description|

it will try to find a method named AddEntrySampleDescription and pass it a single parameter "sample name".

I can do

|name|e1|add|sample name|entry|sample description|

but it just doesn't look right.

So, what I ended up doing is (note the extra empty cell between the parameters)

|name|e1|add entry|sample name||sample description|

which does what I want and isn't as ugly as the option #2 but it still seems like a hack. Do I miss something or is that actually the way to call methods on domain objects?

Upvotes: 3

Views: 156

Answers (1)

Mike Stockdale
Mike Stockdale

Reputation: 5266

You can add the empty cell between parameters - this is a widely-used technique. Or you can use SequenceFixture:

http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.FitLibraryFixtures.SequenceFixture

SequenceFixture is very similar to DoFixture and has almost the same features — in fact the only difference between those two is the naming convention for methods. Instead of using odd cells to construct a method name, SequenceFixture takes the first cell in each row as the method name, and all other cells as arguments

Upvotes: 3

Related Questions