TestNG 测试套件(二)

1、配置类

package com.course.testng.suite;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;

public class SuiteConfig {

    @BeforeSuite
    public void beforeSuite(){
        System.out.println("beforeSuite 已执行");
    }

    @AfterSuite
    public void afterSuite(){
        System.out.println("afterSuite 已执行");
    }

    @BeforeMethod
    public void beforeMethod(){
        System.out.println("beforeMethod 已执行");
    }

    @AfterMethod
    public void afterMethod(){
        System.out.println("afterMethod 已执行");
    }
}

2、业务类一

package com.course.testng.suite;

import org.testng.annotations.Test;

public class LoginTest {

    @Test
    public void login(){
        System.out.println("登录成功...");
    }
}

3、业务类二

package com.course.testng.suite;

import org.testng.annotations.Test;


public class PayTest {

    @Test
    public void pay(){
        System.out.println("支付成功...");
    }
}

4、测试套件配置

<?xml version="1.0" encoding="UTF-8" ?>
<suite name="test">
    <test name="login">
        <classes>
            <class name="com.course.testng.suite.SuiteConfig" />
            <class name="com.course.testng.suite.LoginTest" />
        </classes>
    </test>
    <test name="pay">
        <classes>
            <class name="com.course.testng.suite.SuiteConfig" />
            <class name="com.course.testng.suite.PayTest" />
        </classes>
    </test>
</suite>

这里粗略的看下TestNG的约束文件,有些标签是需要指定的。

<!--

Here is a quick overview of the main parts of this DTD.  For more information,
refer to the <a href="https://testng.org">main web site</a>.
                                                      
A <b>suite</b> is made of <b>tests</b> and <b>parameters</b>.
                                                      
A <b>test</b> is made of three parts:                        

<ul>
<li> <b>parameters</b>, which override the suite parameters     
<li> <b>groups</b>, made of two parts                           
<li> <b>classes</b>, defining which classes are going to be part
  of this test run                                    
</ul>
                                                      
In turn, <b>groups</b> are made of two parts:                
<ul>
<li> Definitions, which allow you to group groups into   
  bigger groups                                       
<li> Runs, which defines the groups that the methods     
  must belong to in order to be run during this test  
</ul>
                                                      
Cedric Beust & Alexandru Popescu                      
@title DTD for TestNG                                    
@root suite

-->

如果需要在xml给出那些标签的提示可以加入如下约束头

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

执行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值