テスト対象クラス
java
1@Repository 2public class Dao { 3 4 @Autowired 5 JdbcTemplate jdbc; 6 7 public void update() { 8 // jdbcのexecuteを呼び、例外をtry-catchする 9 } 10 11}
テストクラス
java
1public class DaoTest { 2 3 @Autowired 4 Dao target; 5 6 @SpyBean 7 JdbcTemplate jdbc; 8 9 @Before 10 public void setUp() { 11 MockitoAnnotations.initMocks(this); 12 } 13 14 @Test(expected = RuntimeException.class) 15 public void tset_exception() { 16 Mockito.doThrow(new RuntimeException()).when(jdbc).execute(anyString(), any()); 17 target.update(); 18 } 19}
例外
org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: -> at ***.DaoTest.test_exception(DaoTest.java:***) E.g. thenReturn() may be missing. Examples of correct stubbing: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(exception).when(mock).someVoidMethod(); Hints: 1. missing thenReturn() 2. you are trying to stub a final method, which is not supported
tset_exceptionを単体で実行した場合は問題ないのですが、テストクラス全体を実行すると
tset_exceptionの直後のテストメソッドでだけこの例外発生します。
ネットをくまなく調べたのですが解決方法がわかりませんでした。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。