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.

	@Test
	public void testPrivateConstructor() throws Exception {
		Constructor<?>[] cons = MyUtil.class.getDeclaredConstructors();
		cons[0].setAccessible(true);
		cons[0].newInstance((Object[])null);
	}

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.