我是TESTNG框架的新手。在這個框架中沒有主要的方法。因此我的疑問是,我們可以使用new關鍵字在測試套件的任何位置創建對象嗎?或者是否有一個基本規則,即對象只能在某些地方被實例化(比如像@beforesuite,@test等testng註釋)?在下面的代碼中,當我使用new關鍵字(Ideal objIdeal = new Ideal();)時,它會失敗,但是當我將它放入@test註釋方法(login或logout)時,它會通過。因此,在使用Testng框架時,在類中實例化對象的基本拇指規則是什麼。TestNG框架和新關鍵字
package testing.ideal;
public class Application {
public String strURL;
public Application() {
this.strURL = Ideal.strURL;
System.out.println("the url is--" + this.strURL);
}
}
package testing.ideal;
import org.testng.annotations.*;
public class Ideal
extends Application {
public static String strURL = "XXX";
Ideal objIdeal = new Ideal();
@Test
public void login() {
System.out.println("This is an testng Method");
}
@Test
public void logout() {
System.out.println("This is an testng Method");
}
}
/* This is Testng XML*/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel = "none">
<test name="login" >
<classes>
<class name="testing.ideal.Ideal">
</class>
</classes>
</test>
</suite>
你需要用專用的亞軍類運行測試類的實例;你的環境很不清楚 – fge