PowerMock in scala

I want to mock scala companion object, so I am trying to use PowerMockito. I have the following:

import org.junit.runner.RunWith
import org.mockito.Mockito.when
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import org.powermock.api.mockito.PowerMockito._

@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[ClassToMock]))
class Test {

describe("test") {
  it("test") {
    mockStatic(classOf[ClassToMock])
    when(ClassToMock.apply()).thenReturn(null)
  }
}

      

I get the following error when running the test:

The class path.to.ClassToMock 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: 

      

Any ideas on how I can manage to make the annotation?

thank!!

+3
scala mockito powermockito


source to share


No one has answered this question yet

Check out similar questions:

17
Calling calling methods using power mockito - org.powermock.api.mockito.ClassNotPreparedException
7
Parameterized Device Tests in Scala (with JUnit4)
3
Power Mockito returns org.powermock.api.mockito.ClassNotPreparedException error
2
PowerMock and Mockito not working for TestNG
2
How to mock an array of interfaces using powermock or mockito
2
PowerMock Mockito ignore junit FixMethodOrder
0
Does PowerMockito work without PowerMockRunner?
0
Mocking static methods and AEM Mocks
0
Can't disable static method call with PowerMockito
0
Powermockito: how to "release" a class annotated with @PrepareForTest?



All Articles
Loading...
X
Show
Funny
Dev
Pics