簡體   English   中英

Junit:使用異常映射器測試拋出的異常

[英]Junit: testing thrown exception while using exception mapper

在使用異常映射器時,如何使用Junit4測試拋出的異常?

測試執行中期望的拋出異常。 請用 :

@Test(expected=<ExpectedException>.class)
public void testThrownException() {
// Your test code that throws the expected exception
}

如果您的代碼引發了預期的異常,並因斷言失敗和代碼引發的任何其他異常而失敗,則測試將通過。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM