Appuim項目實戰---監聽testng

來源:互聯網
上載者:User

標籤:family   fail   group   成功   odi   背景   test   tco   log   

背景:在我們項目中使用testng的會使用到監聽,主要用於在啟動testng前做一些事,還有在對於testng方法運行完了後在做的一些是,我們使用監聽,接上個案例

監聽類繼承TestListenerAdapter,實現以下幾個方法

package until;

import org.testng.ITestContext;

import org.testng.ITestResult;

import org.testng.TestListenerAdapter;

public class TestngListener extends TestListenerAdapter {

    @Override

    public void onTestSuccess(ITestResult tr) {

        super.onTestSuccess(tr);

    }

    @Override

    public void onTestSkipped(ITestResult tr) {

        super.onTestSkipped(tr);

    }

    @Override

    public void onTestStart(ITestResult result) {

        super.onTestStart(result);

        System.out.println("啟動我是onTestStart,我是testng的測試方法");

    }

    @Override

    public void onStart(ITestContext testContext) {

        super.onStart(testContext);

        System.out.println("啟動我是onstart,在test方法前所有初始化都在我這裡做");

    }

    @Override

    public void onTestFailure(ITestResult tr) {

        super.onTestFailure(tr);

        System.out.println("我是onTestFailure,如果案例失敗了我們在進行其他動作");

    }

}

在xml中配置

  1. <?xml version="1.0" encoding="gb2312"?>  
  2. <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">  
  3.     
  4. <suite name="SuiteName" >  
  5.  <listeners>  
  6.         <listener class-name="until.TestngListener" />   
  7.     </listeners>  
  8.     <test name="version" preserve-order="true">  
  9.          <classes>  
  10.               <class name="com.test.appuimtest.rosewholeAPP">  
  11.                 <methods>       
  12.                      <include name="loginWithMicroBlog"/>  
  13.                 </methods>   
  14.             </class>   
  15.          
  16.      </classes>  
  17.     </test>  
  18. </suite>  

列印效果,目前更改了一些日誌顯示,圖片還是以前的,這塊大家可以自己動手查看,在實現的幾個方法裡執行順序如下

  1. 執行testng之前,先執行onStart
  2. 執行testng方法之前,先執行onTestStart
  3. 如果方法執行跳過,就執行onTestSkipped
  4. 如果方法成功,就執行onTestSuccess
  5. 如果方法執行失敗,就執行onTestFailure

Appuim項目實戰---監聽testng

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.