2017-01-10 29 views
1

請看以下簡單的程序:批處理不捕捉異常在控制檯

package com.temp.practice; 
import org.testng.SkipException; 
import org.testng.annotations.Test; 

@Test 
public class Exp1 
{ 
    public void e1() 
    {  
     System.out.println("Excpetion Test1"); 
     throw new SkipException("e1--- The test cases is not executed"); 
    } 
} 

如果我執行上面的代碼,我收到SkipException在控制檯預期。

enter image description here

但是,當我在三個不同的類別相同類型的代碼,並在一個批處理執行它們,跳過異常沒有在控制檯抓獲。

enter image description here

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="SuiteName" > 
<test name="ITest"> 
<classes> 
<class name="com.temp.practice.Exp1"/> 
</classes> 
</test> <!-- TestB --> 
<test name="StroSearch"> 
<classes> 
<class name="com.temp.practice.Exp2"/> 
</classes> 
</test> <!-- TestB --> 
<test name="full"> 
<classes> 
<class name="com.temp.practice.Exp3"/> 
</classes> 
</test> <!-- TestB --> 
</suite> <!-- SuiteName --> 

可能是什麼原因?

+0

1)您正在使用哪個TestNG版本? 2)'Default test.xml'的內容是什麼(請將其作爲文本提供,而不是圖片)。 – SubOptimal

+0

感謝您的回覆。 1)TestNg版本:6.9.13.201609291640 2)我沒有test.xml。我有一個名爲Testng.xml的文件,腳本(文本和圖像)複製到我的問題中。 –

+0

在控制檯窗口的第一個screeshot中顯示'[Utils]試圖創建... \ Default test.xml'。也許你以不同的方式運行測試。 – SubOptimal

回答

1

問題是你沒有在你的套件xml中指定詳細級別。只有在套件xml中定義了2或更多的冗長時纔打印Stacktraces。所以看蹤跡

  • 變化<suite name="SuiteName" >
  • <suite name="SuiteName" verbose="2"> ,然後再試一次。您應該在控制檯上看到異常堆棧跟蹤。
+0

非常感謝。現在,我在批處理運行期間在控制檯中收到異常。 –

+0

@KannanC你能幫我接受我的答案嗎,如果能解決你的問題 –

+0

當然可以!只是做到了 –