• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion for Date

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...or, if you want to test for equality:
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic