0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JUnit で引数をチェックするテストを書くには

Posted at

Mockito の ArgumentCaptor を利用する。

例えば、呼び出したメソッド内で与えた初期値が引数としてわたっているかをチェックするため。

import static org.mockito.Mockito.verify;
import org.mockito.ArgumentCaptor;

省略

    // キャプチャする引数を用意
    ArgumentCaptor<Long> idCaptor = ArgumentCaptor.forClass(Long.class);

    // テスト対象を呼び出し
    service.getReview(null);

    // キャプチャ
    verify(mapper).findById(idCaptor.capture());

    // 評価
    assertEquals(0L, idCaptor.getValue().longValue());

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?