<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://javatutorial.net/how-to-run-junit-test-with-maven](https://javatutorial.net/how-to-run-junit-test-with-maven) 本教程將介紹如何使用 [Maven](https://javatutorial.net/how-to-install-maven-on-windows-linux-and-mac) 的 Surefire 插件運行單元測試。 如果您不熟悉單元測試,則可以按照本教程[快速了解](https://javatutorial.net/how-to-use-junit-for-unit-testing)。 ![java-featured-image](https://img.kancloud.cn/05/3e/053ee0bb59842d92359246c98f815e0c_780x330.jpg) 在我們的 Maven 項目中,我們需要以下強制性依賴項: ```java <dependencies>???? <dependency>???????? <groupId>org.junit.jupiter</groupId>???????? <artifactId>junit-jupiter-api</artifactId>???????? <version>5.4.2</version>???????? <scope>test</scope>???? </dependency>???? <dependency>??????? <groupId>org.junit.jupiter</groupId>???????? <artifactId>junit-jupiter-engine</artifactId>???????? <version>5.4.2</version>???????? <scope>test</scope>???? </dependency> </dependencies> ``` `junit-jupiter-engine`依賴項包含運行我們的單元測試的 JUnit Jupiter 測試引擎的實現。 `junit-jupiter-api`依賴項提供了 API,使我們能夠編寫使用 JUnit 5 的測試和擴展。 因此,讓我們創建一個非常簡單的 Java 文件: ```java import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class Example1 {??????????? public static int getNumber() {??????????????????????? return 5;??????????? } ???public static String getMeaningfulText() {??????????????????????? return "Hello World";??????????? } } ``` 現在,為它創建一個 Test 類: ```java import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class TestExample1 {??? @Test??? ??????? public void testNumber() {??????? ???????????????? assertEquals(5, Example1.getNumber());??????????? } @Test??? ??????? public void testMeaningfulText () {??????? ???????????????? assertEquals(“Hello World”, Exampe1.getMeaningfulText ());??????????? }??? } ``` **最后,我們可以使用`mvn clean build`運行程序,并且應該看到 Superfire 插件正在運行我們的單元測試** ```java [INFO] [INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ running-unit-tests --- [INFO]-------------------------------------------------------?T E S T S-------------------------------------------------------Running net.javatutorial.junit5.JUnit5Example1Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.039 sec -in net.javatutorial.junit5.JUnit5Example1Results :Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------[ INFO] BUILD SUCCESS[ INFO] ------------------------------------------------------------------------ ```
                  <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>

                              哎呀哎呀视频在线观看