You can test a private constructor by using Reflection. Insert the following code in your unit test class:
1 2 3 4 5 6 7 8 9 |
import java.lang.reflect.Constructor; @Test public void privateConstructorTest() throws Exception { Constructor<MyClass> constructor = MyClass.class.getDeclaredConstructor(); assertEquals(constructor.isAccessible(), false); constructor.setAccessible(true); constructor.newInstance((Object[]) null); } |