问题描述
我有很多测试课程。我想添加一个监听器来处理onFailure,onFinished等。我的解决方案是创建一个自定义运行器并重写run方法以添加监听器:
class Customrunner(klass: Class<*>?) : BlockJUnit4ClassRunner(klass) {
override fun run(notifier: RunNotifier) {
notifier.addListener(JUnitExecutionListener())
notifier.fireTestRunStarted(description)
super.run(notifier)
}
}
但是,我的测试类不仅使用BlockJUnit4ClassRunner,而且某些测试类使用powermockrunner,MockitoJUnitRunner等。因此,我必须创建多个自定义运行器类来扩展每个运行器(powermockrunner,MockitoJUnitRunner等)。 。)仅添加侦听器?
有没有一种方法可以直接注入侦听器而无需创建多个自定义运行器?
我希望这样:
@CustomListener
@RunWith(powermockrunner::class)
class UtilTest {
}
因此,通过添加@CustomListener,是否可以将侦听器“注入”到运行程序,而不必替换@RunWith()内的所有运行程序?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)