From: Michael A. J. <csm...@ho...> - 2001-02-28 17:24:37
|
> If the only new behavior TBadDelegateContainer introduces is overriding the > constructor so it can create TBadDelegate, then there's not much to test. If > there's not much to test, then if your hierarchy explodes you still won't > have that much more to test. In fact, you could probably argue that each > constructor is not going to break, so don't test it. [snip] > I don't think I buy your easier to test argument ... unless you know > something I don't <g>. I'm not so much interested in testing the constuctor as I am in testing the behavior of the container in the prescense of the bad delegate. Now suppose you have another delegate in the class (not of the same type) that you also need to test the behavior of. In our real example, the container is a base class for creating log entries, the delegate checks to see if there is enough free disk space left to to write to disk. our bad delegate tells us that NO you don't (the original bad delegate wrote a 50GB temp file to insure you didn't (how I got drug into fixing this mess in the first place, this single test took 17 minutes to execute)) . When then introduced another delegate to help locate free disk space on other drives and continue operation. However, there are cases when this is going to fail, so we got tests and classes like this: TCheckFreeSpace, TBadFreeSpaceMock, TFreeSpaceLocator, TBadFreeSpaceLocatorMock then we got these derived classes: TLogEntry = class(TObjecT) { this one contains TBadFreeSpaceGoodLocatorLogEntry = TClass(TlogEntry); TBadFreeSpaceBadLocatorLogEntry = class(TLogEntry); TBadFreeSpaceGoodLocatorSensorEntry = TClass(TlogEntry); TBadFreeSpaceBadLocatorSensorEntry = class(TLogEntry); { more dervied for various types of equipment.....} Then we have similar combinations for some of the objects dervied from TLogEntry that create other log entries in other logs besides the main log that LogEntry updates. This is why I thought the registration function would be useful. > > Another thought -- could you add the class to the container constructor? > TContainer.create(ADelegateClass: TDelegateClass); > begin > delegate := ADelegateClass.create; > end; This might be a comprimise. assimilate the registration ito the constructor. Another thought inspired by this is to virtualize the alloccation of the delegate into a virtual function. Kind of like a psuedo factory. |