junit3.8源码分析

首先在TestSuite中的 public TestSuite(final Class theClass) {
  fName= theClass.getName();设置断点,在这里设想,这个theClass是junit给我们传过来的,就是我们自己的那个测试类所对应的Class对象,单步执行,会到下面那段代码里面,这里会生成我们的测试类所对应的对象,采用反射的方式

static public Test createTest(Class theClass, String name) {
  Constructor constructor;
  try {
   constructor= getTestConstructor(theClass);
  } catch (NoSuchMethodException e) {
   return warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()");
  }
  Object test;
  try {
   if (constructor.getParameterTypes().length == 0) {
    test= constructor.newInstance(new Object[0]);
    if (test instanceof TestCase)
     ((TestCase) test).setName(name);
   } else {
    test= constructor.newInstance(new Object[]{name});
   }
  } catch (InstantiationException e) {
   return(warning("Cannot instantiate test case: "+name+" ("+exceptionToString(e)+")"));
  } catch (InvocationTargetException e) {
   return(warning("Exception in constructor: "+name+" ("+exceptionToString(e.getTargetException())+")"));
  } catch (IllegalAccessException e) {
   return(warning("Cannot access test case: "+name+" ("+exceptionToString(e)+")"));
  }
  return (Test) test;
 }

当生成对象之后把它们加入到suite里面去,最后才是一个一个的去执行的,才会到TestCase里面的方法中去执行

public void run(TestResult result) {
  result.run(this);
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yjsuge

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值