隨筆 - 117  文章 - 72  trackbacks - 0

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

          常用鏈接

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

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

          • 積分 - 155532
          • 排名 - 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 天堂露珠 閱讀(334) 評論(0)  編輯  收藏 所屬分類: Test

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


          網站導航:
           
          主站蜘蛛池模板: 平度市| 华蓥市| 绥芬河市| 怀宁县| 武宣县| 塔城市| 盐池县| 青铜峡市| 大方县| 申扎县| 安远县| 永泰县| 潞城市| 连平县| 泉州市| 庆阳市| 德兴市| 红原县| 蛟河市| 广宗县| 云阳县| 吉隆县| 四平市| 嵊泗县| 潮州市| 禄丰县| 札达县| 保亭| 高阳县| 安福县| 横峰县| 通州市| 四子王旗| 黄平县| 通海县| 汉中市| 沅江市| 焦作市| 武川县| 灵山县| 通许县|