I am carrying out unit testing for my project but i am not sure i am doing it correctly. The example below calculates the difference between 2 time duration's.
public void diffTime2() throws Exception {
//Calculsates the difference
String ExpectedResult = "1:0:0";
String str_time1 = "04 13, 2018 09:00:00";
String str_time2 = "04 13, 2018 08:00:00";
DateFormat simpleDateFormat3 = new SimpleDateFormat("MM dd, yyyy HH:mm:ss");
Date date1 = simpleDateFormat3.parse(str_time1);
Date date2 = simpleDateFormat3.parse(str_time2);
DateTime dt1 = new DateTime(date2);
DateTime dt2 = new DateTime(date1);
long hours = (Hours.hoursBetween(dt1, dt2).getHours() % 24);
long mins = (Minutes.minutesBetween(dt1, dt2).getMinutes() % 60);
long secs = (Seconds.secondsBetween(dt1, dt2).getSeconds() % 60);
String result = (hours+":"+mins+":"+secs);
//System.out.println(hours+":"+mins+":"+secs);
assertEquals(ExpectedResult, result);
}
It successfully runs and seems to be OKbut i am not sure that i am completing the unit testing exactly how i should.
Any observation about this is greatly appreciated