MockK Patterns for JUnit 4
Artifacts are hosted on the Maven Central repository.
repositories {
mavenCentral()
}
dependencies {
testImplementation("com.github.erikhuizinga:mockk-junit4:$LATEST_VERSION")
}
Extend this class to automatically apply MockkTestClassRule
and MockkTestRule
.
These rules clear all MockK mocks after every unit test and unmock all MockK mocks after the test class.
Class rule to unmock all MockK mocks so that they don't leak between unit test classes.
Rule to clear all MockK mocks so that their state doesn't leak between unit test functions.
Take a look at ExampleTestSuite for an example to use MockkTest
with an extensive description of the involved MockK and JUnit 4 mechanics.