隨筆 - 117  文章 - 72  trackbacks - 0

          聲明:原創(chuàng)作品(標(biāo)有[原]字樣)轉(zhuǎn)載時(shí)請(qǐng)注明出處,謝謝。

          常用鏈接

          常用設(shè)置
          常用軟件
          常用命令
           

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

          • 積分 - 156402
          • 排名 - 390

          最新評(píng)論

          [標(biāo)題]:[轉(zhuǎn)]JUnit4.5 QuickTutorial
          [時(shí)間]:2009-7-5
          [摘要]:JUnit官方例子QuickTutorial
          [關(guān)鍵字]:JUnit、Test、測(cè)試、單元測(cè)試、helloworld
          [環(huán)境]:JUnit4.5、MyEclipse7
          [作者]:Winty (wintys@gmail.com) http://www.aygfsteel.com/wintys

          [正文]:
          Subscription.java:
          package wintys.junit;

          /**
           * JUnit4.5 QuickTutorial
           * http://code.google.com/p/t2framework/wiki/JUnitQuickTutorial
           *  
           * @author Winty
           * @version 2009-07-04
           */
          public class Subscription {
                 private int price ; // subscription total price in euro-cent
                 private int length ; // length of subscription in months

                 // constructor :
                 public Subscription(int p, int n) {
                   price = p ;
                   length = n ;
                 }

                /**
                 * Calculate the monthly subscription price in euro,
                 * rounded up to the nearest cent.
                 */
                 public double pricePerMonth() {
                   double r = (double) price / (double) length /100.0;
                    return r ;
                 }

                /**
                 * Call this to cancel/nulify this subscription.
                 */
                 public void cancel() { length = 0 ; }
          }

          用JUnit測(cè)試:
          SubscriptionTest.java:
          package wintys.junit;

          import static org.junit.Assert.*;

          import org.junit.After;
          import org.junit.Before;
          import org.junit.Test;

          public class SubscriptionTest {
              Subscription S;

              @Before
              public void setUp() throws Exception {
                   S = new Subscription(200,2) ;
              }

              @After
              public void tearDown() throws Exception {
                  S = null;
              }

              @Test
              public void testPricePerMonth() {
                  
                  assertEquals(S.pricePerMonth() , 1.0);
              }

          }

          [參考資料]:
          JUnitQuickTutorial : http://code.google.com/p/t2framework/wiki/JUnitQuickTutorial
          posted on 2009-07-07 23:49 天堂露珠 閱讀(347) 評(píng)論(0)  編輯  收藏 所屬分類: Test

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 若尔盖县| 中牟县| 青河县| 双流县| 兴文县| 成武县| 通山县| 阳曲县| 桑日县| 通辽市| 扬中市| 青神县| 稻城县| 建水县| 翁牛特旗| 屯留县| 尖扎县| 大安市| 穆棱市| 新宾| 浦北县| 弥勒县| 玉树县| 丹寨县| 阳朔县| 高邮市| 谢通门县| 灌阳县| 隆化县| 太白县| 调兵山市| 嵩明县| 秀山| 枣强县| 海口市| 宁蒗| 华宁县| 海盐县| 鹰潭市| 淄博市| 太仓市|