小编naq*_*ash的帖子

如果在TestNG中执行组,则不会调用@Before Suite和@BeforeTest方法

下面是我的XML文件和Demo Class.Precondition()方法将在demo1()方法之前运行,而postCondition()方法将在demo1()方法之后运行.同样的过程适用于demo2().但是当我运行代码时,不会调用BeforeSuite和BeforeTest方法.为什么.?怎么称呼他们?

Output :           
Before Method is executing                                                       
DEMO -1   
After Method is executing  
Before Method is executing  
DEMO 2  
After Method is executing
Run Code Online (Sandbox Code Playgroud)
<?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 = "Hey"></include>
            </run>
        </groups>
        <classes>
            <class name="practicepackage.Demo"/>
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->  
Run Code Online (Sandbox Code Playgroud)
package practicepackage;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Demo {

    @BeforeSuite
    public void beforeSuite(){
        System.out.println("Before Suite method is being …
Run Code Online (Sandbox Code Playgroud)

testng annotations

2
推荐指数
1
解决办法
2462
查看次数

标签 统计

annotations ×1

testng ×1