1

タイムアウト例外エラー メッセージをカスタマイズする方法があるかどうかを知りたいです。

私のテストは DataProvider を使用してパラメーター化されているため、どの特定のシナリオが失敗したかを知るために、パラメーターに関する情報をエラー メッセージに含めたいと考えています。

エラーメッセージ

Method org.testng.internal.TestNGMethod.testEndpoint() didn't finish within the time-out 8000

スタックトレース

org.testng.internal.thread.ThreadTimeoutException: Method     
org.testng.internal.TestNGMethod.testEndpoint() didn't finish within the time-out 8000
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
    at sun.security.ssl.InputRecord.read(InputRecord.java:480)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
    at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)
    at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:633)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
4

2 に答える 2

0

インターフェイスITestListenerを実装してリスナー クラスを作成し、onTestFailure() で getThrowable( )を使用して例外を取得できます。

String stackTraceString =      Throwables.getStackTraceAsString(getCurrentTestResult().getThrowable());

同じように、変更されたエラー テキストを使用して setThrowable() を実行できるはずです (自分で確認しませんでした)。

于 2013-12-07T01:44:52.377 に答える
0

TestResult オブジェクトから dataprovider パラメータを取得できます。Vlad が提案したように、ITestListener インターフェイスを実装します。

onTestFailure で、result.getParameters を使用してパラメーターを取得し、getThrowable を使用して例外を取得します。カスタム メッセージで新しい Throwable を作成し、params を追加して、おそらく既存のメッセージを追加し (そのためのコンストラクターがあります)、result.setThrowable を使用してこの Throwable を結果オブジェクトに設定します。

于 2013-12-09T15:06:00.027 に答える