久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='No4So'></bdo><ul id='No4So'></ul>

      <small id='No4So'></small><noframes id='No4So'>

      <tfoot id='No4So'></tfoot>

      1. <i id='No4So'><tr id='No4So'><dt id='No4So'><q id='No4So'><span id='No4So'><b id='No4So'><form id='No4So'><ins id='No4So'></ins><ul id='No4So'></ul><sub id='No4So'></sub></form><legend id='No4So'></legend><bdo id='No4So'><pre id='No4So'><center id='No4So'></center></pre></bdo></b><th id='No4So'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='No4So'><tfoot id='No4So'></tfoot><dl id='No4So'><fieldset id='No4So'></fieldset></dl></div>

        <legend id='No4So'><style id='No4So'><dir id='No4So'><q id='No4So'></q></dir></style></legend>

        JUnit 混淆:使用“擴展 TestCase"或“@Test"?

        JUnit confusion: use #39;extends TestCase#39; or #39;@Test#39;?(JUnit 混淆:使用“擴展 TestCase或“@Test?)
          <tfoot id='nvfa1'></tfoot>
            <legend id='nvfa1'><style id='nvfa1'><dir id='nvfa1'><q id='nvfa1'></q></dir></style></legend>

              <small id='nvfa1'></small><noframes id='nvfa1'>

                <bdo id='nvfa1'></bdo><ul id='nvfa1'></ul>
                  <tbody id='nvfa1'></tbody>

                <i id='nvfa1'><tr id='nvfa1'><dt id='nvfa1'><q id='nvfa1'><span id='nvfa1'><b id='nvfa1'><form id='nvfa1'><ins id='nvfa1'></ins><ul id='nvfa1'></ul><sub id='nvfa1'></sub></form><legend id='nvfa1'></legend><bdo id='nvfa1'><pre id='nvfa1'><center id='nvfa1'></center></pre></bdo></b><th id='nvfa1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nvfa1'><tfoot id='nvfa1'></tfoot><dl id='nvfa1'><fieldset id='nvfa1'></fieldset></dl></div>
                • 本文介紹了JUnit 混淆:使用“擴展 TestCase"或“@Test"?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我發現 JUnit 的正確使用(或至少是文檔)非常令人困惑.這個問題既可以作為未來的參考,也可以作為一個真實的問題.

                  I've found the proper use (or at least the documentation) of JUnit very confusing. This question serves both as a future reference and as a real question.

                  如果我理解正確的話,創建和運行 JUnit 測試有兩種主要方法:

                  If I've understood correctly, there are two main approaches to create and run a JUnit test:

                  方法 A(JUnit 3 風格):創建一個擴展 TestCase 的類,并使用單詞 test 開始測試方法.當將該類作為 JUnit 測試運行時(在 Eclipse 中),所有以單詞 test 開頭的方法都會自動運行.

                  Approach A (JUnit 3-style): create a class that extends TestCase, and start test methods with the word test. When running the class as a JUnit Test (in Eclipse), all methods starting with the word test are automatically run.

                  import junit.framework.TestCase;
                  
                  public class DummyTestA extends TestCase {
                  
                      public void testSum() {
                          int a = 5;
                          int b = 10;
                          int result = a + b;
                          assertEquals(15, result);
                      }
                  }
                  

                  方法 B(JUnit 4 風格): 創建一個普通"類并在方法前添加 @Test 注釋.請注意,您不必以單詞 test 開始方法.

                  Approach B (JUnit 4-style): create a 'normal' class and prepend a @Test annotation to the method. Note that you do NOT have to start the method with the word test.

                  import org.junit.*;
                  import static org.junit.Assert.*;
                  
                  public class DummyTestB {
                  
                      @Test
                      public void Sum() {
                          int a = 5;
                          int b = 10;
                          int result = a + b;
                          assertEquals(15, result);
                      }
                  }
                  

                  將兩者混合似乎不是一個好主意,請參見例如這個stackoverflow問題:

                  Mixing the two seems not to be a good idea, see e.g. this stackoverflow question:

                  現在,我的問題:

                  1. 首選方法是什么,或者您什么時候會使用其中一種方法而不是另一種方法?
                  2. 方法 B 允許通過擴展 @Test 注釋來測試異常,如 @Test(expected = ArithmeticException.class).但是在使用方法 A 時如何測試異常?
                  3. 當使用方法 A 時,您可以將多個測試類分組到一個測試套件中,如下所示:

                  1. What is the preferred approach, or when would you use one instead of the other?
                  2. Approach B allows for testing for exceptions by extending the @Test annotation like in @Test(expected = ArithmeticException.class). But how do you test for exceptions when using approach A?
                  3. When using approach A, you can group a number of test classes in a test suite like this:

                  TestSuite suite = new TestSuite("All tests");
                  suite.addTestSuite(DummyTestA.class);
                  suite.addTestSuite(DummyTestAbis.class);

                  但這不能與方法 B 一起使用(因為每個測試類都應該是 TestCase 的子類).為方法 B 分組測試的正確方法是什么?

                  我已將 JUnit 版本添加到這兩種方法中

                  I've added the JUnit versions to both approaches

                  推薦答案

                  區分比較簡單:

                  • 擴展 TestCase 是在 JUnit 3 中編寫單元測試的方式(當然 JUnit 4 仍然支持它)
                  • 使用@Test注解是JUnit 4引入的方式
                  • extending TestCase is the way unit tests were written in JUnit 3 (of course it's still supported in JUnit 4)
                  • using the @Test annotation is the way introduced by JUnit 4

                  通常您應該選擇注釋路徑,除非需要與 JUnit 3(和/或早于 Java 5 的 Java 版本)兼容.新方法有幾個優點:

                  Generally you should choose the annotation path, unless compatibility with JUnit 3 (and/or a Java version earlier than Java 5) is needed. The new way has several advantages:

                  • @Test 注釋 更明確,更容易在工具中支持(例如,通過這種方式可以輕松搜索所有測試)
                  • 可以用 @Before 注釋多個方法/@BeforeClass@After/@AfterClass提供更大的靈活性
                  • 支持 @Rule 注釋ExpectedException 之類的東西
                  • 支持 @Ignored 注釋
                  • 支持使用 @RunWith 的替代測試運行器

                  要在 JUnit 3 TestCase 中測試預期的異常,您必須明確文本.

                  To test for expected exceptions in a JUnit 3 TestCase you'd have to make the text explicit.

                  public void testMyException() {
                    try {
                      objectUnderTest.myMethod(EVIL_ARGUMENT);
                      fail("myMethod did not throw an Exception!");
                    } catch (MyException e) {
                      // ok!
                      // check for properties of exception here, if desired
                    }
                  }
                  

                  JUnit 5 引入了另一個 API 更改,但仍使用注釋.新的 @Test 注釋是 org.junit.jupiter.api.Test(舊"JUnit 4 是 org.junit.Test),但它的工作方式與 JUnit 4 幾乎相同.

                  JUnit 5 introduced yet another API change, but still uses annotations. The new @Test annotation is org.junit.jupiter.api.Test (the "old" JUnit 4 one was org.junit.Test), but it works pretty much the same as the JUnit 4 one.

                  這篇關于JUnit 混淆:使用“擴展 TestCase"或“@Test"?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                    <legend id='vdhep'><style id='vdhep'><dir id='vdhep'><q id='vdhep'></q></dir></style></legend>
                        <bdo id='vdhep'></bdo><ul id='vdhep'></ul>
                          <tbody id='vdhep'></tbody>
                      • <i id='vdhep'><tr id='vdhep'><dt id='vdhep'><q id='vdhep'><span id='vdhep'><b id='vdhep'><form id='vdhep'><ins id='vdhep'></ins><ul id='vdhep'></ul><sub id='vdhep'></sub></form><legend id='vdhep'></legend><bdo id='vdhep'><pre id='vdhep'><center id='vdhep'></center></pre></bdo></b><th id='vdhep'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vdhep'><tfoot id='vdhep'></tfoot><dl id='vdhep'><fieldset id='vdhep'></fieldset></dl></div>

                            <small id='vdhep'></small><noframes id='vdhep'>

                          1. <tfoot id='vdhep'></tfoot>
                            主站蜘蛛池模板: 亚洲高清视频在线观看 | 中文字幕乱码视频32 | 一区二区三区高清 | 国产成人精品一区二区三区在线 | 人人干超碰 | 欧美精品一区三区 | 欧美高清视频 | 久久久激情 | 草草草网站 | 精品国产1区2区3区 在线国产视频 | 日韩一区二区三区视频在线观看 | 欧美中文字幕一区二区 | 一级黄色片美国 | av在线播放国产 | 在线免费观看黄视频 | 亚洲欧美国产精品一区二区 | 国产乱码精品1区2区3区 | 午夜精品在线观看 | 欧美在线一区二区三区 | 伊人伊人 | 国产一区91精品张津瑜 | 欧美在线a | 日韩精品免费视频 | 国产精品久久久久久吹潮 | 国产成人啪免费观看软件 | 免费精品 | 91精品久久久 | 国产免费拔擦拔擦8x高清 | 日本成人免费网站 | 91久久久久久久久久久 | 狠狠狠色丁香婷婷综合久久五月 | 中文字幕乱码一区二区三区 | 亚洲电影第三页 | 黄色免费网 | 精品一区在线 | 免费激情av | 午夜男人天堂 | 一区二区国产精品 | 亚洲精品电影在线观看 | 亚洲九九 | 午夜视频一区二区三区 |