Rookie
Rookie

Reputation: 33

Unit tests file IO java

I am trying to write a unit tests on a class that dynamically creates java classes using data from XLS file. All the write methods I used are private. I have one public method in the same class that makes a call to all these private write methods. Can some one tell me how to write unit tests for this scenario.

Upvotes: 1

Views: 287

Answers (2)

Akah
Akah

Reputation: 1920

You can do this by two ways :

By reflection, like shown here :

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

Or you cant use PowerMock if you want to mock private methods.

Upvotes: 0

Sleiman Jneidi
Sleiman Jneidi

Reputation: 23349

Private methods should be used internally in the class, and hence you don't need to test them, because by testing the public ones, your are indirectly testing the private ones. Unless they are never used, then you delete them so you don't have them in the first place.

Upvotes: 1

Related Questions