三、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 ...
随机推荐
- jq判断input 复选框有没有选
选中了返回true ,没选中返回false$("input[type='checkbox']").is(':checked'):
- python-基础入门-2
这里介绍两个,相当于c中的scanf函数 第一个raw_input 1 age=raw_input("how old are you ") 2 print "you ar ...
- FL Studio乐理教程之添加和弦
和弦是指有一定音程关系的一组声音,即将三个或以上的音,按照三度或非三度的叠置关系,在纵向上加以结合,就称为和弦. FL Studio可以编辑和弦吗?当然可以!首先我们使用FL Stuido20钢琴卷帘 ...
- FL studio系列教程(一):什么是FL水果音乐制作软件
如今,越来越多的音乐人选择使用音乐制作软件来进行音乐的创作,一台电脑.一款软件以及一个外接MIDI就是一个小型的音乐工作站.FL Studio成了音乐界萌新的首选,目前最新的版本为FL Studio2 ...
- Boom 3D带你聆听《我们的乐队》音乐盛宴
说到前段时间大热的音乐类综艺节目,<我们的乐队>肯定值得一提.<我们的乐队>是由谢霆锋.萧敬腾.王俊凯担任导师,以团队的形式组成各种风格的乐队,并通过同场比拼,最终选出获胜的乐 ...
- vulnhub: DC 9
信息收集: root@kali:/opt/test# nmap -A -v 192.168.76.137 Starting Nmap 7.80 ( https://nmap.org ) at 2020 ...
- pytest的setup和teardown
学过unittest的setup和teardown,前置和后置执行功能.pytest也有此功能并且功能更强大,今天就来学习一下吧. 用例运行级别: 模块级(setup_module/teardown_ ...
- 安装Linux软件时遇到这个问题,如何解决?
提示 Could not get lock /var/lib/dpkg/lock 报错? 有些小伙伴在使用 apt 包管理器更新或安装软件时,可能会遇到过诸如以下的错误提示: E: Could not ...
- Python超全干货:【二叉树】基础知识大全
概念 二叉树是每个节点最多有两个子树的树结构.通常子树被称作"左子树"(left subtree)和"右子树"(right subtree) 二叉树的链式存储: ...
- 痞子衡嵌入式:深入i.MXRT1050系列ROM中串行NOR Flash启动初始化流程
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是深入i.MXRT1050系列ROM中串行NOR Flash启动初始化流程. 从外部串行NOR Flash启动问题是i.MXRT系列开发最 ...