🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# TestNG 注解教程 > 原文: [https://howtodoinjava.com/testng/testng-annotations-tutorial/](https://howtodoinjava.com/testng/testng-annotations-tutorial/) TestNG 使用注解来帮助开发人员编写测试。 下表是包含有关 TestNG 提供的所有注解的信息及其简要说明的表。 我将在针对其用法的单独教程中详细介绍它们。 ## TestNG 测试配置注解 | 注解 | 描述 | | --- | --- | | [**`@BeforeSuite`**](https://static.javadoc.io/org.testng/testng/6.8.21/org/testng/annotations/BeforeSuite.html "BeforeSuite") | 带注解的方法将在 TestNG 套件内声明的任何测试之前执行。 | | [**`@AfterSuite`**](http://testng.org/javadoc/org/testng/annotations/AfterSuite.html "AfterSuite") | 带注解的方法将在 TestNG 套件内声明的任何测试之后执行。 | | [**`@BeforeTest`**](http://testng.org/javadoc/org/testng/annotations/BeforeTest.html "BeforeTest") | 带注解的方法将在 TestNG 套件中声明的每个测试部分之前执行。 | | [**@AfterTest**](http://testng.org/javadoc/org/testng/annotations/AfterTest.html "AfterTest") | 带注解的方法将在 TestNG 套件中声明的每个测试部分之后执行。 | | [**`@BeforeGroups`**](http://testng.org/javadoc/org/testng/annotations/BeforeGroups.html "BeforeGroups") | 带注解的方法将在执行指定组的任何测试方法之前运行。 | | [**`@AfterGroups`**](http://testng.org/javadoc/org/testng/annotations/AfterGroups.html "AfterGroups") | 带注解的方法将在指定组的任何测试方法执行后运行。 | | [`@BeforeClass`](http://testng.org/javadoc/org/testng/annotations/BeforeClass.html "BeforeClass") | 带注解的方法在测试类的任何测试方法之前执行。 | | [**`@AfterClass`**](http://testng.org/javadoc/org/testng/annotations/AfterClass.html "AfterClass") | 在执行测试类的每个测试方法之后,将执行带注解的方法。 | | [@BeforeMethod](http://testng.org/javadoc/org/testng/annotations/BeforeMethod.html "BeforeMethod") | 这些带注解的方法在每个测试方法执行之前执行。 | | [**`@AfterMethod`**](http://testng.org/javadoc/org/testng/annotations/AfterMethod.html "AfterMethod") | 这些带注解的方法在每个测试方法执行后执行。 | | [**`@DataProvider`**](http://testng.org/javadoc/org/testng/annotations/DataProvider.html "DataProvider") | 将方法标记为测试方法的数据提供方法。 所述方法必须返回对象双数组(`Object[][]`)作为数据。 | | [**`@Factory`**](http://testng.org/javadoc/org/testng/annotations/Factory.html "Factory") | 将带注解的方法标记为返回类对象数组(`Object[]`)的工厂。 然后,这些类对象将被 TestNG 用作测试类。 这用于运行一组具有不同值的测试用例。 | | [**`@Listeners`**](http://testng.org/javadoc/org/testng/annotations/Listeners.html "Listeners") | 应用于测试类。 定义一组扩展`org.testng.ITestNGListener`的测试监听器类。 帮助跟踪执行状态和记录目的。 | | [**`Parameters`**](http://testng.org/javadoc/org/testng/annotations/Parameters.html "Parameters") | 此注解用于将参数传递给测试方法。 这些参数值在运行时使用`testng.xml`配置文件提供。 | | [**`Test`**](https://static.javadoc.io/org.testng/testng/6.8.21/org/testng/annotations/Test.html "Test") | 将类或方法标记为测试方法。 如果在类级别使用,则类的所有公共方法都将被视为测试方法。 | 当您感到困惑时,请参考 **TestNG 注解**的表格。 **祝您学习愉快!**