<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # JUnit5 `@Disabled`測試示例 > 原文: [https://howtodoinjava.com/junit5/junit-5-disabled-test-example/](https://howtodoinjava.com/junit5/junit-5-disabled-test-example/) JUnit [`@Disabled`](http://junit.org/junit5/docs/current/api/org/junit/jupiter/api/Disabled.html)注解可用于禁用測試套件中的測試方法。 該注解可以應用于測試類以及各個測試方法。 它僅接受**一個可選參數**,它指示此測試被禁用的原因。 ## `@Disabled`的測試類 將`@Disabled`應用于測試類時,**該類中的所有測試方法也會自動禁用**。 ```java import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @Disabled public class AppTest { @Test void testOnDev() { System.setProperty("ENV", "DEV"); Assumptions.assumeFalse("DEV".equals(System.getProperty("ENV"))); } @Test void testOnProd() { System.setProperty("ENV", "PROD"); Assumptions.assumeFalse("DEV".equals(System.getProperty("ENV"))); } } ``` ![JUnit5 Disabled Annotation Over Class](https://img.kancloud.cn/8e/5f/8e5f670ccb4a9d84cf1f6984e9993b00_654x182.png) JUnit5 類上的`@Disabled`注解 請注意運行次數:2/2(跳過 2 個)。 顯然,兩個測試都被禁用,因此不執行。 ## JUnit5 `@Disabled`測試方法 `@Disabled`用于表示當前已禁用帶注解的**測試方法,因此不應執行**。 ```java import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class AppTest { @Disabled("Do not run in lower environment") @Test void testOnDev() { System.setProperty("ENV", "DEV"); Assumptions.assumeFalse("DEV".equals(System.getProperty("ENV"))); } @Test void testOnProd() { System.setProperty("ENV", "PROD"); Assumptions.assumeFalse("DEV".equals(System.getProperty("ENV"))); } } ``` ![JUnit5 Disabled Annotation Over Method](https://img.kancloud.cn/26/9e/269e2e1b32a930e167ac8db3bf655ac5_711x174.png) JUnit5 方法上的`@Disabled`注解 將我的問題放在評論部分。 學習愉快! [源碼下載](https://github.com/lokeshgupta1981/Junit5Examples/tree/master/JUnit5Examples)
                  <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>

                              哎呀哎呀视频在线观看