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

Jac*_*kie 8 scala powermock scalatest powermockito

我有以下测试......

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]);
      ...
  }
}
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时,我得到......

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.
Run Code Online (Sandbox Code Playgroud)

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

Vad*_*dim -2

我在使用 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 {
}
Run Code Online (Sandbox Code Playgroud)

ETC...