隨筆 - 117  文章 - 72  trackbacks - 0

          聲明:原創作品(標有[原]字樣)轉載時請注明出處,謝謝。

          常用鏈接

          常用設置
          常用軟件
          常用命令
           

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

          • 積分 - 156212
          • 排名 - 390

          最新評論

          [標題]:[轉]JUnit4.5 QuickTutorial
          [時間]:2009-7-5
          [摘要]:JUnit官方例子QuickTutorial
          [關鍵字]:JUnit、Test、測試、單元測試、helloworld
          [環境]: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測試:
          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 天堂露珠 閱讀(344) 評論(0)  編輯  收藏 所屬分類: Test

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 醴陵市| 从江县| 乐都县| 团风县| 青浦区| 加查县| 五大连池市| 六安市| 清丰县| 新田县| 建瓯市| 奇台县| 环江| 穆棱市| 东至县| 崇文区| 深州市| 苏州市| 江孜县| 余江县| 土默特左旗| 内乡县| 报价| 扶风县| 呼玛县| 潮州市| 庐江县| 大竹县| 临邑县| 曲周县| 常德市| 永胜县| 霍州市| 登封市| 新田县| 资中县| 汶川县| 彭州市| 益阳市| 扶沟县| 乐山市|