gpt4 book ai didi

scala - PowerMockito 即使使用 Scala Test 使用 @PrepareForTest 也会抛出 ClassNotPreparedException

转载 作者:行者123 更新时间:2023-12-04 04:42:20 27 4
gpt4 key购买 nike

我有以下测试...

import org.scalatest.junit.JUnitRunner
...
@PowerMockRunnerDelegate(classOf[JUnitRunner])
@PrepareForTest(Array(classOf[AuditLog]))
class ConnectorAPITest extends path.FreeSpec with ShouldMatchers {
"Mocked Tests" - {
println("This got called in the mocked tests.")
PowerMockito.mockStatic(classOf[AuditLog]);
...
}
}

但是当我运行时,我得到...
An exception or error caused a run to abort: The class com.paxata.services.log.AuditLog not prepared for test.
To prepare this class, add class to the '@PrepareForTest' annotation.
In case if you don't use this annotation, add the annotation on class or method level.
org.powermock.api.mockito.ClassNotPreparedException:
The class com.paxata.services.log.AuditLog not prepared for test.
To prepare this class, add class to the '@PrepareForTest' annotation.

鉴于注释已经存在,哪个没有意义?它是 Scala 测试的特质吗?

最佳答案

我在使用 FunSuite 时遇到了同样的问题。当我转向 JUnit 时它起作用了。

@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[SomeStaticClass]))
class MyTestClass {

@Before
def setUp {
PowerMockito.mockStatic(classOf[SomeStaticClass])
Mockito.when(SomeStaticClass.getSomeObject(1)).thenReturn(new SomeObject(1))
}

@Test
def someTestMethod {
}

等等...

关于scala - PowerMockito 即使使用 Scala Test 使用 @PrepareForTest 也会抛出 ClassNotPreparedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39799660/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com