@BeforeSuite 不工作
@BeforeSuite not working
我试过这个:
基类
package pages;
import org.testng.annotations.BeforeSuite;
public class BaseClass {
@BeforeSuite
public static void setup() {
System.out.println("in set up method");
}
}
测试类
package pages;
import org.testng.annotations.Test;
public class TestClass extends BaseClass {
@Test(groups = { "group1" })
public void grpOnetest() {
System.out.println("Method grp one");
}
@Test(groups = { "group2" })
public void grpTwotest() {
System.out.println("Method grp two");
}
@Test(groups = { "group3" })
public void grpThreetest() {
System.out.println("method grp three");
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name="group1" />
</run>
</groups>
<classes>
<class name="pages.TestClass" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
它没有给出任何错误,只是不打印:
"in set up method" 即不 运行 @BeforeSuite
您需要将设置方法放入您要包含的组中,否则它不会运行,因为该方法不属于该组。
将套件添加到所有组,应该可以。
您需要 alwaysRun = true
@BeforeSuite
。
For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to.
换句话说,如果您 运行 具有特定组的套件,配置方法必须具有预期的组或 alwaysRun
将激活每个组的方法.
我试过这个: 基类
package pages;
import org.testng.annotations.BeforeSuite;
public class BaseClass {
@BeforeSuite
public static void setup() {
System.out.println("in set up method");
}
}
测试类
package pages;
import org.testng.annotations.Test;
public class TestClass extends BaseClass {
@Test(groups = { "group1" })
public void grpOnetest() {
System.out.println("Method grp one");
}
@Test(groups = { "group2" })
public void grpTwotest() {
System.out.println("Method grp two");
}
@Test(groups = { "group3" })
public void grpThreetest() {
System.out.println("method grp three");
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name="group1" />
</run>
</groups>
<classes>
<class name="pages.TestClass" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
它没有给出任何错误,只是不打印:
"in set up method" 即不 运行 @BeforeSuite
您需要将设置方法放入您要包含的组中,否则它不会运行,因为该方法不属于该组。
将套件添加到所有组,应该可以。
您需要 alwaysRun = true
@BeforeSuite
。
For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to.
换句话说,如果您 运行 具有特定组的套件,配置方法必须具有预期的组或 alwaysRun
将激活每个组的方法.