Kotlin,Spring,Junit5,PowerMock和Mockito的模拟静态方法

问题描述

在课堂上,我有

@ExtendWith(SpringExtension::class)
@AutoConfiguremockmvc
@SpringBoottest
@PrepareForTest(LocalDateTime::class)

我的测试方法包含以下内容

@Test
fun `testMethod`() {
    powermockito.mockStatic(LocalDateTime::class.java)
    Mockito.`when`(LocalDateTime.Now()).thenReturn(LocalDateTime.of(2018,8,22,10,0));
 }

我的build.gradle.kts

testImplementation ( "org.mockito:mockito-core:3.5.9")
testImplementation("org.powermock:powermock-api-mockito2:2.0.7")
testImplementation("org.powermock:powermock-module-junit5:1.6.4")

错误

org.mockito.exceptions.misusing.MissingMethodInvocationException: when()需要一个参数,该参数必须是“模拟的方法调用”。 例如: when(mock.getArticles())。thenReturn(articles);

如何使用Kotlin,Junitt5,Spring Boot 2,Mockito和PowerMock模拟LocalDateTime.Now()

(我不想使用LocalDateTime.Now(clock)方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)