Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Private methods

 
Ananth Ram
Ranch Hand
Posts: 99
  • 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
  • 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
  • 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: 34422
347
Eclipse IDE Java VI Editor
  • 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
  • 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: 34422
347
Eclipse IDE Java VI Editor
  • 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
  • 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.

[=
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic