Joe White’s Blog

Life, .NET, and Cats


DUnitLite 0.4: bugfixes and Should.ReferTo

Version 0.4 of DUnitLite is available. It fixes a couple of fairly major bugs (noted below) and adds a minor new feature.

Download it here: DUnitLite 0.4

What is DUnitLite?

For those who don’t remember, DUnitLite is my set of add-ons to DUnit to make assertions more readable, in the spirit of NUnit’s Assert.That(...) assertions (originally from NUnitLite). For example:

Specify.That(Foo, Should.Equal(45));
Specify.That(Bar, Should.Not.Equal(45));
Specify.That(Baz, Should.Be.AtLeast(40));
Specify.That(Quux, Should.Be.OfType(TSpecialQuux));

What’s new in 0.4

  • BUG: When you used TInsulatedTest (or TSpecification), DUnit was unable to count the number of passing tests — it just reported 0 tests run. Fixed.
  • BUG: When you used TInsulatedTest (or TSpecification), the test-suite nodes were labeled “TInsulatedTest” instead of the actual class name. Fixed.
  • NEW: Added Should.ReferTo(...) (reference equality check). Currently only works for objects, not interfaces.

Score one for dogfood

I’m using DUnitLite to write the tests / specifications for Tyler, so I’m quickly running into its bugs and limitations. This is the first time I’ve seriously tried to use DUnitLite in a project (its use of records-with-methods would reliably crash the pre-SR1 Delphi 2006 compiler we had at work at the time, and I never got back to it), so this is the first time I’ve actually noticed these gaping holes.

Fortunately, I wrote DUnitLite, so it’s really easy for me to fix the bugs. Don’t be surprised if you see a few more releases in the near future.

6 Responses to “DUnitLite 0.4: bugfixes and Should.ReferTo”

  1. Lars Fosdal Says:

    One good thing with Assert is the ability to compile with asserts in or out.
    How does that work with DUnitLite?

  2. Joe Says:

    It works the same way as with DUnit (since it’s built on top of DUnit): you don’t ever compile your unit tests into your production app in the first place. So asserted vs. non-asserted doesn’t matter.

    At work, we put all of our unit tests into separate units. A unit called Accounts.pas would have a corresponding AccountTests.pas. AccountTests will use Accounts, but never the other way around. So none of those test units are ever compiled into our production app, which effectively gets what I think you’re looking for, i.e., the production app isn’t filled with test code.

    Then we have a separate project named Tests.dpr. We compile all of our test units into this app (and only this app), and it’s what launches the DUnit test runner. And you’d better believe that all of those tests are compiled in, whether it’s an asserted build or not — if our tests didn’t do anything, it would defeat the whole purpose of having automated tests in the first place!

  3. Patrick van Logchem Says:

    I’d like to point out two things:

    1) When DecimalSeparator is set to anything else than “.”, some tests fail

    2) Additional implicit operators could be added via a class helper, so Values.pas won’t need changing.
    Alas, Delphi doesn’t allow operator overloaders on record helpers (or class helpers for that matter).
    (I’m thinking of requesting this in QualityCentral)

    Cheers

  4. Lars Fosdal Says:

    I see. I guess I was approaching the subject from a “programming by contract” perspective. I usually put Asserts in primitives to ensure I don’t feed them silly things in the dev.testing.

    But … (playing at devil’s advocate- note that I haven’t really used NUnit or DUnit) …
    What is wrong with:

    Assert(Foo = 45);
    Assert(Bar 45);
    Assert(Baz >= 40);
    Assert(Quux is TSpecialQuux);

    ?

  5. Lars Fosdal Says:

    (except the assertion exception ><)

    NOW I get it :P

  6. Joe Says:

    Patrick: Yes, it would be way cooler if you could add implicit operators via class helpers. Alas.

    And I’ll make a note to check on that DecimalSeparator thing. That never occurred to me (as you noticed). Thanks!

    Lars: Yeah, looks like you got it — the difference is in how much information you see when it fails. Sometimes knowing that Foo wasn’t 45 is only half the battle — you want to know what it was! Assert() doesn’t give you that, and neither do DUnit’s most simplistic methods, Check(Boolean) and Fail(). CheckEquals and friends are much preferred because they do give you the better information. So does DUnitLite, but with DUnitLite, your code is easier to read (because things are the right way around).

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).