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);

Ads









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 ?
can we use scanner class,class , object and methods to get output without using constructor ????
Getting Methods Information of a class
What if the main() method is declared as private?
What are weak methods?
Retrieving the class name through Reflection API
Class AsyncEvent important methods
What modifiers are allowed for methods in an Interface?
what is the size of java class
Calling Methods Using SpEL
What do you understand by private, protected and public?
write a program to demonstrate wrapper class and its methods......
variables and methods declared in abstract class is abstract or not
Abstract class,Abstract methods and classes
What is an Abstract Class and what is it's purpose?
An application using swings and vector methods
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 JavaScript?
What is the best way to learn java
What is the fastest way to learn AI?
What is the best way to learn JavaScript?
Java Abstract Class Example
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays
Object Class Methods in Java
What are the most common methods of Hibernate configuration?

Ads