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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 在 @Unit 中使用泛型 泛型為 **@Unit** 出了一個難題,因為我們不可能“通用測試”。我們必須針對某個特定類型的參數或者參數集才能進行測試。解決方法十分簡單,讓測試類繼承自泛型類的一個特定版本即可: 下面是一個 **stack** 的簡單實現: ```java // annotations/StackL.java // A stack built on a LinkedList package annotations; import java.util.*; public class StackL<T> { private LinkedList<T> list = new LinkedList<>(); public void push(T v) { list.addFirst(v); } public T top() { return list.getFirst(); } public T pop() { return list.removeFirst(); } } ``` 為了測試 String 版本,我們直接讓測試類繼承一個 Stack\<String\> : ```java // annotations/StackLStringTst.java // Applying @Unit to generics // {java onjava.atunit.AtUnit // build/classes/main/annotations/StackLStringTst.class} package annotations; import onjava.atunit.*; import onjava.*; public class StackLStringTst extends StackL<String> { @Test void tPush() { push("one"); assert top().equals("one"); push("two"); assert top().equals("two"); } @Test void tPop() { push("one"); push("two"); assert pop().equals("two"); assert pop().equals("one"); } @Test void tTop() { push("A"); push("B"); assert top().equals("B"); assert top().equals("B"); } } ``` 輸出為: ```java annotations.StackLStringTst . tTop . tPush . tPop OK (3 tests) ``` 這種方法存在的唯一缺點是,繼承使我們失去了訪問被測試的類中 **private** 方法的能力。這對你非常重要,那你要么把 private 方法變為 **protected**,要么添加一個非 **private** 的 **@TestProperty** 方法,由它來調用 **private** 方法(稍后我們會看到,**AtUnitRemover** 會刪除產品中的 **@TestProperty** 方法)。 **@Unit** 搜索那些包含合適注解的類文件,然后運行 **@Test** 方法。我的主要目標就是讓 **@Unit** 測試系統盡可能的透明,使得人們使用它的時候只需要添加 **@Test** 注解,而不需要特殊的編碼和知識(現在版本的 **JUnit** 符合這個實踐)。不過,如果說編寫測試不會遇到任何困難,也不太可能,因此 **@Unit** 會盡量讓這些困難變的微不足道,希望通過這種方式,你們會更樂意編寫測試。
                  <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>

                              哎呀哎呀视频在线观看