TestNG中的注解(Annotations)

TestNG中的注解极大的方便了测试用例与测试方法的组织。考虑到平时使用的特别多,所以从官方文档中转载过来,并且考虑到逐步的翻译,以备不时之需。

@BeforeSuite
@AfterSuite
@BeforeTest
@AfterTest
@BeforeGroups
@AfterGroups
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod
Configuration information for a TestNG class:

@BeforeSuite: The annotated method will be run before all tests in this suite have run. 
@AfterSuite: The annotated method will be run after all tests in this suite have run. 
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. 
@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. 
@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. 
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked. 
@AfterClass: The annotated method will be run after all the test methods in the current class have been run. 
@BeforeMethod: The annotated method will be run before each test method. 
@AfterMethod: The annotated method will be run after each test method.

  alwaysRun For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to. 
For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped.
  dependsOnGroups The list of groups this method depends on.
  dependsOnMethods The list of methods this method depends on.
  enabled Whether methods on this class/method are enabled.
  groups The list of groups this class/method belongs to.
  inheritGroups If true, this method will belong to groups specified in the @Test annotation at the class level.
 
@DataProvider Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.
  name The name of this data provider. If it‘s not supplied, the name of this data provider will automatically be set to the name of the method.
  parallel If set to true, tests generated using this data provider are run in parallel. Default value is false.
 
@Factory Marks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[].
 
@Listeners Defines listeners on a test class.
  value An array of classes that extend org.testng.ITestNGListener.
 
@Parameters Describes how to pass parameters to a @Test method.
  value The list of variables used to fill the parameters of this method.
 
@Test Marks a class or a method as part of the test.
  alwaysRun If set to true, this test method will always be run even if it depends on a method that failed.
  dataProvider The name of the data provider for this test method.
  dataProviderClass The class where to look for the data provider. If not specified, the data provider will be looked on the class of the current test method or one of its base classes. If this attribute is specified, the data provider method needs to be static on the specified class.
  dependsOnGroups The list of groups this method depends on.
  dependsOnMethods The list of methods this method depends on.
  description The description for this method.
  enabled Whether methods on this class/method are enabled.
  expectedExceptions The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.
  groups The list of groups this class/method belongs to.
  invocationCount The number of times this method should be invoked.
  invocationTimeOut The maximum number of milliseconds this test should take for the cumulated time of all the invocationcounts. This attribute will be ignored if invocationCount is not specified.
  priority The priority for this test method. Lower priorities will be scheduled first.
  successPercentage The percentage of success expected from this method
  singleThreaded If set to true, all the methods on this test class are guaranteed to run in the same thread, even if the tests are currently being run with parallel="methods". This attribute can only be used at the class level and it will be ignored if used at the method level. Note: this attribute used to be called sequential (now deprecated).
  timeOut The maximum number of milliseconds this test should take.
  threadPoolSize The size of the thread pool for this method. The method will be invoked from multiple threads as specified by invocationCount. 
时间: 2024-10-03 01:57:13

TestNG中的注解(Annotations)的相关文章

TestNG学习-002-annotaton 注解概述及其执行顺序

此文主要讲述用 TestNG 基础的 annotation (注解)知识,及其执行的顺序,并通过一个 TestNG 简单的实例演示 annotation 的执行顺序. 希望能对初学 TestNG 测试框架的亲们有所帮助.若有不足之处,敬请大神指正,不胜感激! 言归正传,以下为 TestNG 常用的 annotation 及其释义,敬请参阅. @BeforeSuite:被此注解的方法将在所有测试运行之前运行该方法. @AfterSuite: 被此注解的方法将在所有测试运行之后运行该方法. @Bef

【java】java中的注解(Annotation)是如何工作的?

Java中的注解是如何工作的? 自Java5.0版本引入注解之后,它就成为了Java平台中非常重要的一部分.开发过程中,我们也时常在应用代码中会看到诸如@Override,@Deprecated这样的注解.这篇文章中,我将向大家讲述到底什么是注解,为什么要引入注解,注解是如何工作的,如何编写自定义的注解(通过例子),什么情况下可以使用注解以及最新注解和ADF(应用开发框架).这会花点儿时间,所以为自己准备一杯咖啡,让我们来进入注解的世界吧. 什么是注解? 用一个词就可以描述注解,那就是元数据,即

Spring Boot中的注解

文章来源:http://www.tuicool.com/articles/bQnMra 在Spring Boot中几乎可以完全弃用xml配置文件,本文的主题是分析常用的注解. Spring最开始是为了解决EJB等大型企业框架对应用程序的侵入性,因此大量依靠配置文件来“非侵入式”得给POJO增加功能,然而,从Spring 3.x开始,Spring被外界最为诟病的一点就是配置繁多,号称“配置地狱”,各种xml文件,出了问题非常难排查.从Spring 4.x开始,Spring.io提供了三种方式编织B

MyBatis中使用注解进行selectKey的查询

1.定义接口类,方法中添加注解查询 package cn.et.mybatis.lesson02.selectKey; import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.SelectKey; public interface KeyAnnoMapper { /* * statement="sel

TestNG中group的用法

TestNG中的组可以从多个类中筛选组属性相同的方法执行. 比如有两个类A和B,A中有1个方法a属于组1,B中有1个方法b也属于组1,那么我们可以通过配置TestNG文件实现把这两个类中都属于1组的方法抽取出来执行. 示例代码 car1 package ngtest; import org.testng.annotations.Test; public class Car1 { @Test(groups={"driver"})//定义该方法属于driver组 public void d

SpringBoot项目中自定义注解的使用

1.定义注解接口 /** * @Package: com.example.config * @Description: 定制一个接口 * @author: zfy * @date: 19/2/23 下午4:20 */ @Documented @Retention(RUNTIME) @Target(METHOD) public @interface MyLog {    String value() default "日志注解"; } [^Documented 注解]: Document

myBatis中的注解@Param、返回值为Map、JAVA读取Excel并解析文本、Class.getResource()和ClassLoader.getResource()

myBatis中的注解@Param:http://blog.csdn.net/gao36951/article/details/44258217:  http://www.cnblogs.com/thomas12112406/p/6217211.html. myBatis返回值为Map:http://blog.csdn.net/werewr342352321df/article/details/11892755. ====================== JAVA读取Excel并解析文本:h

Hibernate中的注解说明

Hibernate中注解注解比较多,常用的也就那么几个,在这里把Hibernate中的注解汇总总结一下. @Entity:将一个类声明为一个实体bean,即一个持久化POJO; @Id:声明bean的标识属性,即和表中的主键对应的属性: @Table:声明bean映射数据库中指定的表: @Column:声明bean的属性到表的列的映射,该注解还有以下属性: name:可选,属性要映射的列明,如果属性名和列名相同则可以省略: unique:可选,是否在该列上设置唯一约束,默认值为false: nu

在Mybatis中使用注解@多个参数查询

@Select("SELECT * FROM wc_homework WHERE organization_id=#{classId} ORDER BY createtime DESC LIMIT #{start},#{count}") @Results({ @Result(column = "course_id", property = "course_id"), @Result(column = "homework_id"