junit源码学习--运行测试的过程

本文通过分析junit的TestRunner.java源码,详细解释了如何从main方法开始,解析参数,创建并运行测试类及指定方法的过程,涉及反射、异常处理等关键步骤。
摘要由CSDN通过智能技术生成

找到textui/TestRunner.java,看到了阔别很久的main方法,OK,开始运行测试。

TestRunner.java

/**
  * 运行自身的start方法,并将返回结果提交给容器

  */

public static void main(String args[]) {
  TestRunner aTestRunner= new TestRunner();
  try {
   TestResult r= aTestRunner.start(args);
   if (!r.wasSuccessful())
    System.exit(FAILURE_EXIT);
   System.exit(SUCCESS_EXIT);
  } catch(Exception e) {
   System.err.println(e.getMessage());
   System.exit(EXCEPTION_EXIT);
  }
 }

 

 /**
  * Starts a test run. Analyzes the command line arguments and runs the given
  * test suite.解析传入参数,并根据参数运行对应的方法
  */

public TestResult start(String args[]) throws Exception {
  String testCase= "";
  String method= "";
  boolean wait=

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值