ユーザ用ツール

サイト用ツール


mockito

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
mockito [2015/10/21 13:20]
sou [サンプル]
mockito [2015/10/21 17:10] (現在)
sou [メモ]
ライン 18: ライン 18:
   ...   ...
   ​   ​
-  ​/** +    ​/** 
-   ​* モックが相互作用することを検証 +     ​* モックが相互作用することを検証 
-   ​* @throws Exception +     ​* @throws Exception 
-   ​*/ +     ​*/ 
-  @Test +    @Test 
-  public void testVerify() throws Exception { +    public void testVerify() throws Exception { 
-    List mockedList = mock(List.class);​ +        List mockedList = mock(List.class);​ 
-    mockedList.add("​one"​);​ +        mockedList.add("​one"​);​ 
-    mockedList.clear();​ +        mockedList.clear();​
-     +
-    // mockのメソッドが呼びだされていることを確認する +
-    verify(mockedList).add("​one"​);​ +
-    verify(mockedList).clear();​ +
-  }+
   ​   ​
-  ​/** +        // mockのメソッドが呼びだされていることを確認する 
-   ​* スタブとして利用 +        verify(mockedList).add("​one"​);​ 
-   ​* @throws Exception +        verify(mockedList).clear();​ 
-   ​*/ +    } 
-  @Test +   
-  public void testStub() throws Exception { +    ​/** 
-    List mockedList = mock(List.class);​ +     ​* スタブとして利用 
-    // スタブとして「first」を返すよう設定 +     ​* @throws Exception 
-    when(mockedList.get(0)).thenReturn("​first"​);​ +     ​*/ 
-       +    @Test 
-    // JUnitで検証 +    public void testStub() throws Exception { 
-    String str = mockedList.get(0).toString();​ +        List mockedList = mock(List.class);​ 
-    assertEquals("​first",​ str); +         
-  }+        ​// スタブとして「first」を返すよう設定 
 +        when(mockedList.get(0)).thenReturn("​first"​);​ 
 +   
 +        // JUnitで検証 
 +        String str = mockedList.get(0).toString();​ 
 +        assertEquals("​first",​ str); 
 +    } 
 +     
 + 
 +===== 参考URL ===== 
 +Mockito API\\ 
 +http://​site.mockito.org/​mockito/​docs/​current/​org/​mockito/​Mockito.html
mockito.1445401227.txt.gz · 最終更新: 2015/10/21 13:20 by sou