<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國際加速解決方案。 廣告
                # 使用 Maven 執行 JUnit 測試用例 > 原文: [https://howtodoinjava.com/junit/executing-junit-testcases-with-maven/](https://howtodoinjava.com/junit/executing-junit-testcases-with-maven/) [**Maven**](//howtodoinjava.com/maven/ "Maven") 是用于項目依賴和構建管理的好工具。 它可以用于運行項目的 [**Junit**](//howtodoinjava.com/junit/ "JUnit") 測試用例。 在本文中,我將展示一些簡單但有用的命令示例,以各種方式運行測試用例。 為了演示,我使用以下命令創建了一個 [**maven java 項目**](//howtodoinjava.com/maven/create-a-simple-java-project-using-maven/ "Create a simple java project using?maven"): ```java mvn archetype:generate -DgroupId=com.howtodoinjava.junit -DartifactId=mavenJunitDemo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false ``` 然后,我在測試文件夾中創建了一個測試類,如下所示。 ```java package com.howtodoinjava.junit; import org.junit.Test; public class TestSurefire { @Test public void testcaseFirst() { System.out.println("First testcase executed"); } @Test public void testcaseSecond() { System.out.println("Second testcase executed"); } @Test public void testcaseThird() { System.out.println("Third testcase executed"); } @Test public void otherTestcase() { System.out.println("Another testcase executed"); } } ``` 讓我們檢查一下 maven 測試命令并查看其輸出: 1)使用命令“`mvn test`”運行所有測試用例:該命令將運行測試文件夾中存在的所有測試用例,而不考慮其他任何條件。 ```java ------------------------------------------------------- ?T E S T S ------------------------------------------------------- Running com.howtodoinjava.junit.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec Running com.howtodoinjava.junit.TestSurefire Another testcase executed First testcase executed Third testcase executed Second testcase executed Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.02 sec Results : Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 ``` 2)僅使用“`-Dtest=TestSurefire test`”執行特定的測試類:這將執行測試類`TestSurefire`中的所有測試用例。 ```java ------------------------------------------------------- ?T E S T S ------------------------------------------------------- Running com.howtodoinjava.junit.TestSurefire Another testcase executed First testcase executed Third testcase executed Second testcase executed Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 sec Results : Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 ``` 您可以在命令中使用多個測試類,甚至可以在測試類名稱中使用通配符來匹配一組測試類。 例如`mvn -Dtest=TestSurefire,TestOth*Class test`。 3)僅使用“`mvn -Dtest=TestSurefire#testcaseFirst test`”在測試類中測試某個測試用例:此命令將僅執行單個測試用例方法,即`testcaseFirst()`。 ```java ------------------------------------------------------- ?T E S T S ------------------------------------------------------- Running com.howtodoinjava.junit.TestSurefire First testcase executed Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.034 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 ``` 4)使用通配符映射測試多個測試用例,例如 “`mvn -Dtest=TestSurefire#testcase* test`”:這將有助于在一個簡單的短命令中運行多個具有相似名稱的測試用例。 ```java ------------------------------------------------------- ?T E S T S ------------------------------------------------------- Running com.howtodoinjava.junit.TestSurefire First testcase executed Second testcase executed Third testcase executed Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.034 sec Results : Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 ``` 給我留言不清楚,或者我缺少的東西。 **祝您學習愉快!**
                  <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>

                              哎呀哎呀视频在线观看