teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

わかりにくいのでspy部分だけピックアップ

2015/12/17 06:25

投稿

退会済みユーザー
answer CHANGED
@@ -1,7 +1,13 @@
1
1
  [doNothing](http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/Mockito.html#doNothing())ですかね。
2
2
 
3
3
  ```java
4
+ final MyClass mockObj = spy(MyClass.class);
5
+ doNothing().when(mockObj).exec();
6
+ ```
4
7
 
8
+ 全部記載するとこんな感じです:
9
+ ```java
10
+
5
11
  import static org.junit.Assert.*;
6
12
  import static org.mockito.Matchers.*;
7
13
  import static org.mockito.Mockito.*;

1

テストクラスを全部載せる

2015/12/17 06:25

投稿

退会済みユーザー
answer CHANGED
@@ -1,17 +1,31 @@
1
1
  [doNothing](http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/Mockito.html#doNothing())ですかね。
2
2
 
3
3
  ```java
4
+
5
+ import static org.junit.Assert.*;
6
+ import static org.mockito.Matchers.*;
7
+ import static org.mockito.Mockito.*;
8
+
9
+ import org.junit.Test;
10
+ import org.junit.runner.RunWith;
11
+ import org.mockito.runners.MockitoJUnitRunner;
12
+
13
+ @RunWith(MockitoJUnitRunner.class)
14
+ public class MyTest {
15
+
4
- public static class MyClass {
16
+ public static class MyClass {
5
- void exec() {
17
+ void exec() {
6
- System.out.println("hello");
18
+ fail("called!");
19
+ }
7
20
  }
8
- }
9
21
 
10
- @Test
22
+ @Test
11
- public void test() {
23
+ public void test() {
12
- final MyClass mockObj = spy(MyClass.class);
24
+ final MyClass mockObj = spy(MyClass.class);
13
- doNothing().when(mockObj).exec();
25
+ doNothing().when(mockObj).exec();
14
26
 
15
- mockObj.exec();
27
+ mockObj.exec();
28
+ }
16
29
  }
30
+
17
31
  ```