I have a unit test that checks to make sure an object inside my instance is created with a proper Date populated:
Date earlier = new Date();
Thread.sleep(10);
instance.execute();
assertTrue(instance.getMyObject.getCreationDate().after(earlier));
This test works for me on Windows 7 Java 6 when running in Eclipse or with Ant from the command line.
However, my client says that this test is failing for him (he didn’t specify his environment). How could this be?
On Windows XP, the clock resolution is only 1/60 of a second. This means that you can wait 10 ms and the clock time will appear the same. I would increase the time to 100 to 250 ms.