美文网首页
②Eclipse中如何创建TestNG

②Eclipse中如何创建TestNG

作者: by小杰 | 来源:发表于2017-03-03 11:14 被阅读662次
    一、在Eclipse中在线安装TestNG

    在Eclipse中,选择菜单Help ->Install New Software 然后Add
    在Location中输入:http://beust.com/eclipse

    image.png
    点击OK之后,会自动匹配可用的文件 image.png
    二、创建TestNG项目

    选中项目右键 ->Build Path ->Add Library ->TestNG


    image.png
    三、简单实例
    package com.test.testNG;
    import org.testng.annotations.*;
    
    public class SampleTest {
    
        @BeforeClass
        public void beforMethod(){
            
            System.out.println("+++++++++++++++++++");
            
        }
        
        @Test
        public void testMethod(){
            
            System.out.println("*************");
        }
        
        @AfterClass
        public void afterMethod(){
            
            System.out.println("+++++++++++++++++++");
        }
    }```
    运行:
    
    ![image.png](https://img.haomeiwen.com/i1803308/9f60bd0f6eae7579.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    
    #####三、注解描述
    | 注解       |  描述  |
        | --------    | :----: |
     |@BeforeSuite:        |被注释的方法将在所有测试运行前运行|
     |@AfterSuite:        |被注释的方法将在所有测试运行后运行|
     |@BeforeTest:       | 被注释的方法将在测试运行前运行|
     |@AfterTest:        |被注释的方法将在测试运行后运行|
     |@BeforeGroups:      | 被配置的方法将在列表中的gourp前运行。这个方法保证在第一个属于这些组的测试方法调用前立即执行。|
    |@AfterGroups:        |被配置的方法将在列表中的gourp后运行。这个方法保证在最后一个属于这些组的测试方法调用后立即执行。|
    |@BeforeClass:        |被注释的方法将在当前类的第一个测试方法调用前运行。
    |@AfterClass:       | 被注释的方法将在当前类的所有测试方法调用后运行。|
    |@BeforeMethod:        |被注释的方法将在每一个测试方法调用前运行。|
    |@AfterMethod:      |  被注释的方法将在每一个测试方法调用后运行。|
    |@DataProvider   | 标记一个方法用于为测试方法提供数据。|
    |@Factory    |标记方法作为一个返回对象的工厂,这些对象将被TestNG用于作为测试类。这个方法必须返回Object[]|
    |@Parameters    |描述如何传递参数给@Test方法|
    |@Test        |标记一个类或方法作为测试的一部分|
    
    
    

    相关文章

      网友评论

          本文标题:②Eclipse中如何创建TestNG

          本文链接:https://www.haomeiwen.com/subject/gkulgttx.html