作为进一步的问题:在某个日期伪造系统时钟
有可能在Maven配置文件上设置特定的日期吗?毕竟,我使用的测试概要文件决定了测试数据库的使用。
在您的Maven配置文件中,您可以通过Surefire传入一个日期时间作为系统属性:
...
<profile>
...
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<testDateTime>2013-01-01T00:00:00.000Z</testDateTime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
...
然后在测试中使用它,像这样:
final String dateTime = System.getProperty("testDateTime");
// parse date-time etc...
有帮助吗?