日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java测试用例编写_TestNG测试用例编写和执行

發(fā)布時間:2024/9/27 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java测试用例编写_TestNG测试用例编写和执行 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

編寫TestNG用例測試基本上包括以下步驟:

編寫業(yè)務(wù)邏輯

針對業(yè)務(wù)邏輯中涉及的方法編寫測試類,在代碼中插入TestNG的注解

直接執(zhí)行測試類或者添加一個testng.xml文件

運(yùn)行 TestNG.

下面我們介紹一個完整的例子來測試一個邏輯類;

1.創(chuàng)建一個pojo類EmployeeDetail.java

public classEmployeeDetail {privateString name;private doublemonthlySalary;private intage;/***@returnthe name*/

publicString getName() {returnname;

}/***@paramname the name to set*/

public voidsetName(String name) {this.name =name;

}/***@returnthe monthlySalary*/

public doublegetMonthlySalary() {returnmonthlySalary;

}/***@parammonthlySalary the monthlySalary to set*/

public void setMonthlySalary(doublemonthlySalary) {this.monthlySalary =monthlySalary;

}/***@returnthe age*/

public intgetAge() {returnage;

}/***@paramage the age to set*/

public void setAge(intage) {this.age =age;

}

}

EmployeeDetail用來:

get/set 員工的名字的值

get/set?員工月薪的值

get/set員工年齡的值

2.創(chuàng)建一個EmployeeLogic.java

public classEmployeeLogic {//Calculate the yearly salary of employee

public doublecalculateYearlySalary(EmployeeDetail employeeDetails){double yearlySalary=0;

yearlySalary= employeeDetails.getMonthlySalary() * 12;returnyearlySalary;

}

}

EmployeeLogic.java用來:

計(jì)算員工年工資

3.創(chuàng)建一個測試類,為NewTest,包含測試用例,用來進(jìn)行測試;

importorg.testng.Assert;importorg.testng.annotations.Test;importorg.testng.annotations.BeforeMethod;importorg.testng.annotations.AfterMethod;importorg.testng.annotations.DataProvider;importorg.testng.annotations.BeforeClass;importorg.testng.annotations.AfterClass;importorg.testng.annotations.BeforeTest;importorg.testng.annotations.AfterTest;importorg.testng.annotations.BeforeSuite;importorg.testng.annotations.AfterSuite;importcom.thunisoft.Employee.EmployeeDetail;public classNewTest {

EmployeeLogic empBusinessLogic= newEmployeeLogic();

EmployeeDetail employee= newEmployeeDetail();//test to check yearly salary

@Testpublic voidtestCalculateYearlySalary() {

employee.setName("Rajeev");

employee.setAge(25);

employee.setMonthlySalary(8000);double salary =empBusinessLogic

.calculateYearlySalary(employee);

Assert.assertEquals(96000, salary, 0.0, "8000");

}

}

NewTest.java類作用:測試員工年薪

4.測試執(zhí)行:選中這個類-》右鍵-》run as 選擇TestNG Test

5.查看執(zhí)行結(jié)果

控制臺會輸出如下:

可以看到,運(yùn)行了一個test,成功輸出

TestNG輸出控制臺結(jié)果如下:

我們可以看到運(yùn)行了一testCalculateYearlySalary測試方法,并且測試通過。

如果我們將測試代碼中的Assert.assertEquals(96000, salary, 0.0, "8000");改為

Assert.assertEquals(86000, salary, 0.0, "8000");,則運(yùn)行結(jié)果如下:

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的java测试用例编写_TestNG测试用例编写和执行的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。