I'm new to jUnit and I'm trying to deep more my knowledge about it. I searched on the web but didn't found anything to solve a couple of doubts.
This is the code:
public class StringConverter {
public static String formatDate(Date date) {
DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return sdf.format(date);
}
}
This is the jUnit4 Test Case:
public class StringConverterTest {
@Test
public void testFormatDate() {
Calendar calendar = new GregorianCalendar(2013, 02, 13, 8, 30, 00);
assertEquals("13/03/2013 08:30:00", StringConverter.formatDate(calendar.getTime()));
}
}
The TestCase runs correctly without any problems but i have 2 simple questions/problems:
1) It's correct to test only the correct functionality of the method or should i test also null
values and/or any particular exception?
2) When i run the code coverage with EclEmma it gives me 75% code coverage because the test case is not testing the constructor of the StringConverter
class. Testing the StringConverter
class constructor is not in my plan since the StringConverter
class is a util class, so it won't be instanced. There is a way to exclude this from the code coverage?
Any advice wil be appreciated. Thanks.