作为对此的进一步问题:Fake system clock on certain date
是否可以在 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...
这有帮助吗?
关于java - 确定 Maven 配置文件上的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15223329/