tag:blogger.com,1999:blog-5794802768211098530.post3086800675843010797..comments2023-06-14T14:25:33.595+02:00Comments on Dev Experience: JUnit: How to test your private methodsAnonymoushttp://www.blogger.com/profile/01453456655661580489noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-5794802768211098530.post-70555440295700982152013-02-15T15:46:16.437+01:002013-02-15T15:46:16.437+01:00Tanks, good setup and very usable for testing priv...Tanks, good setup and very usable for testing private methodsAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-62843913004199178472011-03-20T20:05:32.577+01:002011-03-20T20:05:32.577+01:00@Carlos: I think dp4j.com offers a better or more ...@Carlos: I think dp4j.com offers a better or more elegant solution, with reflection being injected at compile-time.Simpaticohttps://www.blogger.com/profile/11296072654064015891noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-65553804013910107162009-08-30T16:50:51.444+02:002009-08-30T16:50:51.444+02:00Although I agree that sometimes you need to test y...Although I agree that sometimes you need to test your private method, most of the time, it may means that the class is doing more than one thing. There maybe something inside that class that could be extracted out and be made more reusable.<br /><br />A cohesive class would be small enough that testing the public methods would indirectly test all the private ones in all its permutations. Then again, that is the ideal case of course.<br /><br />You also have to remember that Reflection comes at a cost, namely it makes your test more resistant to refactoring. And that is not just the name changes. At times, the benefits might outweight the cost, using Reflections helps a lot in a lot of cases too (ie. framework building).<br /><br />That's just my opinion though. Then again, you are working with your own pet projects, so no need to be too strict for that matter ;-). There will be always time to refactor if needs be.fadzlanhttps://www.blogger.com/profile/15534128508178684488noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-78712905850186707642009-08-29T21:34:43.355+02:002009-08-29T21:34:43.355+02:00Aggggggg TCL! What a crap! ;-)
I have to say, that...Aggggggg TCL! What a crap! ;-)<br />I have to say, that the last week I have been working on a project where I am using reflection + groovy compile on runtime and my conclusion is that even if is dangerous, is just an amazing way to define new classes in runtime. So, I would say I love reflection also ;-)Unknownhttps://www.blogger.com/profile/00608660611313170613noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-13025427838753759292009-08-28T11:47:18.842+02:002009-08-28T11:47:18.842+02:00You can also implement your JUnit-Tests in Groovy ...You can also implement your JUnit-Tests in Groovy which can call private methods like any other method.Unknownhttps://www.blogger.com/profile/08589455876182943607noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-45129559435500668752009-08-28T09:10:02.435+02:002009-08-28T09:10:02.435+02:00Hi Casper,
Is not like I love the way the API is ...Hi Casper,<br /><br />Is not like I love the way the API is wrote. What I like is the flexibility that can give me when needed.<br /><br />The last years I've worked a lot with Tcl, and I must say that the flexibility that I have there is hard to find anywhere else (and really dangerous sometimes) ;)Anonymoushttps://www.blogger.com/profile/01453456655661580489noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-9797396805750325312009-08-28T03:34:49.339+02:002009-08-28T03:34:49.339+02:00I have to say you are the first and only one who I...I have to say you are the first and only one who I have ever heard of, who's a fan of the Java reflection API. :)Casper Banghttps://www.blogger.com/profile/09493174484116672294noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-69666629205891372652009-08-27T22:50:52.331+02:002009-08-27T22:50:52.331+02:00Hi Alex,
Thanks a lot for pointing this project. ...Hi Alex,<br /><br />Thanks a lot for pointing this project. I didn't knew about it :)Anonymoushttps://www.blogger.com/profile/01453456655661580489noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-71070372579609351992009-08-27T22:44:44.472+02:002009-08-27T22:44:44.472+02:00Hello
I'd like to suggest to use FEST-Reflect...Hello<br /><br />I'd like to suggest to use FEST-Reflect instead of raw Java Reflection. This project provides a fluent interface and a little more type safety. It makes Reflection a lot easier to use :)<br /><br />http://fest.easytesting.org/reflect<br /><br />Disclaimer: I'm the creator of FEST-Reflect<br /><br />Cheers,<br />-AlexAnonymoushttps://www.blogger.com/profile/17146635182338081808noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-63480961023832637202009-08-27T15:25:06.137+02:002009-08-27T15:25:06.137+02:00Hi Dani,
Even when you're right, there's ...Hi Dani,<br /><br />Even when you're right, there's always an exception to the rule ;)<br /><br />My class works with files. I have some methods that do some parsing on the filenames to retrieve some info. To have a nice wrapping test I cannot have tons of files, so I use the default class constructor (no arguments). Now I have an empty instance of my class since I didn't use the real constructor.<br /><br />The only way I found to solve this situation was to directly access the private methods that are used by my class constructor.<br /><br />In this way I can simulate a real environment :)Anonymoushttps://www.blogger.com/profile/01453456655661580489noreply@blogger.comtag:blogger.com,1999:blog-5794802768211098530.post-85367369067400023492009-08-27T08:31:56.140+02:002009-08-27T08:31:56.140+02:00nice trick! but appart of that, what is the point?...nice trick! but appart of that, what is the point? From the point of view of good coding, a private method should be only invoked by public methods or the constructor of a class, which means that is accessible for testing by invoking the public method that is going to call them. So, by writting a test for the public method, you are testing the privated ones!Unknownhttps://www.blogger.com/profile/00608660611313170613noreply@blogger.com