You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercise-5.md
+28-5Lines changed: 28 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,29 @@ In the `src/main/test` folder the file BootiqueControllerTest should be availabl
10
10
11
11
We are going to be using a mocking framework to mock out our dependencies. Spring test conveniently bundles Mockito so let's use that. First thing to do now, is to define the MockitoRunner as the testrunner for your unit test. Add it now.
12
12
13
-
In java you would do something like the listing below.
13
+
In java you would do something like the listing below.
14
+
15
+
For JUnit 4
14
16
15
17
```java
18
+
importorg.junit.Test
19
+
importorg.junit.runner.RunWith
20
+
importorg.mockito.junit.MockitoJUnitRunner
21
+
16
22
@RunWith(MockitoJUnitRunner.class)
17
23
```
18
24
19
-
**Exercise**: Convert the test to Kotlin and add the MockitoJUnitRunner to it.
25
+
For JUnit 5
26
+
27
+
```java
28
+
importorg.junit.jupiter.api.Test
29
+
importorg.junit.jupiter.api.extension.ExtendWith
30
+
importorg.mockito.junit.jupiter.MockitoExtension
31
+
32
+
@ExtendWith(MockitoExtension::class)
33
+
```
34
+
35
+
**Exercise**: Convert the test to Kotlin and add Mockito to it.
20
36
21
37
<details>
22
38
<summary>Suggested solution</summary>
@@ -92,12 +108,9 @@ public void testRetrieveBasket() {
92
108
93
109
```
94
110
import org.assertj.core.api.Assertions.assertThat
95
-
import org.junit.Test
96
-
import org.junit.runner.RunWith
97
111
import org.mockito.InjectMocks
98
112
import org.mockito.Mock
99
113
import org.mockito.Mockito.*
100
-
import org.mockito.junit.MockitoJUnitRunner
101
114
```
102
115
103
116
<details>
@@ -177,7 +190,17 @@ We are going to test the app by calling an endpoint, so we'll be modifying the t
177
190
178
191
First, we'll need to configure the web environment to test against. Modify the `@SpringBootTest` annotation like below.
0 commit comments