您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > junit
用testsuite管理junit單元測(cè)試用例
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/9/26 11:19:06 ] 推薦標(biāo)簽:testsuite junit 單元測(cè)試

  因?yàn)樵跍y(cè)試過程中可能不能同時(shí)run所有的測(cè)試用例,或者是想同時(shí)run不同的測(cè)試用例或所有的用例,那么我們要維護(hù)一個(gè)公共的Suite,這個(gè)Suite可以添加TestSuite或一個(gè)單個(gè)用例(測(cè)試函數(shù))。

TestCase->TestSuite,Testmethods->TestSuite

  舉例說明:

package calculor.Calculor;
import static org.junit.Assert.*;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class CalcTest extends TestCase {
 @Before
 public void setUp() throws Exception {
 }
 @After
 public void tearDown() throws Exception {
 }
 @Test
 public void testAdd() {
  //fail("Not yet implemented");
  assertEquals(2, 2);
 }
}

  另外一個(gè)TestCase集合類

package calculor.Calculor;

import static org.junit.Assert.*;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TTmmTest extends TestCase {
 public TTmmTest(){}
 public TTmmTest (String name){
  super(name);
 }//注意這里添加了這個(gè)構(gòu)造函數(shù),因?yàn)橐{(diào)用父類的構(gòu)造函數(shù),用于下面Suite添加該類的測(cè)試方法
 @Before
 public void setUp() throws Exception {
 }
 @After
 public void tearDown() throws Exception {
 }
 @Test
 public void testHelloworld() {
  //fail("Not yet implemented");
  assertEquals(2,2);
 }
}

  那么我們可以對(duì)這兩個(gè)不相關(guān)的測(cè)試類集合進(jìn)行包裝,是建立一個(gè)TestSuite類,封裝這些不相關(guān)的類,這對(duì)于我們大的項(xiàng)目來說是非常關(guān)鍵的,因?yàn)槲覀兛赡芡瑫r(shí)維護(hù)很多測(cè)試類,run回歸測(cè)試用例等。

上一頁12下一頁
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd