What's the proper way to test a class with private methods using JUnit?

What's the proper way to test a class with private methods using JUnit?

What's the proper way to test a class with private methods using JUnit?

View Answers

December 24, 2013 at 2:59 PM

Define private method in a class and using it in another class in a same package. Here is the source code:

Here is the example of Example of Finalize method in Java


December 24, 2013 at 3:02 PM

Here is an example:

Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
return method.invoke(targetObject, argObjects);
And for fields:

Field field = targetClass.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(object, value);









Related Tutorials/Questions & Answers:
What's the proper way to test a class with private methods using JUnit?
what is class methods in objective c
Advertisements
what is class methods in objective c
what is proper way to save pictures in SQl database and call it through JSP ?
using class and methods - Java Beginners
Private variable of class
java object class methods
can we use scanner class,class , object and methods to get output without using constructor ????
to create a java class and methods
Getting Methods Information of a class
What if the main() method is declared as private?
Retrieving the class name through Reflection API
What are weak methods?
What are the methods in Object? - Java Beginners
The ActionForm and what are important methods in ActionForm.
What modifiers are allowed for methods in an Interface?
PHP list class methods
Class AsyncEvent important methods
what is the size of java class
What do you understand by private, protected and public?
Calling Methods Using SpEL
write a program to demonstrate wrapper class and its methods......
variables and methods declared in abstract class is abstract or not
What is the best way to learn Bootstrap?
What is the best way to learn Bootstrap?
What is the best way to learn JavaScript?
What is the best way to learn java
What is the best way to learn JavaScript?
What is the fastest way to learn AI?
What is the best way to learn JavaScript?
creating class and methods - Java Beginners
What is an Abstract Class and what is it's purpose?
Abstract class,Abstract methods and classes
An application using swings and vector methods
What is Action Class?
What is an abstract class?
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays
What is final class?
What are the most common methods of Hibernate configuration?
Object Class Methods in Java
Java Abstract Class Example
What is Calendar class in Java?
What is the fastest way to read a file in Java?
Abstract class or methods example-1
What is the Locale class?
methods
methods
methods
What is the best way to filter a Java Collection?

Ads