-
-
Save corningsun/a9a0527edc2f5dc5f3659424d1b8a224 to your computer and use it in GitHub Desktop.
java.util.Date.getTime() testNG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.corning.demo.util; | |
import org.testng.annotations.BeforeMethod; | |
import org.testng.annotations.Test; | |
import java.util.Date; | |
import static org.testng.Assert.assertEquals; | |
public class DateGetTimeTest { | |
private Date date; | |
private long time; | |
@BeforeMethod | |
public void setUp() { | |
date = new Date(); | |
time = date.getTime(); | |
} | |
@Test(threadPoolSize = 1, invocationCount = 10000) | |
public void testDateGetTime() { | |
assertEquals(time, date.getTime()); | |
} | |
// threadPoolSize = 1 all passed | |
@Test(threadPoolSize = 20, invocationCount = 10000) | |
public void testDateGetTime2() { | |
assertEquals(time, date.getTime()); | |
} | |
// threadPoolSize = 20 有概率会失败,结果相差几毫秒 | |
// java.lang.AssertionError: expected [1615537139497] but found [1615537139498] | |
// Expected :1615537139497 | |
// Actual :1615537139498 | |
} | |
// JDK 1.8 | |
java version "1.8.0_161" | |
Java(TM) SE Runtime Environment (build 1.8.0_161-b12) | |
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode) | |
// mvn dependency | |
<dependency> | |
<groupId>org.testng</groupId> | |
<artifactId>testng</artifactId> | |
<version>6.10</version> | |
<scope>test</scope> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment