12

I have the following test...

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]);
      ...
  }
}

But when I run I get...

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.

Which doesn't make sense given the annotation is already there? Is it an idiosyncrasy of Scala test?

Jackie
  • 21,969
  • 32
  • 147
  • 289

1 Answers1

-2

I had the same problem using FunSuite. It works when I turned to 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 {
}

etc...

Vadim
  • 1,336
  • 2
  • 10
  • 10