JUnit和TestNG的區別
作者:
網絡轉載 發布時間:
[ 2014/8/18 14:36:36 ] 推薦標簽:
TestNG
然后相應的我們用@DataProvider來標注一個方法,這個方法提供了數據:
//This function will provide the patameter data
@DataProvider(name = "Data-Provider-Function")
public Object[][] parameterIntTestProvider() {
TestNGTest6_3_0 obj = new TestNGTest6_3_0();
obj.setMsg("Hello");
obj.setNumber(123);
return new Object[][]{
{obj}
};
}
3.測試依賴性:
對于JUnit 來說,所有的測試彼此之間都是獨立的,毫無依賴性。
但是對于 TestNG來說,我們完全可以讓測試彼此之間有依賴性,做法是dependsOnMethods屬性來標識一個被依賴的測試方法:
@Test
public void method1() {
System.out.println("This is method 1");
}
@Test(dependsOnMethods={"method1"})
public void method2() {
System.out.println("This is method 2");
}