5.新建一個sum類,用來計算兩整數(shù)之和,代碼如下:
packagecom.hpp; publicclasssum{privateintno1;privateintno2;privateintmysum; publicintadd(intno1,intno2){mysum=no1+no2;returnmysum; } }
6.再新建testng class
點擊finish,代碼如下
packagecom.test; importorg.testng.annotations.Test;importstaticorg.testng.Assert.assertEquals;importcom.hpp.sum; publicclassNewTest{privatesum newSum=newsum();
@Testpublicvoidf(){intmysum=newSum.add(1,2);assertEquals(3,mysum,"Right");} }
testing,xml會自動配置好的,這里不用管
項目的文件結(jié)構(gòu)如下:
7.在testing.xml右鍵點擊RunAs->Testng Suite,即可看到結(jié)果