basetestrunner.java

来自「junit中的软件设计模式 源代码,看了挺有收获的」· Java 代码 · 共 49 行

JAVA
49
字号
package junit.textui;

import junit.framework.*;
import java.lang.reflect.*;
import java.text.NumberFormat;
import java.io.*;
import java.util.*;

/**
 * Base class for all test runners.
 * This class was born live on stage in Sardinia during XP2000.
 */
public abstract class BaseTestRunner{
	public static final String SUITE_METHODNAME= "suite";

    /**
     * Returns the Test corresponding to the given suite. This is
     * a template method, subclasses override runFailed(), clearStatus().
     */
    public Test getTest(String suiteClassName) {
        if (suiteClassName.length() <= 0) {
            return null;
        }
        Class testClass= null;
        try {
            testClass= Class.forName(suiteClassName);
        } catch(Exception e) {
            return null;
        }
        Method suiteMethod= null;
        try {
            suiteMethod= testClass.getMethod(SUITE_METHODNAME, new Class[0]);
         } catch(Exception e) {
             // try to extract a test suite automatically
            return new TestSuite(testClass);
        }
        Test test= null;
        try {
            test= (Test)suiteMethod.invoke(null, new Class[0]); // static method
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return test;
    }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?