zoukankan      html  css  js  c++  java
  • JUnit 单元测试方法中启用子线程的问题

     其实junit是将test作为参数传递给了TestRunner的main函数。并通过main函数进行执行。

    test函数在main中执行。如果test执行结束,那么main将会调用System.exit(0);即使还有其他的线程在运行,main也会调用System.exit(0);

    System.exit()是系统调用,通知系统立即结束jvm的运行,即使jvm中有线程在运行,jvm也会停止的。所以会出现之前的那种情况。其中System.exit(0);的参数如果是0,表示系统正常退出,如果是非0,表示系统异常退出。

    TestRunner 类的 main 方法:

        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);
            }
        }
  • 相关阅读:
    mac 使用tree命令
    为什么redis支持lua脚本功能
    redis协议
    Linux的SOCKET编程详解
    大型网站架构之分布式消息队列
    自定义String
    逆转单链表
    单例模式 C++
    构造函数不能为虚函数
    Windows消息机制
  • 原文地址:https://www.cnblogs.com/frankyou/p/14849513.html
Copyright © 2011-2022 走看看