南宁建设局网站,石家庄云图网站建设,wordpress忘记,怎么创建一个属于自己的平台编写TestNG用例测试基本上包括以下步骤#xff1a;编写业务逻辑针对业务逻辑中涉及的方法编写测试类#xff0c;在代码中插入TestNG的注解直接执行测试类或者添加一个testng.xml文件运行 TestNG.下面我们介绍一个完整的例子来测试一个逻辑类#xff1b;1.创建一个pojo类Empl…编写TestNG用例测试基本上包括以下步骤编写业务逻辑针对业务逻辑中涉及的方法编写测试类在代码中插入TestNG的注解直接执行测试类或者添加一个testng.xml文件运行 TestNG.下面我们介绍一个完整的例子来测试一个逻辑类1.创建一个pojo类EmployeeDetail.javapublic 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.创建一个EmployeeLogic.javapublic classEmployeeLogic {//Calculate the yearly salary of employeepublic doublecalculateYearlySalary(EmployeeDetail employeeDetails){double yearlySalary0;yearlySalary employeeDetails.getMonthlySalary() * 12;returnyearlySalary;}}EmployeeLogic.java用来计算员工年工资3.创建一个测试类为NewTest包含测试用例用来进行测试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 salaryTestpublic 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.测试执行选中这个类-》右键-》run as 选择TestNG Test5.查看执行结果控制台会输出如下可以看到运行了一个test成功输出TestNG输出控制台结果如下我们可以看到运行了一testCalculateYearlySalary测试方法并且测试通过。如果我们将测试代码中的Assert.assertEquals(96000, salary, 0.0, 8000);改为Assert.assertEquals(86000, salary, 0.0, 8000);则运行结果如下