您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > TestNG
持續(xù)集成:TestNG組織如何測(cè)試用例
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/12/25 11:36:32 ] 推薦標(biāo)簽:軟件測(cè)試工具 單元測(cè)試工具

  1. 目前組織test case的實(shí)踐
  將所有測(cè)試方法放在Common Task的類中,然后根據(jù)test case的測(cè)試邏輯,創(chuàng)建對(duì)應(yīng)的測(cè)試類,然后用TestNG運(yùn)行這些測(cè)試類。
  目前實(shí)踐的實(shí)例代碼如下:
  包含所有測(cè)試方法CommonTasks文件:
import java.util.Random;
public class CommonTasks {
public int method1(int max) {
System.out.println("Run method1()");
return new Random().nextInt(max);
}
public int method2(int max) {
System.out.println("Run method2()");
return new Random().nextInt(max);
}
}
  測(cè)試類TestCase1:先執(zhí)行method1,后執(zhí)行method2
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestCase1 {
CommonTasks task;
@BeforeClass
public void setUp() {
task = new CommonTasks();
}
@Test
@Parameters("max")
public void method1(int max) {
Assert.assertEquals(task.method1(max), 0, "Failed");
}
@Test(dependsOnMethods = "method1")
@Parameters("max")
public void method2(int max) {
Assert.assertEquals(task.method2(max), 0, "Failed");
}
}
  測(cè)試類TestCase2:先執(zhí)行method2,后執(zhí)行method1
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestCase2 {
CommonTasks task;
@BeforeClass
public void setUp() {
task = new CommonTasks();
}
@Test(dependsOnMethods = "method2")
@Parameters("max")
public void method1(int max) {
Assert.assertEquals(task.method1(max), 0, "Failed");
}
@Test
@Parameters("max")
public void method2(int max) {
Assert.assertEquals(task.method2(max), 0, "Failed");
}
}

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