回答編集履歴
2
わかりにくいのでspy部分だけピックアップ
test
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
[doNothing](http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/Mockito.html#doNothing())ですかね。
|
2
2
|
|
3
3
|
|
4
|
+
|
5
|
+
```java
|
6
|
+
|
7
|
+
final MyClass mockObj = spy(MyClass.class);
|
8
|
+
|
9
|
+
doNothing().when(mockObj).exec();
|
10
|
+
|
11
|
+
```
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
全部記載するとこんな感じです:
|
4
16
|
|
5
17
|
```java
|
6
18
|
|
1
テストクラスを全部載せる
test
CHANGED
@@ -4,11 +4,53 @@
|
|
4
4
|
|
5
5
|
```java
|
6
6
|
|
7
|
-
public static class MyClass {
|
8
7
|
|
9
|
-
void exec() {
|
10
8
|
|
9
|
+
import static org.junit.Assert.*;
|
10
|
+
|
11
|
+
import static org.mockito.Matchers.*;
|
12
|
+
|
13
|
+
import static org.mockito.Mockito.*;
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
import org.junit.Test;
|
18
|
+
|
19
|
+
import org.junit.runner.RunWith;
|
20
|
+
|
21
|
+
import org.mockito.runners.MockitoJUnitRunner;
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
@RunWith(MockitoJUnitRunner.class)
|
26
|
+
|
27
|
+
public class MyTest {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public static class MyClass {
|
32
|
+
|
33
|
+
void exec() {
|
34
|
+
|
11
|
-
|
35
|
+
fail("called!");
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
@Test
|
44
|
+
|
45
|
+
public void test() {
|
46
|
+
|
47
|
+
final MyClass mockObj = spy(MyClass.class);
|
48
|
+
|
49
|
+
doNothing().when(mockObj).exec();
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
mockObj.exec();
|
12
54
|
|
13
55
|
}
|
14
56
|
|
@@ -16,18 +58,4 @@
|
|
16
58
|
|
17
59
|
|
18
60
|
|
19
|
-
@Test
|
20
|
-
|
21
|
-
public void test() {
|
22
|
-
|
23
|
-
final MyClass mockObj = spy(MyClass.class);
|
24
|
-
|
25
|
-
doNothing().when(mockObj).exec();
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
mockObj.exec();
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
61
|
```
|