Re: Title: JUnit 4.9b2 (beta-)released
David Gageot <[email protected]> Fri, 4 Feb 2011 16:33:12 +0100
| Newsgroups | gmane.comp.java.junit.user,gmane.comp.java.junit.devel |
|---|---|
| Message-ID | <[email protected]> |
> > On Thu, Feb 3, 2011 at 4:32 PM, dgageot <[email protected]> wrote: >> > Hi, everyone. Thank you for the good work. >> > >> > I was wondering, what made you choose TestRule to be an abstract class >> and not an interface? This is so much of a pain. >> > > JUnit4 provides a number of base classes for Rule implementations already > (Verifier, ExternalResoruces, etc). Anyone wanting to reuse that behavior > already had to lose the inheritance slot. > That's true. And I do prefer 'cannot inherit sometimes' than 'cannot inherit ever'. > In your position, I'd also be frustrated. >> >> > The class being empty, I don't get it. >> >> The idea was to guide people away from an improper usage of Rules. >> For example, calling Timeout.apply in the middle of a test method is >> so likely to be the wrong thing to do, that we wanted to make it >> difficult. If there were some way for a rule to expose one interface >> to the framework, and another to test writers, that would be ideal. >> This seemed like the next-best solution. >> > Seems logical to me. Didn't realize that the benefit was hidden in the 'protected' keyword :-) We could check at runtime that the method is being called properly but that would be less elegant and could be tricky. > >> > One of my custom Rules needs to extend a class already. > > > I would also be interested in understanding the use case. > > Since there is only one method in TestRule, it's very easy to use > delegation instead of inheritance to reuse the code in your base class. > The class I inherit from has dozens of methods. That's not the best use case of delegation. However, I ended up doing exactly that. Overall when I design code, I prefer interfaces over inheritance, but I > believe we should optimize for developers that use Rules over developers > that create new Rule implementations; it's by far the most common case. A > large number of Java developers use IDEs, and having the IDE suggest a > completion that a test should never call is a poor and confusing experience. > Agree 100%. Thanks for the insights, David. [Non-text portions of this message have been removed] ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/junit/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/junit/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/