List of usage examples for junit.framework Test countTestCases
public abstract int countTestCases();
From source file:org.apache.ofbiz.testtools.ModelTestSuite.java
private void parseTestElement(String caseName, Element testElement) { String nodeName = testElement.getNodeName(); if ("junit-test-suite".equals(nodeName)) { String className = testElement.getAttribute("class-name"); try {/*from w ww . java2 s. c o m*/ @SuppressWarnings("unchecked") Class<? extends TestCase> clz = (Class<? extends TestCase>) ObjectType.loadClass(className); TestSuite suite = new TestSuite(); suite.addTestSuite(clz); Enumeration<?> testEnum = suite.tests(); int testsAdded = 0; int casesAdded = 0; while (testEnum.hasMoreElements()) { Test tst = (Test) testEnum.nextElement(); this.testList.add(tst); casesAdded += tst.countTestCases(); testsAdded++; } Debug.logInfo( "Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module); } catch (Exception e) { String errMsg = "Unable to load test suite class : " + className; Debug.logError(e, errMsg, module); } } else if ("service-test".equals(nodeName)) { this.testList.add(new ServiceTest(caseName, testElement)); } else if ("simple-method-test".equals(nodeName)) { if (UtilValidate.isNotEmpty(testElement.getAttribute("name"))) { this.testList.add(new SimpleMethodTest(caseName, testElement)); } else { String methodLocation = testElement.getAttribute("location"); List<SimpleMethod> simpleMethods; try { simpleMethods = SimpleMethod.getSimpleMethodsList(methodLocation, null); for (SimpleMethod simpleMethod : simpleMethods) { String methodName = simpleMethod.getMethodName(); if (methodName.startsWith("test")) { this.testList.add( new SimpleMethodTest(caseName + "." + methodName, methodLocation, methodName)); } } } catch (MiniLangException e) { Debug.logError(e, module); } } } else if ("webdriver-test".equals(nodeName)) { try { String className = "org.apache.ofbiz.testtools.WebDriverTest"; Class<?> cl; cl = Class.forName(className); Constructor<?> con = cl.getConstructor(String.class, Element.class); this.testList.add((Test) con.newInstance(caseName, testElement)); } catch (Exception e) { Debug.logError(e, module); } } else if ("entity-xml".equals(nodeName)) { this.testList.add(new EntityXmlAssertTest(caseName, testElement)); } else if ("entity-xml-assert".equals(nodeName)) { // this is the old, deprecated name for the element, changed because it now does assert or load this.testList.add(new EntityXmlAssertTest(caseName, testElement)); } }
From source file:org.ofbiz.testtools.ModelTestSuite.java
private void parseTestElement(String caseName, Element testElement) { String nodeName = testElement.getNodeName(); if ("junit-test-suite".equals(nodeName)) { String className = testElement.getAttribute("class-name"); try {// w w w. j av a 2s . c om @SuppressWarnings("unchecked") Class<? extends TestCase> clz = (Class<? extends TestCase>) ObjectType.loadClass(className); TestSuite suite = new TestSuite(); suite.addTestSuite(clz); Enumeration<?> testEnum = suite.tests(); int testsAdded = 0; int casesAdded = 0; while (testEnum.hasMoreElements()) { Test tst = (Test) testEnum.nextElement(); this.testList.add(tst); casesAdded += tst.countTestCases(); testsAdded++; } Debug.logInfo( "Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module); } catch (Exception e) { String errMsg = "Unable to load test suite class : " + className; Debug.logError(e, errMsg, module); } } else if ("service-test".equals(nodeName)) { this.testList.add(new ServiceTest(caseName, testElement)); } else if ("simple-method-test".equals(nodeName)) { if (UtilValidate.isNotEmpty(testElement.getAttribute("name"))) { this.testList.add(new SimpleMethodTest(caseName, testElement)); } else { String methodLocation = testElement.getAttribute("location"); List<SimpleMethod> simpleMethods; try { simpleMethods = SimpleMethod.getSimpleMethodsList(methodLocation, null); for (SimpleMethod simpleMethod : simpleMethods) { String methodName = simpleMethod.getMethodName(); if (methodName.startsWith("test")) { this.testList.add( new SimpleMethodTest(caseName + "." + methodName, methodLocation, methodName)); } } } catch (MiniLangException e) { Debug.logError(e, module); } } } else if ("entity-xml".equals(nodeName)) { this.testList.add(new EntityXmlAssertTest(caseName, testElement)); } else if ("entity-xml-assert".equals(nodeName)) { // this is the old, deprecated name for the element, changed because it now does assert or load this.testList.add(new EntityXmlAssertTest(caseName, testElement)); } }