📜  TestNG注释

📅  最后修改于: 2021-01-11 11:57:34             🧑  作者: Mango

什么是TestNG注释?

TestNG注释是一段代码,它被插入程序或业务逻辑内部,用于控制测试方法的执行流程。

TestNG注释列表

TestNG Annotation Description
@BeforeSuite The @BeforeSuite annotated method will run before the execution of all the test methods in the suite.
@AfterSuite The @AfterSuite annotated method will run after the execution of all the test methods in the suite.
@BeforeTest The @BeforeTest annotated method will be executed before the execution of all the test methods of available classes belonging to that folder.
@AfterTest The @AfterTest annotated method will be executed after the execution of all the test methods of available classes belonging to that folder.
@BeforeClass The @BeforeClass annotated method will be executed before the first method of the current class is invoked.
@AfterClass The @AfterClass annotated method will be invoked after the execution of all the test methods of the current class.
@BeforeMethod The @BeforeMethod annotated method will be executed before each test method will run.
@AfterMethod The @AfterMethod annotated method will run after the execution of each test method.
@BeforeGroups The @BeforeGroups annotated method run only once for a group before the execution of all test cases belonging to that group.
@AfterGroups The @AfterGroups annotated method run only once for a group after the execution of all test cases belonging to that group.

TestNG注释的层次结构:

  • @BeforeSuite
  • @BeforeTest
  • @课前
  • @BeforeMethod
  • @测试
  • @AfterMethod
  • @下课以后
  • @AfterTest
  • @AfterSuite

使用TestNG注释的好处:

  • TestNG注释使测试人员的工作变得非常轻松。根据您的要求,您可以访问测试方法,即它没有预定义的模式或格式。
  • 您可以将其他参数传递给TestNG批注。
  • 如果是TestNG批注,则无需扩展任何测试类。
  • TestNG注释是强类型的,即在编译时检测到错误。