隨筆 - 117  文章 - 72  trackbacks - 0

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

          常用鏈接

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

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 富裕县| 沅陵县| 霍州市| 汝阳县| 申扎县| 蓝山县| 穆棱市| 灵宝市| 原阳县| 昌平区| 独山县| 正宁县| 珲春市| 武定县| 科尔| 七台河市| 鄢陵县| 新泰市| 沂源县| 福建省| 宜城市| 双桥区| 南康市| 辽阳市| 苗栗市| 彩票| 中卫市| 郴州市| 巴彦淖尔市| 疏勒县| 于都县| 化隆| 新田县| 察哈| 宿州市| 蓬溪县| 丰台区| 浦东新区| 谷城县| 会理县| 佛教|