关于Rule
查看Junit源码,可看到 关于Rule的实现,有
org.junit.rules.TestRule 接口和 org.junit.rules.MethodRule 接口
TestRule
其中 TestRule主要针对一个测试类中的
1.org.junit.Before
2.org.junit.After
3.org.junit.BeforeClass
4.org.junit.AfterClass的相关处理
MethodRule
主要针对测试类的方法进行处理,本篇文章将重点说明这点,它可以支持 APP自动化/或者UI 自动化 等异常或正常执行的数据处理。提高整体代码的简洁及可读性
实例
本篇文章我们的目标是实现,针对Junit测试执行出现的异常,打印出 对应的类名称及方法名称
实现
package com.finger.test.rule;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
/**
* Created by 飞狐 on 2018/2/11.
*/