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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # JUnit5 `@Tag`注解示例 > 原文: [https://howtodoinjava.com/junit5/junit-5-tag-annotation-example/](https://howtodoinjava.com/junit5/junit-5-tag-annotation-example/) JUnit5 [`@Tag`](http://junit.org/junit5/docs/current/api/org/junit/jupiter/api/Tag.html) 可用于從測試計劃中過濾測試用例。 它可以幫助針對不同的環境,不同的用例或任何特定要求創建多個不同的測試計劃。 您可以通過僅在測試計劃中包括那些標記的測試或通過從測試計劃中排除其他測試來執行測試集。 ## 1\. `@Tag`注解用法 1. 我們可以將其**應用于測試類或測試方法或同時應用**。 ```java @Tag("development") public class ClassATest { @Test @Tag("userManagement") void testCaseA(TestInfo testInfo) { } } ``` 2. 我們也可以將**多個標簽應用于單個測試**案例,以便您可以將其包含在多個測試計劃中。 ```java public class ClassATest { @Test @Tag("development") @Tag("production") void testCaseA(TestInfo testInfo) { } } ``` ## 2\. 使用`@IncludeTags`和`@ExcludeTags`創建測試計劃 我們可以在測試計劃中使用[`@IncludeTags`](http://junit.org/junit5/docs/current/api/index.html?org/junit/platform/runner/IncludeTags.html)或[`@ExcludeTags`](http://junit.org/junit5/docs/current/api/index.html?org/junit/platform/runner/ExcludeTags.html)注解來過濾測試或包括測試。 ```java //@IncludeTags example @RunWith(JUnitPlatform.class) @SelectPackages("com.howtodoinjava.junit5.examples") @IncludeTags("production") public class MultipleTagsExample { } //@ExcludeTags example @RunWith(JUnitPlatform.class) @SelectPackages("com.howtodoinjava.junit5.examples") @ExcludeTags("production") public class MultipleTagsExample { } ``` 要添加多個標簽,請在所需注解中傳遞標簽的*字符串數組*。 ```java @RunWith(JUnitPlatform.class) @SelectPackages("com.howtodoinjava.junit5.examples") @IncludeTags({"production","development"}) public class MultipleTagsExample { } ``` 我們不能在單個測試計劃中同時包含`@IncludeTags`和`@ExcludeTags 注`解。 ## 3\. JUnit5 `@Tag`示例 假設我們有 3 個測試,并且我們想在開發環境中運行全部 3 個測試; 但只想在生產中運行一個。 因此,我們將標記測試如下: ```java public class ClassATest { @Test @Tag("development") @Tag("production") void testCaseA(TestInfo testInfo) { //run in all environments } } public class ClassBTest { @Test @Tag("development") void testCaseB(TestInfo testInfo) { } } public class ClassCTest { @Test @Tag("development") void testCaseC(TestInfo testInfo) { } } ``` 讓我們為兩種環境創建測試計劃。 #### 在生產環境中運行測試 ```java @RunWith(JUnitPlatform.class) @SelectPackages("com.howtodoinjava.junit5.examples") @IncludeTags("production") public class ProductionTests { } ``` ![JUnit5 @Tag Example - Production Tests](https://img.kancloud.cn/0e/d3/0ed354f82ba6490e5e0b346ec73854e9_535x187.png) JUnit5 `@Tag`示例 – 生產測試 #### 在開發環境中運行測試 ```java @RunWith(JUnitPlatform.class) @SelectPackages("com.howtodoinjava.junit5.examples") @IncludeTags("development") public class DevelopmentTests { } ``` ![JUnit5 @Tag Example - Development Tests](https://img.kancloud.cn/6b/57/6b57cc973f86ab6931799079720e3f2b_544x229.png) JUnit5 `@Tag`示例 – 開發測試 將我的問題放在評論部分。 學習愉快! [源碼下載](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>

                              哎呀哎呀视频在线观看