Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nillerr/mockk-junit


https://github.com/nillerr/mockk-junit

Last synced: 5 days ago
JSON representation

Awesome Lists containing this project

README

        

# MockK for JUnit 5

Provides the `@MockKTest` annotation for running `checkUnnecessaryStub()` on all [MockK](https://mockk.io/) mock
instances stored in the member properties of the test class the annotation is present on.

## Installation

```kotlin
dependencies {
implementation("io.github.nillerr:mockk-junit5:1.0.1")
}
```

## Usage

Annotate a test class with the `@MockKTest` annotation:

```kotlin
@MockKTest
class UserServiceTests {
// Mocks
private val repository: UserRepository = mockk()

// SUT
private val service = UserService(repository)

@Test
fun test() {
// Given
val id = "5"
val account = AccountRecords.default
every { repository.find(id) }.returnsMany(account)

// When
val result = service.get(id)

// Then
assertEquals(result).isEqualTo(Accounts.default)
}
}
```

JUnit will now call `checkUnnecessaryStub()` on the `UserRepository` after every test.