Joe White’s Blog

Life, .NET, and Cats


Correction: dSpec does have the optional Message parameter

In my last post, I incorrectly said that dSpec doesn’t have the Message parameter. Jody corrected me. Here’s the syntax:

Specify.That(FRate, 'Tax rate').Should.Equal(0.10);

I kinda like this syntax — it puts the label right next to the thing it’s labeling, rather than putting the label last like DUnitLite does now. What do you guys think? Which of the following syntaxes would be best for DUnitLite?

Specify.That(FRate, Should.Equal(0.10), 'Tax rate'); // (a)
Specify.That(FRate, 'Tax rate', Should.Equal(0.10)); // (b)
Specify.That('Tax rate', FRate, Should.Equal(0.10)); // (c)

Currently DUnitLite uses (a). (b) is more like dSpec.

The advantage to (c) would be when your expressions are long enough to line-wrap. If the label is likely to be shorter than the expression being tested (and, therefore, more likely to fit on the first line without wrapping), then this kind of formatting might work really well:

Specify.That('State tax rate',
TInvoiceCalculator.CreateForState(FCustomer.State).TaxRate,
Should.Equal(0.10));

But without wrapping, having a label as the first parameter might get in the way of readability. I’m not sure.

Which syntax seems most readable to you?

4 Responses to “Correction: dSpec does have the optional Message parameter”

  1. Samuel Tesla Says:

    The reason that dSpec can do it that way, though, is that the conditions are specified with later method calls. If you’re going to put the message in the middle of an argument list, then it will become impossible for that message to be optional.

    Considering that well-written tests frequently don’t need assertion messages, it would be a real hassle to always have to provide them.

  2. Heinz Zastrau Says:

    what do you think about this syntax :-)

    Specify(’Tax rate’).That(FRate, Should,Equal(0.10));

    Ciao Heinz Z.

  3. Joe White Says:

    Sam: Of course I wouldn’t make Message a required parameter — most of the time you don’t need it. I would overload the method so you could either pass it or not. And that’s easy whichever of the three syntaxes I use.

  4. Joe White Says:

    Heinz: I don’t really care for that syntax, for two reasons: it’s less readable (it’s not worded the way you would actually write a sentence); and it would require Specify to be a unit procedure, rather than a class (and I prefer to avoid unit procedures if I possibly can).

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2008. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS).