MockKRule

class MockKRule(testSubject: Any) : TestWatcher, TestRule

A simple JUnit 4 rule which handles the setting up and tearing down of mock objects using the MockK or RelaxedMockK annotations at the beginning and end of each test respectively - without needing to manually call unmockkAll or MockKAnnotations.init.

Example:

class ExampleTest {
@get:Rule
val mockkRule = MockKRule(this)

@MockK
private lateinit var car: Car

@Test
fun something() {
every { car.drive() } just runs
...
}
}

Constructors

Link copied to clipboard
fun MockKRule(testSubject: Any)

Functions

Link copied to clipboard
open override fun apply(p0: Statement, p1: Description): Statement