Package bdjunit.textui

Source Code of bdjunit.textui.DVBLogTestRunner

/*
* DVBLogTestRunner.java
*
*/

package bdjunit.textui;

import bdjunit.framework.AssertionFailedError;
import bdjunit.framework.Test;
import bdjunit.framework.TestListener;
import bdjunit.framework.TestResult;
import bdjunit.framework.TestSuite;
import bdjunit.runner.TestRunnerBase;

import java.lang.reflect.*;
import java.awt.*;
import org.dvb.test.DVBTest;


/**
* Test runner for DVBTest.log().
*/
public class DVBLogTestRunner extends TestRunnerBase implements TestListener{

    /** Creates a new instance of DVBLogTestRunner */
    private DVBLogTestRunner() {
       
    }
   
    static public TestResult run(Test test) throws Exception {
        DVBLogTestRunner runner = new DVBLogTestRunner();
        return runner.doRun(test);
    }
   
    static public TestResult run(Test test, Container uiTarget) throws Exception {
        TestRunnerBase.uiTarget = uiTarget;
        DVBLogTestRunner runner = new DVBLogTestRunner();
        return runner.doRun(test);
    }
   
    public TestResult doRun(Test suite) {
        TestResult result= new TestResult();
        //result.addListener(this.testListener);
        result.addListener(this);
        suite.run(result);
        // Tests Result
        StringBuffer fStrBuf = new StringBuffer();
        if (result.failureCount() == 0 && result.errorCount() == 0)
        {   // all tests OK
            fStrBuf.append("OK");
            fStrBuf.append("\n");
            fStrBuf.append("Tests:" + suite.countTestCases());           
            log(fStrBuf.toString());
        }
        else
        {   // report failure and error
            fStrBuf.append("Tests: " + suite.countTestCases() + " ");
            fStrBuf.append("Failures: " + result.failureCount() + " ");
            fStrBuf.append("Errors: " + result.errorCount() + " ");           
            log(fStrBuf.toString());
        }
       
        return result;
    }
   
    static private Test getTest(Class testClass) throws Exception {
        try {
            Method suiteMethod= testClass.getMethod("suite", new Class[0]);
            Test testSuite = (Test) suiteMethod.invoke(null, new Class[0]);
            return testSuite;
        } catch (Exception ex) {
            return new TestSuite(testClass);
        }
       
    }
   
    static private Test getTest(String className) throws Exception {
        return getTest(Class.forName(className));
    }
   
    protected void log(String message) {
        try {
            DVBTest.log("BDJunit Test", message);
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }       
    }
    static public Container getUiTarget() {
        return uiTarget;
    }   
    // interface - TestListener
   
    public void addError(Test test, Throwable t) {
//        StackTraceElement[] stElems = t.getStackTrace();
//        if (stElems.length > 0)
//        {
//            log("Error:" + test.toString() + ":" + t.getMessage() + ":" + stElems[0].toString());
//        }   
    }
   
    public void addFailure(Test test, AssertionFailedError t) {
//        StackTraceElement[] stElems = t.getStackTrace();
//        if (stElems.length > 0)
//        {
//            log("Fail:" + test.toString() + ":" + t.getMessage() + ":" + stElems[0].toString());
//        }   
        //for (int i = 0; i < stElems.length; i++)
        //{
        //    DVBTest.log("Test", "    " + test.toString() + ":" + stElems[i].toString());               
        //}
    }
   
    public void endTest(Test test) {

    }
   
    public void startTest(Test test) {
        log(".");
    }

    //public static void main(String args[]) {
    //    try {
    //        DVBLogTestRunner.run(getTest(args[0]));
    //     } catch(Exception e) {
    //        e.printStackTrace();
    //    }
    //}   
}
TOP

Related Classes of bdjunit.textui.DVBLogTestRunner

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.