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

  因為在測試過程中可能不能同時run所有的測試用例,或者是想同時run不同的測試用例或所有的用例,那么我們要維護一個公共的Suite,這個Suite可以添加TestSuite或一個單個用例(測試函數(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);
 }
}

  另外一個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òu)造函數(shù),因為要調(diào)用父類的構(gòu)造函數(shù),用于下面Suite添加該類的測試方法
 @Before
 public void setUp() throws Exception {
 }
 @After
 public void tearDown() throws Exception {
 }
 @Test
 public void testHelloworld() {
  //fail("Not yet implemented");
  assertEquals(2,2);
 }
}

  那么我們可以對這兩個不相關(guān)的測試類集合進行包裝,是建立一個TestSuite類,封裝這些不相關(guān)的類,這對于我們大的項目來說是非常關(guān)鍵的,因為我們可能同時維護很多測試類,run回歸測試用例等。

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