JUnit4.8.2源代码分析-4 RunNotifier与RunListener

本文详细分析了JUnit4.8.2中RunListener和RunNotifier的实现,它们基于观察者模式。RunListener定义了测试运行过程中的7个关键回调接口,而RunNotifier作为通知器,负责在事件发生时调用这些接口。TextListener作为具体的监听器示例,通过PrintStream打印测试结果。RunNotifier虽然充当通知角色,但实际的事件触发不在其本身,设计上采用了二传手式的委派模式。
摘要由CSDN通过智能技术生成

JUnit4执行过程中,org.junit.runner.notification. RunListener和RunNotifier运用了观察者模式

1.观察者

观察者Observer/Listener主要作用是分析各种事件并定义相应的回调接口。例如JDK中MouseListener处理鼠标键相关的5个动作:鼠标键被按下/pressed、释放/released、单击/clicked、光标进入或离开某组件/enters or exits。java.awt.event .MouseListener的源代码:

public interface MouseListener extendsEventListener {

    publicvoid mouseClicked(MouseEvent e);

    publicvoid mousePressed(MouseEvent e);

    publicvoid mouseReleased(MouseEvent e);

    publicvoid mouseEntered(MouseEvent e);

    publicvoid mouseExited(MouseEvent e);

}

那么,RunListener处理测试运行的7个动作

1. publicvoid testRunStarted(Description description)

在所有测试将要运行前的动作。如同运动会比赛前召开开幕式一样。

2. public void testStarted(Description

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值