• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertion for Date

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am writing test cases and i wish to compare the date in the database

to what i entered in the DTO of the object...It is givind me errors..

I wish to comapre two dates...

Is there an assertionEquals or assertionTrue method or any other method..

that wud allow me..to do it. with the dates as arguments?

Thx in advance,
A Kumar.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Date implements the equals method, assertEquals(Object, Object) should work fine...
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I will try to work out this way..and get back to u...

But is it ok..if I compare the two dates...

int val= Date1.compareToDate(Date2)

assertEquals(1,val );

Thx
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by A Kumar:
But is it ok..if I compare the two dates...

int val= Date1.compareToDate(Date2)

assertEquals(1,val );

I would rather do something like this:
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...or, if you want to test for equality:
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other thing to watch with dates is the precision. ALl of the methods post about (that check for equality) require the dates to be the same to the millisecond. If you want to check just the date part or the time part, you can write a custom assertion. For example,



I favor assertEquals(date1, date2);
over assertTrue(date1.equals(date2));
because it gives clearer output on an assertion failure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic