TestNG 重写TestCase框架方法
2020-05-14 本文已影响0人
BestFei
一、重写TestCase
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.ITest;
import org.testng.ITestContext;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
@Listeners({ReportListener.class})
public class TestCase extends AbstractTestNGSpringContextTests implements ITest {
public TestCase() {
}
@BeforeMethod
public void BeforeMethod(Method method, Object[] testData) {
}
@AfterMethod
public void afterMethod(Method method, Object[] testData) {
this.steps.clear();
}
@BeforeClass(
alwaysRun = true
)
public void beforeScenario() {
}
@AfterClass(
alwaysRun = true
)
@DataProvider(name = "providerTestCaseData")
public Object[][] providerTestData(Method method, ITestContext context) throws IOException {
Object[][] ret = (Object[][])null;
// ...
return ret;
}
}
二、业务测试类继承重写的TestCase
public class LoginTest extends TestCase {
@TestCaseDesc(author = "best.fei",version = "1.0.0",)
@CaseDataSource(filename = "loginTestData.json")
@Test(dataProvider = "providerTestCaseData")
public void testNormalLogin(InputParam inputParam) throws Exception {
}