We have migrated to Delphi X Seattle.

We have migrated to Delphi X Seattle.  

We now find that many of our DUnit tests fail because the overridden constructor for our descendants of TTestCase is not being called.

Anyone know why that is?  Did DUnit change?  And how do you create a class without calling it's constructor, for heaven's sake?

Comments

  1. What was your previous version (of Delphi)?  Also which constructor exactly, are you overriding?  (In our testsuite there's only one place where a constructor is overridden, and indeed it's not called, although technically it's one of the alternative/optional/paramterised constructors so perhaps not all that surprising, and it turns out that's essentially redundant as well as it doesn't do anything other than call inherited, so in our case it doesn't matter and was never noticed.  --  Everything gets customized via overriding Setup/Teardown and class function Suite. I've got several versions of Delphi on this machine and have done some diffs between the TestFramework.pas files from each, and though there's some differences there's nothing jumping out yet to cause this.  Maybe haven't looked closely enough yet...)

    ReplyDelete
  2. Sorry, should have mentioned that we are coming from XE.  

    I just moved the work done in the constructor to the Setup (and destructor/teardown), and it is working.  

    Not sure how it ever did work.  ;-)

    ReplyDelete
  3. Nick Hodges Setup/Teardown is the place to use for DUnit.

    As for creating a class without calling its constructor, in Delphi you can have multiple constructors... including the original, non-virtual TObject.Create... which should have been made virtual long ago.

    (one of the very first classes I wrote back in Delphi 2 days was a "TVirtualConstructedObject" whose sole purpose was to introduce a virtual constructor...)

    ReplyDelete
  4. Eric Grange There isn't a Quality report about making Create virtual. Could you write one perhaps? I am struggling to explain it well enough to be persuasive in a QP report (not thinking well today.) I mean, it's either obvious or it's not, and I haven't written it well enough, so I ended up not submitting the QP item.

    ReplyDelete
  5. David Millington Such QP would be worthless because that change would probably break every code out there. It should have done in Delphi 1, now it's too late.

    ReplyDelete
  6. David Millington Allen Bauer also mentioned it a couple years ago, they are aware of it

    ReplyDelete
  7. Stefan Glienke bah, at least it would be a clean break, with 100% compiler support... unlike the horror of zero-based strings (which brought zero benefits), or the messy ARC/weakref implementation of mobile compilers.

    Last breaking change with compiler support was what... UnicodeString? and that one did not even have 100% compiler support (due to bug with single-character strings)

    ReplyDelete
  8. I guess there would be enough people calling the whambulance because a virtual ctor call over a static one is omg sooo much slower...

    ReplyDelete
  9. Stefan Glienke a naked TObject.Create has so much overhead these days that a virtual call would not be measurable (even the memory allocation times are not significant anymore)

    ReplyDelete
  10. Maybe we should add a QP? What are the reasons for it being virtual? I'm sure Allen is aware, but it's always good to have the item in the system...

    ReplyDelete
  11. Nick Hodges - Log in to EDN and go to Registered Users Downloads... I saw a hotfix there for DUnitX and I'm betting it fixes this.

    ReplyDelete
  12. Whoops, looks like you solved it. I jumped the gun.

    ReplyDelete
  13. Jeff Martin That DUnitX hotfix does not fix any issue - it just adds a line to the license header ;)

    ReplyDelete

Post a Comment