0
0

UT Mockito when使い方

Last updated at Posted at 2024-06-01

whenとは

スタブを実現させる際に使用します。メソッドが呼ばれた際に特定の値を返すように操作することができます。
ex)

when(mock.someMethod()).thenReturn(10);

また、whenは同じメソッドが2回使用される場合や例外処理のUTで有効です。
ex)

when(mock.someMethod()).thenReturn(10).thenReturn(0);
when(mock.someMethod()).thenThrow(new RuntimeException());

参考

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