当我运行测试时:
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyStuff.class)
public class MyStuffTest { ..whatever
将 ZonedDateTime
类添加到该代码后,它开始失败并出现以下错误:
java.lang.IllegalStateException: Failed to transform class with name MyCode Reason: [source error] toInstant() not found in java.time.ZonedDateTime
在我的代码中的某个地方:
long longTimeNoSee = ZonedDateTime.parse(getateTimeString()).toInstant().toEpochMilli();
我猜这是powermock
中的一个错误。但也许有人有一些想法(?)
最佳答案
这似乎确实是 Powermock 中的一个错误。参见
https://github.com/jayway/powermock/issues/557
您可能想要添加示例并为此问题投票。
更新:根据 Powermock 的说法,这似乎是 javassist 中的一个问题:https://github.com/jboss-javassist/javassist/issues/43
关于datetime - 未找到 PowerMockito 和 Java 8 ZonedDateTime toInstant(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25272839/