1 25 package org.ofbiz.base.container; 26 27 import java.util.Enumeration ; 28 import java.util.Iterator ; 29 30 import junit.framework.TestResult; 31 import junit.framework.TestSuite; 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.ObjectType; 34 35 36 42 public class JunitContainer implements Container { 43 44 public static final String module = JunitContainer.class.getName(); 45 protected TestResult results = null; 46 protected String configFile = null; 47 48 51 public void init(String [] args, String configFile) { 52 this.configFile = configFile; 53 } 54 55 public boolean start() throws ContainerException { 56 ContainerConfig.Container jc = ContainerConfig.getContainer("junit-container", configFile); 57 58 Iterator ti = jc.properties.values().iterator(); 60 if (ti == null) { 61 Debug.log("No tests to load", module); 62 return true; 63 } 64 65 TestSuite suite = new TestSuite(); 67 while (ti.hasNext()) { 68 ContainerConfig.Container.Property prop = (ContainerConfig.Container.Property) ti.next(); 69 Class clz = null; 70 try { 71 clz = ObjectType.loadClass(prop.value); 72 suite.addTestSuite(clz); 73 } catch (Exception e) { 74 Debug.logError(e, "Unable to load test suite class : " + prop.value, module); 75 } 76 } 77 78 results = new TestResult(); 80 81 suite.run(results); 83 84 Debug.log("[JUNIT] Pass: " + results.wasSuccessful() + " | # Tests: " + results.runCount() + " | # Failed: " + 86 results.failureCount() + " # Errors: " + results.errorCount(), module); 87 if (Debug.infoOn()) { 88 Debug.log("[JUNIT] ----------------------------- ERRORS ----------------------------- [JUNIT]", module); 89 Enumeration err = results.errors(); 90 if (!err.hasMoreElements()) { 91 Debug.log("None"); 92 } else { 93 while (err.hasMoreElements()) { 94 Debug.log("--> " + err.nextElement(), module); 95 } 96 } 97 Debug.log("[JUNIT] ------------------------------------------------------------------ [JUNIT]", module); 98 Debug.log("[JUNIT] ---------------------------- FAILURES ---------------------------- [JUNIT]", module); 99 Enumeration fail = results.failures(); 100 if (!fail.hasMoreElements()) { 101 Debug.log("None"); 102 } else { 103 while (fail.hasMoreElements()) { 104 Debug.log("--> " + fail.nextElement(), module); 105 } 106 } 107 Debug.log("[JUNIT] ------------------------------------------------------------------ [JUNIT]", module); 108 } 109 110 return true; 111 } 112 113 public void stop() throws ContainerException { 114 try { 115 Thread.sleep(5000); 116 } catch (Exception e) { 117 throw new ContainerException(e); 118 } 119 } 120 } 121 | Popular Tags |