testNG 注释实例
1. 单个测试用例文件
新建TestDBConnection.java文件
import org.testng.annotations.*;
public class TestDBConnection {
@Test
public void runOtherTest1() {
System.out.println("@Test - runOtherTest1");
}
@Test
public void runOtherTest2() {
System.out.println("@Test - runOtherTest2");
}
@Test(groups = "haha")
public void runOtherTest3() {
System.out.println("@Test - runOtherTest3");
}
@BeforeClass
public void beforeClass() {
System.out.println("@Test - BeforeClass");
}
@BeforeGroups(groups = "haha")
public void beforeGroups() {
System.out.println("@Test - BeforeGroups");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("@Test - BeforeMethod");
}
@AfterMethod
public void afterMethod() {
System.out.println("@Test - AfterMethod");
}
@AfterGroups(groups = "haha")
public void afterGroups() {
System.out.println("@Test - AfterGroups");
}
@AfterClass
public void afterClass() {
System.out.println("@Test - AfterClass");
}
}
配置并运行

点击运行,结果如下:
[TestNG] Running:
/Users/sunmin/Library/Caches/IdeaIC2017.3/temp-testng-customsuite.xml
@Test - BeforeClass
@Test - BeforeMethod
@Test - runOtherTest1
@Test - AfterMethod
@Test - BeforeMethod
@Test - runOtherTest2
@Test - AfterMethod
@Test - BeforeGroups
@Test - BeforeMethod
@Test - runOtherTest3
@Test - AfterMethod
@Test - AfterGroups
@Test - AfterClass ===============================================
Default Suite
Total tests run: 3, Failures: 0, Skips: 0
=============================================== Process finished with exit code 0
2. Test Suit
新建TestDBConfig.java文件,内容如下:
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest; public class TestDBConfig { @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.xml文件,位置放在pom.xml同级,内容如下。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <!-- @BeforeSuite -->
<suite name="TestAll"> <!-- @BeforeTest -->
<test name="case1">
<classes>
<class name="TestDBConfig" />
</classes>
</test>
<!-- @AfterTest --> <!-- @BeforeTest -->
<test name="case2">
<classes>
<class name="TestDBConnection" />
</classes>
</test>
<!-- @AfterTest -->
</suite>
<!-- @AfterSuite -->
配置及运行

Test kind需选择Suite,Suite的配置文件选择我们自己的testng.xml文件。点击运行,结果如下:为啥@AfterTest会出现在这个地方?
[TestNG] Running:
/Users/sunmin/Downloads/TestHelloWorld/testng.xml
@BeforeSuite
@BeforeTest
@AfterTest
@Test - BeforeClass
@Test - BeforeMethod
@Test - runOtherTest1
@Test - AfterMethod
@Test - BeforeMethod
@Test - runOtherTest2
@Test - AfterMethod
@Test - BeforeGroups
@Test - BeforeMethod
@Test - runOtherTest3
@Test - AfterMethod
@Test - AfterGroups
@Test - AfterClass
@AfterSuite ===============================================
TestAll
Total tests run: 3, Failures: 0, Skips: 0
=============================================== Process finished with exit code 0
testNG 注释实例的更多相关文章
- 利用Testng注释实现多线程并发测试
Testng 是一款非常优秀的测试框架,真正从测试角度出发,为测试所想.在测试过程中我们经常会遇到对某一个场景做并发请求,主要想了解该程序在并发时是否会有异常或者没考虑到的其他情况,这时往往不是要做性 ...
- C#枚举注释实例
public enum 枚举名称 { /// <summary> /// 注释描述1 /// </summary> ...
- TestNG注释@BeforeGroups与@AfterGroups不执行的处理
在学习TestNG框架注解时发现在执行以下的代码 package com.groups; import org.testng.annotations.AfterGroups; import org.t ...
- selenium TestNG基本注释和属性
TestNG注释详解 suite 属性说明: @name: suite 的名称,必须参数@junit:是否以Junit 模式运行,可选值(true | false),默认"false&quo ...
- Hibernate每个子类一张表(使用注释)实例
在每个子类一张表的情况下,表是根据持久类创建的,但是它们使用主键和外键来重新定义. 所以关系中不会有重复的列. 我们需要在子类中的使用@PrimaryKeyJoinColumn注释和在父类指定@Inh ...
- Selenium和TestNG
本文档由Felipe Knorr Kuhn撰写,并根据其博客上发布的一系列文章进行改编. 建模您的测试用例 在编写测试用例之前,您需要知道如何验证以及将要验证的内容.让我们使用WordPress “创 ...
- Java自动化测试框架-09 - TestNG之依赖注入篇 (详细教程)
1.-依赖注入 TestNG支持两种不同类型的依赖项注入:本机(由TestNG本身执行)和外部(由诸如Guice的依赖项注入框架执行). 1.1-本机依赖项注入 TestNG允许您在方法中声明其他参数 ...
- go语言注释
Go语言注释实例代码教程 - Go支持C语言风格的/* */块注释,也支持C++风格的//行注释. 当然,行注释更通用,块注释主要用于针对包的详细说明或者屏蔽大块的代码. 每个包都应有一个包注解,即 ...
- PHP经验——PHPDoc PHP注释的标准文档(翻译自Wiki)
文档注释,无非“//”和“/**/”两种 ,自己写代码,就那么点,适当写几句就好了:但是一个人总有融入团队的一天,团队的交流不是那几句注释和一张嘴能解决的,还需要通用的注释标准. PHPDoc是PHP ...
随机推荐
- R3300L运行CoreELEC, EmuELEC和Armbian
R3300L的参数 CPU: S905LRAM: Samsung K4B4G1646E-BCMA 512MB * 2 = 1GBROM: Samsung KLM8G1WEPD-B031 8GB eMM ...
- C#-DllImport 路径问题
原文:C# DllImport 相对路径无法找到dll DllImport DLL查找顺序:1.应用程序所在目录2.Windows目录和Windows\System32目录3.环境变量目录 只需要你把 ...
- java 日志框架 pom配置
使用log4j https://blog.csdn.net/qq_37936542/article/details/80839389[slf4j+logback实现web项目日志输出] 只需引入一个包 ...
- Jmeter+nfluxDB+Grafana性能监控平台
下载地址: nfluxDB下载地址:https://portal.influxdata.com/downloads/ Grafana下载地址:https://grafana.com/grafana/d ...
- 转 python2 与 python3 的编码
原文链接:https://blog.csdn.net/xufive/article/details/102726739 引文如下: 无论是py2还是py3,都使用unicode作为内存编码,简称内码. ...
- APT33追踪思路
APT33组织主要针对石油和航空业,这个组织使用了大约十二个命令与控制服务器(C&C)针对性的对目标攻击.APT33也一直在做定点针对性攻击.比如近两年来,该组织利用一位欧洲高级政治人物(该国 ...
- c#之break和continue的区别
break:跳出循环,执行循环外的语句: continue:跳出此次循环,进入下一次循环:
- centos7安装配置MariaDB10
1:添加 MariaDB yum 仓库 vi /etc/yum.repos.d/MariaDB.repo在该文件中添加以下内容保存: [mariadb] name = MariaDB baseurl ...
- 2019广东外语外贸大学CTF新手赛-密码学-RSA题解
题面 n=100000463700003241 e=17 密文: 分析: 题面已明示是RSA加密,已公开n与公钥e,n为1e18内的数字(64位).要爆破RSA,显然是先分析n的值. n的值是由两个素 ...
- mysql 多个字段的查询处理
https://blog.csdn.net/zzzgd_666/article/details/81101548