<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國際加速解決方案。 廣告
                # JUnit `JUnitCore`示例 > 原文: [https://howtodoinjava.com/junit/how-to-execute-junit-testcases-with-junitcore/](https://howtodoinjava.com/junit/how-to-execute-junit-testcases-with-junitcore/) 在任何以增量方式構建的應用中,通常希望只要引入新功能,我們就只能運行某些測試。 可以使用 JUnit 框架的`JUnitCore`類來實現。 [**`JUnitCore`**](http://junit.sourceforge.net/javadoc/org/junit/runner/JUnitCore.html "JUnitCore")是 JUnit 包中的內置類,它基于**外觀設計模式**。 `JUnitCore`類僅用于運行指定的測試類。 > 閱讀更多: [JUnit5 測試套件](https://howtodoinjava.com/junit5/junit5-test-suites-examples/) ## 1\. `JUnitCore`示例 假設在應用發行版中有兩個新功能。 這些功能通過兩個接口公開。 假設接口名稱為`FeatureOne`和`FeatureTwo`。 #### 1.1 要測試的功能 這兩個功能的 JUnit 測試可以如下: ```java package com.howtodoinjava.junit; import junit.framework.Assert; import org.junit.Test; public class TestFeatureOne { @Test public void testFirstFeature() { Assert.assertTrue(true); } } ``` ```java package com.howtodoinjava.junit; import junit.framework.Assert; import org.junit.Test; public class TestFeatureTwo { @Test public void testSecondFeature() { Assert.assertTrue(true); } } ``` #### 1.2 使用`JUnitCore`運行測試 要僅針對上述功能運行測試,我們可以編寫這樣的套件。 ```java package com.howtodoinjava.junit.suite; import java.util.ArrayList; import java.util.List; import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; import com.howtodoinjava.junit.TestFeatureOne; import com.howtodoinjava.junit.TestFeatureTwo; @SuppressWarnings("rawtypes") public class WithJUnitCore { public static void main(String[] args) { List testCases = new ArrayList(); //Add test cases testCases.add(TestFeatureOne.class); testCases.add(TestFeatureTwo.class); for (Class testCase : testCases) { runTestCase(testCase); } } private static void runTestCase(Class testCase) { Result result = JUnitCore.runClasses(testCase); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } } } ``` ## 2\. `JUnitCore`在命令提示符下運行測試 要從命令提示符手動運行測試類,我們可以從控制臺運行以下命令。 給出所有測試類的名稱,以空格分隔。 ```java $ java org.junit.runner.JUnitCore TestFeatureOne TestFeatureTwo ``` ## 3\. `JUnitCore`運行所有測試 強烈建議創建 [JUnit 套件](https://howtodoinjava.com/junit/how-to-execute-junit-testcases-in-test-suite/),并在所有測試用例中執行應用。 這將需要一些工作,但是仍然是在 JUnit 中執行所有測試的最佳方法。 ```java @RunWith(Suite.class) @SuiteClasses({ TestFeatureOne.class, TestFeatureTwo.class }) public class TestFeatureSuite { // } ``` 學習愉快! 參考: [`JUnitCore` Java 文檔](https://junit.org/junit4/javadoc/4.12/org/junit/runner/JUnitCore.html)
                  <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>

                              哎呀哎呀视频在线观看