<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Junit 預期異常測試用例示例 > 原文: [https://howtodoinjava.com/junit/junit-testcases-which-expects-exception-on-runtime/](https://howtodoinjava.com/junit/junit-testcases-which-expects-exception-on-runtime/) [**Junit**](//howtodoinjava.com/junit/ "junit tutorials") 是 Java 編程語言的單元測試框架。 如果您想閱讀有關[**最佳實踐**](//howtodoinjava.com/category/best-practices/ "best practices guides")的信息,以進行 junit 測試,那么這里是一份出色的[**指南**](//howtodoinjava.com/best-practices/unit-testing-best-practices-junit-reference-guide/ "Unit testing best practices : Junit Reference?guide")供您參考。 在本文中,我正在編寫一個示例測試用例,期望在運行時引發異常。 如果它獲得預期的異常,則測試通過。 如果未檢測到預期的異常,則測試用例失敗。 如果您希望應用因非常荒謬的輸入而失敗,這些類型的測試用例將非常有用。 ```java package com.howtodoinjava.test.junit; import org.junit.Test; public class ExpectedExceptionTest { //This test case fails because it was expecting ArithmeticException @Test(expected = ArithmeticException.class) public void expectArithmeticException() { System.out.println("Everything was fine here !!"); } //This test case fails because it was expecting ArithmeticException @Test(expected = ArithmeticException.class) public void expectArithmeticException2() { throw new NullPointerException(); } //This test case passes because it was expecting NullPointerException @Test(expected = NullPointerException.class) public void expectNullPointerException() { //some code which throw NullPointerException in run time throw new NullPointerException(); } } ``` 在上述 3 個測試用例中,前兩個失敗是因為他們期望`ArithmeticException`,而在執行測試用例時并沒有得到。 第三個測試用例獲得通過,因為它期望`NullPointerException`并被測試用例拋出。 這樣,您可以編寫依賴于某些異常的測試用例,以測試失敗時應用的行為。 **祝您學習愉快!**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看