2017-07-19 69 views
1

我試圖執行我的測試腳本,使用testNG並嘗試下面的代碼,但0顯示反對運行,失敗和跳過在控制檯...因爲我無法驗證結果在我的腳本TestNG顯示0測試運行

package com.demoaut.newtours.testcases; 

import org.testng.Assert; 

import org.testng.annotations.Test; 

//import junit.framework.Assert; 

public class TC002_CheckAssert 
{ 

    @Test 
    public TC002_CheckAssert() 
    { 
     System.out.println("ajkcbh"); 
     try 
     { 
      Assert.assertEquals("Pass", "Pass"); 
     } 
     catch(Exception e) 
     { 
      System.out.println("Exception:"+e.getLocalizedMessage()); 
     } 
    } 


} 

我上面的腳本通過的testng.xml文件執行

<suite name="Suite"> 
    <test name="Test"> 
    <classes> 
     <class name="com.demoaut.newtours.testcases.TC002_CheckAssert" /> 
    </classes> 
    </test> 
</suite> 

控制檯resule

ajkcbh

「======================================== ======= 「

套房

總測試運行:0,失敗:0,跳過:0

」 =============== ================================「

+0

你用maven命令運行嗎? – Murthi

+0

沒有。我沒有使用maven。 – Durgesh

+0

你確定你在輸出中看到了'ajkcbh'。這意味着您的測試實際上正在運行。還有一件事,你在哪個IDE中運行這個測試,如果它是** elicpse **,你確定** testng **插件已安裝。 –

回答

4

這是您的問題答案:

你的代碼塊有一個小錯誤。當您在@Test註釋中使用TestNG和書寫方法時,我們應該使用正確的return types來定義方法。我用自己的代碼,只需添加返回類型無效如下:當爲TestNG Test執行

import org.testng.Assert; 
import org.testng.annotations.Test; 

public class Q45191867_Assert_Pass_Suite 
{ 

    @Test 
    public void TC002_CheckAssert() 
    { 
     System.out.println("ajkcbh"); 
     try 
     { 
      Assert.assertEquals("Pass", "Pass"); 
     } 
     catch(Exception e) 
     { 
      System.out.println("Exception:"+e.getLocalizedMessage()); 
     } 
    } 
} 

代碼塊成功執行。

我已經如下執行的代碼塊轉換爲TestNG具有以下testng.xml

<?xml version="1.0" encoding="UTF-8"?> 
 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
 
<suite name="Suite"> 
 
    <test name="Test"> 
 
    <classes> 
 
     <class name="demo.Q45191867_Assert_Pass_Suite"/> 
 
    </classes> 
 
    </test> <!-- Test --> 
 
</suite> <!-- Suite -->

我再次執行該代碼塊作爲TestNG Suite。在這種情況下,以及控制檯上的輸出是:

[TestNG] Running: 
    C:\Users\AtechM_03\LearnAutmation\LearnAutomationTestNG\testng.xml 

ajkcbh 

=============================================== 
Suite 
Total tests run: 1, Failures: 0, Skips: 0 
=============================================== 

讓我知道這個答案是否是您的問題。

+0

是的,我也做了同樣的工作。 – Durgesh