随笔 - 117  文章 - 72  trackbacks - 0

声明:原创作品(标有[原]字样)转载时请注明出处,谢谢。

常用链接

常用设置
常用软件
常用命令
 

订阅

订阅

留言簿(7)

随笔分类(130)

随笔档案(123)

搜索

  •  

积分与排名

  • 积分 - 152576
  • 排名 - 390

最新评论

[标题]:[转]JUnit4.5 QuickTutorial
[时间]:2009-7-5
[摘要]:JUnit官方例子QuickTutorial
[关键字]:JUnit、Test、测试、单元测试、helloworld
[环境]:JUnit4.5、MyEclipse7
[作者]:Winty (wintys@gmail.com) http://www.blogjava.net/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 天堂露珠 阅读(311) 评论(0)  编辑  收藏 所属分类: Test

只有注册用户登录后才能发表评论。


网站导航: