Eclipse 安装TestNG

安装TestNG
1、帮助 - install new software
Eclipse 安装TestNG
2、在work with输入框的右边,点击add,弹出弹窗,在name中输入“TestNG",在Location中输入“http://beust.com/eclipse”, 点击add按钮Eclipse 安装TestNG
3、勾选TestNG,点击next,同意协议,重启eclipse

创建testng的class
1、在工程上右键 底部有个“TestNG”
Eclipse 安装TestNG
或者:工程上右键 new -other -testng
Eclipse 安装TestNG

2、勾选annotations前2排,且在xml suit file中输入 testng.xml(可以随意命名)
Eclipse 安装TestNG

注解:(来自易白的介绍:https://www.yiibai.com/testng/configuration-annotations.html)
@BeforeSuite - 对于套件测试,在此套件中的所有测试运行之前运行。
@AfterSuite - 对于套件测试,在此套件中的所有测试运行之后运行。
@BeforeTest - 对于套件测试,在运行属于标签内的类的任何测试方法之前运行。
@AfterTest - 对于套件测试,在运行属于标签内的类的所有测试方法都已运行之后运行。@BeforeGroups:在调用属于该组的第一个测试方法之前运行。
@AfterGroups:在调用属于组的最后一个测试方法之后运行。
@BeforeClass- 在当前类的第一个测试方法之前运行。
@AfterClass - 运行当前类中的所有测试方法之后都运行。
@BeforeMethod - 在每个测试方法之前运行。
@AfterMethod - 在每个测试方法之后运行。

3、新建完成后,会生成一个testng.xml的文件
4、在testng.xml文件上右键->run as->Testng Suite,即可执行class标签里写的测试类

<?xml version="1.0" encoding="UTF-8"?>
<suite parallel="false" name="Suite">
  <test name="Test">
    <classes>
      <class name="com.testcases.NewTest1"/> //可以写多个class
      <class name="com.testcases.NewTest2"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->