概述
个人分类: 框架
配置文件:
<!-- @BeforeTest -->
<test name="case1">
<classes>
<class name="com.yiibai.TestDBConnection" />
<class name="com.yiibai.DBConfig" />
</classes>
</test>
<!-- @AfterTest -->
<!-- @BeforeTest -->
<test name="case2">
<classes>
<class name="com.yiibai.TestDBConnection" />
<class name="com.yiibai.DBConfig" />
</classes>
</test>
<!-- @AfterTest -->
java代码
package com.yiibai;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class TestDBConnection {
@Test
public void runOtherTest1() {
System.out.println("@Test - runOtherTest1");
}
@Test
public void runOtherTest2() {
System.out.println("@Test - runOtherTest2");
}
@Test(expectedExceptions = ArithmeticException.class)
public void divisionWithException() {
int i = 1 / 0;
System.out.println("After division the value of i is :"+ i);
}
@BeforeGroups("database")
public void setupDB() {
System.out.println("setupDB()");
}
@AfterGroups("database")
public void cleanDB() {
System.out.println("cleanDB()");
}
@Test(groups = "selenium-test")
public void runSelenium() {
System.out.println("runSelenium()");
}
@Test(groups = "selenium-test")
public void runSelenium1() {
System.out.println("runSelenium()1");
}
@Test(groups = "database")
public void testConnectOracle() {
System.out.println("testConnectOracle()");
}
@Test(groups = "database")
public void testConnectMsSQL() {
System.out.println("testConnectMsSQL");
}
@Test(dependsOnGroups = { "database", "selenium-test" })
public void runFinal() {
System.out.println("runFinal");
}
}
public class DBConfig {
@BeforeSuite()
public void beforeSuite() {
System.out.println("@BeforeSuite");
}
@AfterSuite()
public void afterSuite() {
System.out.println("@AfterSuite");
}
@BeforeTest()
public void beforeTest() {
System.out.println("@BeforeTest");
}
@AfterTest()
public void afterTest() {
System.out.println("@AfterTest");
}
最后
以上就是酷炫火为你收集整理的TestNg的使用的全部内容,希望文章能够帮你解决TestNg的使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复