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
Added a JUnit 4 rule #816
Added a JUnit 4 rule #816
Conversation
This is pretty cool, thanks a lot for submitting it! Would you mind also updating the docs here to mention that this can be done with JUnit 4 as well? Thanks again! |
Added a bit next to the JUnit5 section 😃 |
Beautiful, thanks a lot! ...I guess now the only thing left to do is figuring out why the tests are failing :) |
I've been digging a bit into this, and looks like parameter injection is not easy to achieve with JUnit 4. Would you be ok removing |
Agree, hopefully that should sort it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the build to pass on my machine, but I can't push on your branch :)
import io.mockk.impl.annotations.SpyK | ||
import io.mockk.verify | ||
import org.junit.Rule | ||
import org.junit.jupiter.api.Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be org.junit.Test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed!
import kotlin.test.assertEquals | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertTrue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need RunWith(JUnit4::class)
here for the tests to pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Thanks a lot for following up on this! |
I find myself using something like this in most of my personal projects, it saves a lot (okay not that much) boilerplate of calling
MockKAnnotations.init(this)
andunmockkAll()
in every JUnit 4 test case.I essentially copypasted the test case from the equivalent for
MockKExtension
, let me know if that's not okay.