亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Junit4測試
作者:網絡轉載 發布時間:[ 2013/3/21 15:22:14 ] 推薦標簽:

        完整的循環測試代碼如下:
Java代碼
import static org.junit.Assert.*; 
 
import java.util.Arrays; 
import java.util.Collection; 
 
import org.junit.AfterClass; 
import org.junit.BeforeClass; 
import org.junit.Ignore; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.junit.runners.Parameterized; 
import org.junit.runners.Parameterized.Parameters; 
 
/**
 * @author bulargy.j.bai
 * @創建時間:Mar 11, 2008
 * @描述:
 */
@RunWith(Parameterized.class) 
public class MathTest { 
    int faciend; 
    int multiplicator; 
    int result; 
 
    public MathTest(int faciend, int multiplicator, int result) { 
         this.faciend = faciend; 
         this.multiplicator = multiplicator; 
         this.result = result; 
    } 
    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception { 
    } 
 
    /**
     * @throws java.lang.Exception
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception { 
    } 
 
    /**
     * Test method for {@link org.bj.util.Math#divide(int, int)}.
     */
    @Test(expected=ArithmeticException.class) 
    public void testDivide() { 
        assertEquals(3,Math.divide(9,3)); 
        assertEquals(3,Math.divide(10,3)); 
        Math.divide(10,0);//除數不能為0,會拋出異常 
 
    } 
 
    /**
     * Test method for {@link org.bj.util.Math#multiple(int, int)}.
     */
    //@Ignore("忽略乘法測試") 
    @Test
    public void testMultiple() { 
        assertEquals(result,Math.multiple(faciend,multiplicator)); 
    } 
     
    @Parameters
    public static Collection multipleValues() { 
     return Arrays.asList(new Object[][] { 
        {3, 2, 6 }, 
        {4, 3, 12 }, 
        {21, 5, 105 }, 
        {11, 22, 242 }, 
        {8, 9, 72 }}); 
    } 
 
}

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collection;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * @author bulargy.j.bai
 * @創建時間:Mar 11, 2008
 * @描述:
 */
@RunWith(Parameterized.class)
public class MathTest {
 int faciend;
 int multiplicator;
 int result;

 public MathTest(int faciend, int multiplicator, int result) {
   this.faciend = faciend;
   this.multiplicator = multiplicator;
   this.result = result;
 }
 /**
  * @throws java.lang.Exception
  */
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
 }

 /**
  * @throws java.lang.Exception
  */
 @AfterClass
 public static void tearDownAfterClass() throws Exception {
 }

 /**
  * Test method for {@link org.bj.util.Math#divide(int, int)}.
  */
 @Test(expected=ArithmeticException.class)
 public void testDivide() {
  assertEquals(3,Math.divide(9,3));
  assertEquals(3,Math.divide(10,3));
  Math.divide(10,0);//除數不能為0,會拋出異常

 }

 /**
  * Test method for {@link org.bj.util.Math#multiple(int, int)}.
  */
 //@Ignore("忽略乘法測試")
 @Test
 public void testMultiple() {
  assertEquals(result,Math.multiple(faciend,multiplicator));
 }
 
 @Parameters
 public static Collection multipleValues() {
  return Arrays.asList(new Object[][] {
        {3, 2, 6 },
        {4, 3, 12 },
        {21, 5, 105 },
        {11, 22, 242 },
        {8, 9, 72 }});
 }

}
        OK,大功告成。測試看看吧,測試類跑了5次~~。

        大概這么多體會了,總得來說JUnit4以后測試還是很方便的,順便這個是僅僅是為了做例子,實際使用中由于JUnit4不再受命名的限制,所以應該劃分更細粒度的測試來完成,一個方法的正確,異常,錯誤及邊界數據完全可以分開來寫測試方法。由于大部分情況資源只用加載和釋放一次足夠,大大提高的測試的速度,再也不會有以前那樣點開測試然后去泡咖啡的情況出現了~~呵呵~~

上一頁123下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 成人羞羞视频在线观看 | 性欧美成人免费观看视 | 亚洲一区中文 | 国产精品免费观在线 | 日韩123| 综合色久七七综合七七蜜芽 | 国产在线精品一区二区三区 | 久久亚 | 久久天天躁夜夜躁狠狠 | 黄色天堂 | 国产丝袜在线播放 | 国产黑色丝袜小视频在线 | 98精品| 日批免费视频不要会员 | 亚洲欧美一区在线 | 欧美精品在欧美一区二区 | 性生大片一级毛片免费观看 | 4四虎44虎www在线影院麻豆 | 成年网站在线看 | 在线看片a | 三级黄在线 | 国产男女猛烈无遮档免费视频网站 | 欧美极品另类高清videos | 精品无码久久久久久久动漫 | 在线另类 | 日本在线看小视频网址 | 亚洲色图50p | 久久777国产线看是看精品 | 色漫免费看 | 顶级毛片在线手机免费看 | 色综合久久久久久久久五月性色 | 日韩精品免费视频 | 欧美一级在线观看播放 | 国产精品永久免费视频观看 | 天天精品视频 | 精品国产日韩亚洲一区二区 | www.日日爱 | 国产在线91精品天天更新 | 草草在线观看视频 | 高清不卡一区二区 | 欧美中文综合在线视频 |