1
逻辑PowerMockito:未完工磕碰检测(未完成的成株异常)
public class Logic {
String date = (LocalDateTime.now()).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
}
模拟代码
@RunWith(PowerMockRunner.class)
@PrepareForTest({ LocalDateTime.class })
public class LogicTest {
@InjectMocks
Logic target = new Logic();
PowerMockito.mockStatic(LocalDateTime.class);
when(LocalDateTime.now()).thenReturn(LocalDateTime.of(2017, 8, 24, 8, 50, 9));
}
当我试图写JUnit测试情况下,用于上述功能,异常“UnfinishedStubbingException”被显示。
我读了其他答案,但即使在那之后,我无法理解错误的原因。
您可以尝试将'LocalDateTime.of(2017,8,24,8,50,9)'的值存储在中间变量中,并将该变量作为'thenReturn'参数传递? – Berger
有没有方法'当(...' –
@Berger它的工作! 谢谢! –