三、TestNG的基本注解(1)
Before类别和After类别注解
举例说明
创建两个TestNGAnnotationTest.java和TestNGAnnotationTest2.java的类
TestNGAnnotationTest.java
package com.lc.testngTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; public class TestNGAnnotationTest { @BeforeSuite
public void beforeSuite() { System.out.println(this.getClass().getName() + " beforeSuite"); } @AfterSuite
public void afterSuite() { System.out.println(this.getClass().getName() + " afterSuite"); } @BeforeTest
public void beforeTest() { System.out.println(this.getClass().getName() + " beforeTest"); } @AfterTest
public void afterTest() { System.out.println(this.getClass().getName() + " afterTest"); } @BeforeClass
public void beforeClass() { System.out.println(this.getClass().getName() + " beforeClass"); } @AfterClass
public void afterClass() { System.out.println(this.getClass().getName() + " afterClass"); } @BeforeMethod
public void beofreMethod() { System.out.println(this.getClass().getName() + " beforeMethod"); } @AfterMethod
public void afterMethod() { System.out.println(this.getClass().getName() + " afterMethod"); } @Test
public void test1() { System.out.println(this.getClass().getName() + " test1"); } @Test
public void test2() { System.out.println(this.getClass().getName() + " test2"); } }
TestNGAnnotationTest2.java
package com.lc.testngTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; public class TestNGAnnotationTest2 { @BeforeSuite
public void beforeSuite() { System.out.println(this.getClass().getName() + " beforeSuite"); } @AfterSuite
public void afterSuite() { System.out.println(this.getClass().getName() + " afterSuite"); } @BeforeTest
public void beforeTest() { System.out.println(this.getClass().getName() + " beforeTest"); } @AfterTest
public void afterTest() { System.out.println(this.getClass().getName() + " afterTest"); } @BeforeClass
public void beforeClass() { System.out.println(this.getClass().getName() + " beforeClass"); } @AfterClass
public void afterClass() { System.out.println(this.getClass().getName() + " afterClass"); } @BeforeMethod
public void beofreMethod() { System.out.println(this.getClass().getName() + " beforeMethod"); } @AfterMethod
public void afterMethod() { System.out.println(this.getClass().getName() + " afterMethod"); } @Test
public void test1() { System.out.println(this.getClass().getName() + " test1"); } @Test
public void test2() { System.out.println(this.getClass().getName() + " test2"); } }
创建运行项目的xml文件
testng2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="suite1" verbose="1" >
<test name="test1">
<classes>
<class name="com.lc.testngTest.TestNGAnnotationTest"></class>
<class name="com.lc.testngTest.TestNGAnnotationTest2"></class>
</classes>
</test> </suite>
运行结果
[TestNG] Running:
D:\workspace\webTestNG\WebContent\testng2.xml com.lc.testngTest.TestNGAnnotationTest beforeSuite
com.lc.testngTest.TestNGAnnotationTest2 beforeSuite
com.lc.testngTest.TestNGAnnotationTest beforeTest
com.lc.testngTest.TestNGAnnotationTest2 beforeTest
com.lc.testngTest.TestNGAnnotationTest beforeClass
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test1
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test2
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest afterClass
com.lc.testngTest.TestNGAnnotationTest2 beforeClass
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test1
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test2
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 afterClass
com.lc.testngTest.TestNGAnnotationTest afterTest
com.lc.testngTest.TestNGAnnotationTest2 afterTest
com.lc.testngTest.TestNGAnnotationTest afterSuite
com.lc.testngTest.TestNGAnnotationTest2 afterSuite ===============================================
suite1
Total tests run: 4, Failures: 0, Skips: 0
===============================================
其中beforeSuite,afterSuite和beforeTest,afterTest区分不明显,下面修改xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="suite1" verbose="1" >
<test name="test1">
<classes>
<class name="com
[TestNG] Running:
D:\workspace\webTestNG\WebContent\testng.xml com.lc.testngTest.TestNGAnnotationTest beforeSuite
com.lc.testngTest.TestNGAnnotationTest2 beforeSuite
com.lc.testngTest.TestNGAnnotationTest beforeTest
com.lc.testngTest.TestNGAnnotationTest beforeClass
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test1
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test2
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest afterClass
com.lc.testngTest.TestNGAnnotationTest afterTest
com.lc.testngTest.TestNGAnnotationTest2 beforeTest
com.lc.testngTest.TestNGAnnotationTest2 beforeClass
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test1
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test2
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 afterClass
com.lc.testngTest.TestNGAnnotationTest2 afterTest
com.lc.testngTest.TestNGAnnotationTest afterSuite
com.lc.testngTest.TestNGAnnotationTest2 afterSuite ===============================================
suite1
Total tests run: 4, Failures: 0, Skips: 0
===============================================
.lc.testngTest.TestNGAnnotationTest"></class>
</classes>
</test> <test name="test2">
<classes>
<class name="com.lc.testngTest.TestNGAnnotationTest2"></class>
</classes>
</test>
</suite>
运行结果
三、TestNG的基本注解(1)的更多相关文章
- TestNG学习-002-annotaton 注解概述及其执行顺序
此文主要讲述用 TestNG 基础的 annotation (注解)知识,及其执行的顺序,并通过一个 TestNG 简单的实例演示 annotation 的执行顺序. 希望能对初学 TestNG 测试 ...
- asp.net mvc3 数据验证(三)—自定义数据注解
原文:asp.net mvc3 数据验证(三)-自定义数据注解 前两节讲的都是asp.net mvc3预先设定的数据注解,但是系统自由的数据注解肯定不适合所有的场合,所以有时候我们需要 ...
- DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描
DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之Spr ...
- Spring Boot入门(三):使用Scheduled注解实现定时任务
在程序开发的过程中,经常会使用定时任务来实现一些功能,比如: 系统依赖于外部系统的非核心数据,可以定时同步 系统内部一些非核心数据的统计计算,可以定时计算 系统内部的一些接口,需要间隔几分钟或者几秒执 ...
- Android AOP之路三 Android上的注解
一.简单介绍 啥是注解.不懂的能够先看我上一篇文章. 在android 里面 注解主要用来干这么几件事: 和编译器一起给你一些提示警告信息. 配合一些ide 能够更加方便快捷 安全有效的编写java代 ...
- testng 的常用注解
常用注解如下: @BeforeSuite: 此注解的方法会在当前测试集合中的任一测试用例前执行 @AfterSuite: 此注解的方法会在当前测试集合中的所有测试程序结束后执行 @BeforeTest ...
- TestNG的常用注解
@BeforeSuite:表示此注解的方法会在当前测试集合(Suite)中的任一测试用例开始运行之前执行 @AfterSuite:表示此注解的方法会在当前测试集合(Suite)中的所有测试程序运行结束 ...
- spring boot: Bean的初始化和销毁 (一般注入说明(三) AnnotationConfigApplicationContext容器 JSR250注解)
import org.springframework.context.annotation.AnnotationConfigApplicationContext; 使用AnnotationConfig ...
- 关于整合spring+mybatis 第三种方式-使用注解
使用注解 1.与前两种方法一致.不过稍许不同的是beans.xml中配置的差异. <!-- 配置sqlSessionFactory --> <bean id="sqlSes ...
随机推荐
- Zookeeper集群搭建(多节点,单机伪集群,Docker集群)
Zookeeper介绍 原理简介 ZooKeeper是一个分布式的.开源的分布式应用程序协调服务.它公开了一组简单的原语,分布式应用程序可以在此基础上实现更高级别的同步.配置维护.组和命名服务.它的设 ...
- ABBYY FineReader 15 新增编辑表格单元格功能
ABBYY FineReader 15(Windows系统)新增编辑表格单元格功能,在PDF文档存在表格的前提下,可将表中的每个单元格作为单独的文字块进行单独编辑,单元格内的编辑不会影响同一行中其他单 ...
- Vegas干货分享,如何制作霓虹灯效果
在各色各样的展会中,各种炫彩华丽的灯光和光影一直都能吸引到人们大量的关注.同样,在视频制作中,光线的气氛渲染也是常用的方法,常用也就代表着效果明显,也是很多刚学视频剪辑小伙伴们想要学习的一种方法. 今 ...
- 对于this和当前线程的一些理解
在学习这个InheritableThreadLocal类的时候,我对于有个地方一直没有理解,我发现了盲点. 1 private void init(ThreadGroup g, Runnable ta ...
- Codeforces Round #660 (Div. 2) A、B、C题解
A. Captain Flint and Crew Recruitment #构造 题目链接 题意 定义一类正整数,能够被\(p*q\)表示,其中\(p.q(1<p<q)\)均为素数,称之 ...
- Mybatis【1】-- 第一个Mybatis程序
1.框架是什么 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互的方法;另一种定义认为,框架是可被应用开发者定制的应用骨架.前者是从应用方面而后者是从目的方面 ...
- Spring中的Mybatis
1. 前言 在构建一个web应用时基本的套路就是SSM,其中的M就是Mybatis. Mybatis作为一款开源的ORM框架, 由于其易于上手的特点成为当下比较流行的ORM框架,当然它还有一款插件能够 ...
- Python MoviePy中文教程导览及可执行音视频剪辑工具下载
☞ ░ 前往老猿Python博文目录 ░ <Python音视频剪辑库MoviePy1.0.3中文教程导览及可执行工具下载>是老猿两个关于moviepy的专栏<PyQt+moviepy ...
- moviepy音视频剪辑:headblur的参数r_blur卷积核以及fx、fy、r_zone的功能作用及用途
☞ ░ 前往老猿Python博文目录 ░ 在moviepy1.03版本中,headblur的调用语法为:headblurbak(clip,fx,fy,r_zone,r_blur=None) 其中参数f ...
- PyQt(Python+Qt)学习随笔:Qt Designer中Action创建的方法
在Qt Designer中,可以两种方法创建Action对象,一种是菜单定义时,一种是单独定义. 一.定义菜单创建Action 在Qt Designer中创建菜单时,如果对应菜单是最终执行的菜单项,则 ...