aspose file tools*
The moose likes Testing and the fly likes Private methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Private methods " Watch "Private methods " New topic
Author

Private methods

Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99

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

Joined: Jan 18, 2001
Posts: 99

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

Joined: Jan 18, 2001
Posts: 99
Took the package level access, and it works.

Thanks,
Ananth Ram.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30894
    
158

Yes, package access is the traditional solution.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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

Joined: May 26, 2003
Posts: 30894
    
158

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

Joined: Jul 14, 2010
Posts: 754

Or you can test the public test that access the privates one. Sometime it is a better solution than changing the package.

[=


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
 
Don't get me started about those stupid light bulbs.
 
subject: Private methods