@BeforeClass、@AfterClass、@BeforeMethod、@AfterMethod注解下的方法不起作用,只有Suite注解起作用

问题描述 投票:0回答:0
package com.edureka.testng1;

import org.testng.Reporter;
import org.testng.annotations.*;
public class AnnoitationsDemo {
    
    @BeforeSuite
    public void beforeSuiteMethod()
    {
        Reporter.log("Before suite Method",true);
    }
    
    @AfterSuite
    public void afterSuiteMethod()
    {
        Reporter.log("After suite method",true);
    }
    
    @BeforeClass
    public void beforeClassMethod()
    {
        Reporter.log("Before suite method",true);
    }
    
    @AfterClass
    public void afterClassMethod()
    {
        Reporter.log("After class method", true);
    }
    
    @BeforeMethod
    public void beforeMethod()
    {
        Reporter.log("Before method",true);
    }
    
    @AfterMethod
    public void afterMethod()
    {
        Reporter.log("After method",true);
    }
}
package com.edureka.testng1;

import org.testng.Reporter;
import org.testng.annotations.Test;

public class TaskModuleScripts {
    
    @Test (groups = {"Smoke", "Task"})
    public void task1()
    {
        Reporter.log("task 1 method");
    }
    
    @Test (groups = {"Smoke", "Task"})
    public void atask2()
    {
        Reporter.log("task 2 method");
    }
    
    @Test
    public void task3()
    {
        Reporter.log("task 3 method");
    }
    
    @Test
    public void task4()
    {
        Reporter.log("task 4 method");
    }
}

我期待

@BeforeMethods
下的方法应该在每个测试方法之前运行。我已经在
AnnoitationsDemo
<Classes>
 标签下包含了 
testng.xml

java selenium-webdriver testng testng-eclipse
© www.soinside.com 2019 - 2024. All rights reserved.