1--Test NG--常见测试和注解
第一:注解
(1)@test
(2)@BeforeMethod,@AfterMethod
(3)@BeforeClass,@AfterClass
(4)@BeforeSuite,@AfterSuite
第二:套件测试
(1) SuiteConfig:公共方法
public class SuiteConfig{
@BeforeSuite
public void beforesuit(){
system.out.println("beforesuit 运行啦");
}
@AfterSuite
public void aftersuit(){
system.out.println("aftersuit 运行啦");
}
}
(2) LoginTest:
public class LoginTest{
@Test
public void logintaobao(){
system.out.println("login taobao");
}
}
(3) PayTest
public class PayTest{
@Test
public void paysuccess(){
system.out.println("zhifubao success");
}
}
(4) resource:Testng.xml(名字随意)
<?xml version="1.0" encoding="UTF-8" ?>
<suite name="test">
<test name ="login">
<classes>
<class name="com.curse.testng.suite.suiteconfig"/>
<class name="com.curse.testng.suite.LoginTest"/>
</classes>
</test>
<test name ="pay">
<classes>
<class name="com.curse.testng.suite.suiteconfig"/>
<class name="com.curse.testng.suite.PayTest"/>
</classes>
</test>
</suite>
右键执行testng.xml,结果如下:
beforesuit 运行啦
login taobao
zhifubao success
aftersuit 运行啦
如果在suiteconfig文件中增加beforetest和aftertest,执行结果为:
beforesuit 运行啦
beforetest
login taobao
aftertest
beforetest
zhifubao success
aftertest
aftersuit 运行啦
第三:忽略测试
@test(enabled=false)
第四:分组测试
(1)group在方法上
public class groupsonMethod{
@test(groups="server")
public void test1(){
system.out.println("test1");
}
@test(groups="server")
public void test2(){
system.out.println("test2");
}
@test(groups="client")
public void test3(){
system.out.println("test3");
}
@beforegroups("server")
public void beforegroupsonserver(){
system.out.println("beforeservergroups");
}
@aftergroups("server")
public void aftergroupsonserver(){
system.out.println("afterservergroups");
}
}
运行结果:
beforeservergroups
test1
test2
afterservergroups
test3
(2)groups在类上
@test(groups="stu")
public class groupsonclass1{
}
testng.xml:
<test name="onlyrunstu">
<groups>
<run>
<include name="stu"/>
</run>
</groups>
</test>
第五:异常测试
第六:依赖测试
public class DpendTest{
@test
public void test1(){
system.out.println("test1");
throw new RuntimeException();//打印要写在异常前面,因为抛出异常后,后边的代码都不执行
}
@test(dependsOnMethods={"test1"})
public void test2(){
system.out.println("test2");
}
}
结果:test1
test1执行,test2被忽略了,因为test2的依赖测试test1抛出了异常,执行失败了
第七: 超时测试
public class TimeOutTest{
@test(timeout=3000)//单位为ms
public void testsuccess(){
Thread.sleep(millis:2000);
system.out.println("test1");
}
@test(timeout=2000)//单位为ms
public void testfailed(){
Thread.sleep(millis:3000);
system.out.println("test1");
}
}
1--Test NG--常见测试和注解的更多相关文章
- 使用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- 用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- maven解析xml+测试test+注解
条件:maven项目 测试图: 创建maven项目,在maven项目中scr目录下有main.test(没有就创建) 一.解析XML文件方式 在main目录下有java.resources.webap ...
- spring + myBatis 常见错误:注解事务不回滚
最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...
- web端常见测试
一.登录注册功能 1.页面调转 2.tab键与enter键 3.密码加密显示,是否支持复制粘贴 4.账号密码校验 5.刷新页面,更新验证码 二.界面测试 1.样式.颜色.整体布局风格 2.最大化.最小 ...
- mac使用brew安装配置常见测试工具
Homebrew 包管理工具可以让你安装和更新程序变得更方便,目前在 OS X 系统中最受欢迎的包管理工具是 Homebrew. 安装 在安装 Homebrew 之前,需要将 Xcode Comman ...
- Spring整合JUnit4测试使用注解引入多个配置文件
转自:https://kanpiaoxue.iteye.com/blog/2151903 我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个.我们在类的注释上面会这 ...
- java 日志脱敏框架 sensitive-v0.0.4 系统内置常见注解,支持自定义注解
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 特性 基于注解的日志脱敏. 可 ...
- Java日志脱敏框架 sensitive-v0.0.4 系统内置常见注解,支持自定义注解
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 特性 基于注解的日志脱敏. 可 ...
随机推荐
- 判断PDF文件是否相同(通过二进制流判断)
一.Java代码 1.将PDF转为字节流 /* * @step * 1.使用BufferedInputStream和FileInputStream从File指定的文件中读取内容 ...
- nigix反向代理
参考: https://www.cnblogs.com/yycc/p/8185748.html
- redis 集群引出hash一致性算法
写的很棒的文章 https://blog.csdn.net/bntX2jSQfEHy7/article/details/79549368 这篇分析的更叼 https://www.jianshu.com ...
- 关于mfc学习小记(bug小记)
关于控件问题 基本上出错的都是类型不为LPCTSTR 解决方式: 1.字符串转换 _T(str) 例:_T("你说的都对") 关于button控件 按照老旧的方式为其关联函数中添加 ...
- 10、Typescript-类的基本用法
类就是构造函数的另一写法 以前构造函数的写法: 类的基本用法:
- 2-Reverse Integer(简单)
Description: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Outp ...
- go ethereum源码分析 PartIV Transaction相关
核心数据结构: core.types.transaction.go type Transaction struct { data txdata // caches hash atomic.Value ...
- 面向对象DAO模式
DAO模式编写数据访问层代码步骤? 1. 接口 增.删.改.查的方法 方法的返回类型为泛型集合 Int rows=select语句的条数 If(rows>0) 方法的返回类型为泛型集合 If( ...
- python dict to dataframe
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_dict.html Examples By de ...
- 修改create-react-app支持多入口
使用Facebook官方脚手架create-react-app创建React应用,默认只能生成一个SPA,入口是index.html.虽然,SPA的页面切换可以使用前台路由框架方便(比如React-R ...