Java RunListener结果方法
我有一个扩展RunListener的类 我想知道这个方法的结果。 因此,在这种方法中:Java RunListener结果方法,java,junit,Java,Junit,我有一个扩展RunListener的类 我想知道这个方法的结果。 因此,在这种方法中: public void testFinished(Description description) throws java.lang.Exception { System.out.println("Finished execution of test case : " + description.getMethodName()); } 我想要的是:description.getResult(),但它
public void testFinished(Description description) throws java.lang.Exception {
System.out.println("Finished execution of test case : " + description.getMethodName());
}
我想要的是:description.getResult(),但它不存在。
我该怎么做
谢谢。您可以使用的任何方法都取决于
说明
对象。如果您想要/需要getResult()
,则必须在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;
}
好的,但是我在重新定义构造函数时遇到了一个问题:public MyDescription(类fTestClass,字符串fDisplayName,注释fAnnotations){super(fTestClass,fDisplayName,fAnnotations);}有一条消息:>构造函数描述(类,字符串,注释…)不可见您确定您的解决方案是正确的吗?您不需要重新定义构造函数,这只是一个示例。仅实现
getResult()
方法,以及仅在需要时实现其他变量/方法。