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

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


          網站導航:
           
          主站蜘蛛池模板: 高淳县| 高要市| 思南县| 淳化县| 蛟河市| 密山市| 四子王旗| 莱阳市| 亳州市| 东乡| 武宁县| 安平县| 桓台县| 琼海市| 罗源县| 南宁市| 蛟河市| 梁山县| 瓮安县| 南部县| 金堂县| 兴义市| 增城市| 阿巴嘎旗| 双城市| 榆树市| 满洲里市| 浮山县| 庄浪县| 凯里市| 无为县| 都昌县| 精河县| 措美县| 义乌市| 简阳市| 乾安县| 开江县| 松桃| 天长市| 茂名市|