有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

未调用java JUnit RunListener

我试图收集系统中运行的测试数据。测试来自外部jar:

        Class<?> classToLoad = Class.forName ("tests.tests", true, child);
        RunListener rl = new ExecutionListener();
        JUnitCore jUnit = new JUnitCore();
        jUnit.addListener(rl);
        Result result = jUnit.runClasses(classToLoad);

而ExecutionListener是:

public class ExecutionListener extends RunListener
{
    private StringBuilder _strBuilder;

    public ExecutionListener() 
    {
        _strBuilder = new StringBuilder(); 
    }

    @Override
    public String toString()
    {
        return _strBuilder.toString();
    }

    /**
     * Called before any tests have been run.
     * */
    @Override
    public void testRunStarted(Description description) throws java.lang.Exception
    {
        _strBuilder.append("Number of testcases to execute : " + description.testCount());
    }

    /**
     *  Called when all tests have finished
     * */
    @Override
    public void testRunFinished(Result result) throws java.lang.Exception
    {
        _strBuilder.append("Number of testcases executed : " + result.getRunCount());
    }

    /**
     *  Called when an atomic test is about to be started.

     * */
    @Override
    public void testStarted(Description description) throws java.lang.Exception
    {
        _strBuilder.append("Starting execution of test case : "+ description.getMethodName());
    }

    /**
     *  Called when an atomic test has finished, whether the test succeeds or fails.
     * */
    @Override
    public void testFinished(Description description) throws java.lang.Exception
    {
        _strBuilder.append("Finished execution of test case : "+ description.getMethodName());
    }

    /**
     *  Called when an atomic test fails.
     * */
    @Override
    public void testFailure(Failure failure) throws java.lang.Exception
    {
        _strBuilder.append("Execution of test case failed : "+ failure.getMessage());
    }

    /**
     *  Called when a test will not be run, generally because a test method is annotated with Ignore.
     * */
    @Override
    public void testIgnored(Description description) throws java.lang.Exception
    {
        _strBuilder.append("Execution of test case ignored : "+ description.getMethodName());
    }
}

但是没有一个函数被调用。。。所以(rl.toString()返回空字符串)

我怎么能修好它

提前谢谢


共 (0) 个答案