2013-11-22 66 views
0

我有一個擴展了RunListener的類。RunListener結果方法

我想知道方法的結果。 因此這種方法:

public void testFinished(Description description) throws java.lang.Exception { 
    System.out.println("Finished execution of test case : " + description.getMethodName()); 
} 

我想是這樣的:description.getResult(),但它並不existe。 我該如何製作?

謝謝。

回答

0

無論使用哪種方法,都取決於Description對象。如果你想/需要getResult(),你將不得不在Description類中實現該方法並將其公開化。

例子:

這是你需要在你的Description類來實現方法的一個例子。

public Object getResult() { 
    // this is the method you need to implement, with whatever return type you need instead of Object (String etc.) 
    return result; 
} 
+0

好的,但是我有一個問題重新定義的構造: \t公共MyDescription(類 fTestClass,字符串fDisplayName,註釋fAnnotations){ \t \t超級(fTestClass,fDisplayName,fAnnotations); \t} 有一個信息: >構造描述(類,字符串,註釋...)是不可見的 你確定你的解決方案是正確的? – user2998243

+0

你不需要重新定義構造函數,這只是一個例子。只需要實現'getResult()'方法和其他變量/方法。 – Blacklight