Java Coder
What's the proper way to test a class with private methods using JUnit?
2 Answer(s)      a year and 6 months ago
Posted in : Java Beginners

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

Advertisement
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:
Advertisements