If you use cobertura for checking your jUnit code coverage, you have probably also encountered the problem that private constructors cannot be covered. All your classes have 100% coverage but your utillity classes with private constructors stick at 90 or 95% (or even less). Those red sections in the cobertura overview annoyed the hell out of me so I did some research and found a solution using Java reflection.

	public void testPrivateConstructor() throws Exception {
		Constructor<?>[] cons = MyUtil.class.getDeclaredConstructors();

Just add this test to one of your unit tests and replace “MyUtil” with your class and tada!! your private constructor is covered.

Of course, code coverage is not a measure of quality but you get my point.