This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Private methods

 
Ananth Ram
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

I am newbie writing test case for a class. I want to test the private methods using junit. How do I accomplish the same.



Thanks,
Ananth Ram
 
Ananth Ram
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

of course, the class have a public method that calls the private method.



How do I test the private methods in the above class. Someone please advice and help me on the same.

Thanks,
Ananth Ram
 
Ananth Ram
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Took the package level access, and it works.

Thanks,
Ananth Ram.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, package access is the traditional solution.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Yes, package access is the traditional solution.

Would you please explain what do you mean by this?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making a method package private rather than private so the test can call it.

I recognize some disagree and there are other approaches. However, as far as I know, this is the most common.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can test the public test that access the privates one. Sometime it is a better solution than changing the package.

[=
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic