即使使用Scala Test使用@PrepareForTest,PowerMockito也会抛出Cl
发布时间:2020-12-16 08:52:33 所属栏目:安全 来源:网络整理
导读:我有以下测试…… import org.scalatest.junit.JUnitRunner...@PowerMockRunnerDelegate(classOf[JUnitRunner])@PrepareForTest(Array(classOf[AuditLog]))class ConnectorAPITest extends path.FreeSpec with ShouldMatchers { "Mocked Tests" - { println(
|
我有以下测试……
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 {
}
等等… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
