将日期与 JUnit 测试进行比较
您好,我是该网站的新手,使用JUnit测试的应用程序有问题。我的问题是,当我尝试将Date方法与自身进行比较时,它总是失败。我在测试中打印了 Date 对象以查看问题,并且始终以包名称和随机字母结束。下面是 Date 构造函数:
public class Date
{
SimpleDateFormat dformat = new SimpleDateFormat("dd-MM-yyyy");
private int day;
private int month;
private int year;
public Date()
{
String today;
Calendar present = Calendar.getInstance();
day = present.get(Calendar.DAY_OF_MONTH);
month = present.get(Calendar.MONTH);
year = present.get(Calendar.YEAR);
present.setLenient(false);
present.set(year, month - 1, day, 0, 0);
today = dformat.format(present.getTime());
System.out.println(today);
}
这是我的测试:
@Test
public void currentDay()
{
Date current = new Date();
System.out.println(current);
assertEquals("today:", current, new Date());
}
然而,结果总是失败,我得到了一些东西:
comp.work.wk.Date@d3ade7
任何帮助将不胜感激。