Skip to content

Commit

Permalink
corrected incongruent code in "Object mock"
Browse files Browse the repository at this point in the history
  • Loading branch information
polarene committed Mar 7, 2023
1 parent 0fa0b26 commit c152f73
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ every { ObjBeingMocked.add(1, 2) } returns 55
assertEquals(55, ObjBeingMocked.add(1, 2))
```

To revert back, use `unmockkAll` or `unmockkObject`:
To revert back, use `unmockkObject` or `unmockkAll` (more destructive: cancels object, static and constructor mocks)

```kotlin
@Before
fun beforeTests() {
mockkObject(ObjBeingMocked)
every { MockObj.add(1,2) } returns 55
every { ObjBeingMocked.add(1,2) } returns 55
}

@Test
Expand All @@ -397,14 +397,14 @@ fun willUseMockBehaviour() {

@After
fun afterTests() {
unmockkAll()
// or unmockkObject(ObjBeingMocked)
unmockkObject(ObjBeingMocked)
// or unmockkAll()
}
```

Despite the Kotlin language restrictions, you can create new instances of objects if required by testing logic:
```kotlin
val newObjectMock = mockk<MockObj>()
val newObjectMock = mockk<ObjBeingMocked>()
```

### Class mock
Expand Down

0 comments on commit c152f73

Please sign in to comment.