-
Notifications
You must be signed in to change notification settings - Fork 59
How to mock scala obejct #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It seems I forgot to mention it in the docs, you need to use the inline mock maker for this to work |
Sorry, I have checked the test package, I still don't quite understand what inline Mock Maker is, can you provide an example? thanks |
@QuietHR - I was able to get it to work once I added MockMaker plugin per the release notes on Mockito - Mock Maker |
Thank you very much. According to your method, the mock succeeded ~ |
Would you mind guys raising a PR to add those instructions on the README? I'm super busy these days but I can easily merge a PR :) |
Sure. It's my pleasure |
hi , I tried to mock Scala with 1.16.0, but the result was an error. This is my code. What's wrong with it? thanks
my pom
org.mockito
mockito-scala_2.11
1.16.0
my scala 2.11.8
my obejct
object FooObject {
def simpleMethod: String = "not mocked!"
}
object MockObject {
def main(args: Array[String]): Unit = {
withObjectMocked[FooObject.type] {
FooObject.simpleMethod returns "mocked!"
//or
//when(FooObject.simpleMethod) thenReturn "mocked!"
FooObject.simpleMethod == "mocked!"
}
FooObject.simpleMethod == "not mocked!"
}
}
error:
The text was updated successfully, but these errors were encountered: