/** * JUnit 3.7 introduces TestCase.getName() and subsequent versions of JUnit remove the old name() * method. This method provides access to the name of a TestCase via reflection that is supposed * to work with version before and after JUnit 3.7. * * <p>since Ant 1.5.1 this method will invoke "<code>public * String getName()</code>" on any implementation of Test if it exists. * * <p>Since Ant 1.7 also checks for JUnit4TestCaseFacade explicitly. This is used by * junit.framework.JUnit4TestAdapter. * * @param t the test. * @return the name of the test. */ public static String getTestCaseName(Test t) { if (t != null && t.getClass().getName().equals("junit.framework.JUnit4TestCaseFacade")) { // Self-describing as of JUnit 4 (#38811). But trim "(ClassName)". String name = t.toString(); if (name.endsWith(")")) { int paren = name.lastIndexOf('('); return name.substring(0, paren); } else { return name; } } if (t instanceof TestCase && testCaseName != null) { try { return (String) testCaseName.invoke(t, new Object[0]); } catch (Throwable e) { // ignore } } else { try { Method getNameMethod = null; try { getNameMethod = t.getClass().getMethod("getName", new Class[0]); } catch (NoSuchMethodException e) { getNameMethod = t.getClass().getMethod("name", new Class[0]); } if (getNameMethod != null && getNameMethod.getReturnType() == String.class) { return (String) getNameMethod.invoke(t, new Object[0]); } } catch (Throwable e) { // ignore } } return "unknown"; }
@Override public void startTest(Test test) { try { if (test instanceof TestCase) { TestCase testCase = TestCase.class.cast(test); if (currentTestCase == null || testCase.getClass() != currentTestCase.getClass()) { // If this is the first test or different test case class is passed, // close last <testsuite> and start new <testsuite>. if (currentTestCase != null) { // <testsuite> has been started already so close it. serializer.endTag(NS_DEFAULT, TAG_TESTSUITE); } serializer.startTag(NS_DEFAULT, TAG_TESTSUITE); serializer.attribute(NS_DEFAULT, ATTR_NAME, testCase.getClass().getName()); } serializer.startTag(NS_DEFAULT, TAG_TESTCASE); serializer.attribute(NS_DEFAULT, ATTR_NAME, testCase.getName()); currentTestCase = testCase; testCaseStartTime = System.currentTimeMillis(); isTimeAppended = false; } else { MozcLog.e("Unextected type; " + test.getClass().getCanonicalName()); } } catch (IOException e) { MozcLog.e(e.getMessage(), e); } }
/** * Interface TestListener. * * <p>A Test is finished. */ public void endTest(Test test) { // Fix for bug #5637 - if a junit.extensions.TestSetup is // used and throws an exception during setUp then startTest // would never have been called if (!testStarts.containsKey(test)) { startTest(test); } Element currentTest = null; if (!failedTests.containsKey(test)) { currentTest = doc.createElement(TESTCASE); currentTest.setAttribute(ATTR_NAME, JUnitVersionHelper.getTestCaseName(test)); // a TestSuite can contain Tests from multiple classes, // even tests with the same name - disambiguate them. currentTest.setAttribute(ATTR_CLASSNAME, test.getClass().getName()); rootElement.appendChild(currentTest); testElements.put(test, currentTest); } else { currentTest = (Element) testElements.get(test); } Long l = (Long) testStarts.get(test); currentTest.setAttribute( ATTR_TIME, "" + ((System.currentTimeMillis() - l.longValue()) / 1000.0)); }
private static Description makeDescription(Test test) { if (test instanceof TestCase) { TestCase tc = (TestCase) test; return Description.createTestDescription(tc.getClass(), tc.getName(), getAnnotations(tc)); } else if (test instanceof TestSuite) { TestSuite ts = (TestSuite) test; String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName(); Description description = Description.createSuiteDescription(name); int n = ts.testCount(); for (int i = 0; i < n; i++) { Description made = makeDescription(ts.testAt(i)); description.addChild(made); } return description; } else if (test instanceof Describable) { Describable adapter = (Describable) test; return adapter.getDescription(); } else if (test instanceof TestDecorator) { TestDecorator decorator = (TestDecorator) test; return makeDescription(decorator.getTest()); } else { // This is the best we can do in this case return Description.createSuiteDescription(test.getClass()); } }
/* 109: */ /* 110: */ private static Description makeDescription(Test test) /* 111: */ { /* 112: 96 */ if ((test instanceof TestCase)) /* 113: */ { /* 114: 97 */ TestCase tc = (TestCase) test; /* 115: 98 */ return Description.createTestDescription(tc.getClass(), tc.getName()); /* 116: */ } /* 117: 99 */ if ((test instanceof TestSuite)) /* 118: */ { /* 119:100 */ TestSuite ts = (TestSuite) test; /* 120:101 */ String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName(); /* 121:102 */ Description description = Description.createSuiteDescription(name, new Annotation[0]); /* 122:103 */ int n = ts.testCount(); /* 123:104 */ for (int i = 0; i < n; i++) /* 124: */ { /* 125:105 */ Description made = makeDescription(ts.testAt(i)); /* 126:106 */ description.addChild(made); /* 127: */ } /* 128:108 */ return description; /* 129: */ } /* 130:109 */ if ((test instanceof Describable)) /* 131: */ { /* 132:110 */ Describable adapter = (Describable) test; /* 133:111 */ return adapter.getDescription(); /* 134: */ } /* 135:112 */ if ((test instanceof TestDecorator)) /* 136: */ { /* 137:113 */ TestDecorator decorator = (TestDecorator) test; /* 138:114 */ return makeDescription(decorator.getTest()); /* 139: */ } /* 140:117 */ return Description.createSuiteDescription(test.getClass()); /* 141: */ }
private TestEnvironment determineTestEnvironmentBasedOnTestDefaults() { TestEnvironment defaultEnv = null; TestClass defaultEnvTest = null; for (Test t : testsAsList()) { if (t instanceof TestClassWrapper) { if (((TestClassWrapper) t).testCount() > 0) { Test firstTest = ((TestClassWrapper) t).tests().nextElement(); if (firstTest instanceof TestClass) { TestEnvironment env = ((TestClass) firstTest).createDefaultEnvironment(); if (defaultEnv == null) { defaultEnv = env; defaultEnvTest = (TestClass) firstTest; } else { if (!defaultEnv.getClass().equals(env.getClass())) { throw new IllegalStateException( "The test " + defaultEnvTest.getClassName() + " requires the " + defaultEnv.getClass() + " environment, while the " + ((TestClass) firstTest).getClassName() + " test requires the " + env.getClass() + " environment. Automatic resolution of the appropriate " + "test environment will only work if all tests in the suite use the exact same default test environment."); } } } else { throw new IllegalStateException( "Found a test that was a " + firstTest.getClass() + " instead of a TestClass"); } } else { throw new IllegalStateException( "Found a test class " + ((TestClassWrapper) t).getBackingType().getName() + " that has no tests."); } } else { throw new IllegalStateException( "Found a test that was a " + t.getClass() + " instead of a TestClassWrapper"); } } return defaultEnv; }
private static TestSuite extractSuite(Test test) { if (test instanceof TestSuite) { return (TestSuite) test; } else if (test instanceof SuiteListenerWrapper) { return extractSuite(((SuiteListenerWrapper) test).delegate()); } else { throw new IllegalArgumentException( "Unable to extract TestSuite from " + test.getClass().getName()); } }
private String getTestName(Test test) { String testName = ""; if (test instanceof TestCase) { TestCase testCase = (TestCase) test; if (DataDrivenTestCase.class.isAssignableFrom(test.getClass())) { testName = ((DataDrivenTestCase) testCase).getCustomTestName(); } else { testName = testCase.getName(); } } return testName; }
/** * Gets the name of a test, (different method depending on underlying type). * * @param t * @return test name */ public static String getTestName(Test t) { if (t instanceof TestCase) { return ((TestCase) t).getName(); } if (t instanceof JUnit4TestCaseFacade) { return ((JUnit4TestCaseFacade) t).getDescription().getDisplayName(); } if (t instanceof JUnit4TestAdapter) { return ((JUnit4TestAdapter) t).getDescription().getDisplayName(); } throw new ClassCastException(t.getClass().toString()); }
/** Tries to find the name of the class which a test represents across JUnit 3 and 4. */ static String getTestCaseClassName(Test test) { String className = test.getClass().getName(); if (test instanceof JUnitTaskMirrorImpl.VmExitErrorTest) { className = ((JUnitTaskMirrorImpl.VmExitErrorTest) test).getClassName(); } else if (className.equals("junit.framework.JUnit4TestCaseFacade")) { // JUnit 4 wraps solo tests this way. We can extract // the original test name with a little hack. String name = test.toString(); int paren = name.lastIndexOf('('); if (paren != -1 && name.endsWith(")")) { className = name.substring(paren + 1, name.length() - 1); } } return className; }
@Override public void endTest(Test test) { try { if (test != currentTestCase) { MozcLog.e("Unexpected test " + test + "; Expected one is " + currentTestCase); } else if (test instanceof TestCase) { maybeAddTimeAttribute(); serializer.endTag(NS_DEFAULT, TAG_TESTCASE); } else { MozcLog.e("Unextected type; " + test.getClass().getCanonicalName()); } } catch (IOException e) { MozcLog.e(e.getMessage(), e); } }
private static String getName(Test test) { if (test == null) { return "<Null Test>"; } String name = test.getClass().getName(); if (test instanceof TestCase) { TestCase testCase = (TestCase) test; return name + "." + testCase.getName() + "()"; } if (test instanceof JUnit4TestCaseFacade) { JUnit4TestCaseFacade junit4TestCase = (JUnit4TestCaseFacade) test; return junit4TestCase.getDescription().getDisplayName(); } return name; }
public static boolean isThreadHostile(Test test) { Class<?> testClass = test.getClass(); if (testClass.isAnnotationPresent(ThreadHostileTest.class)) { return true; } if (test instanceof WebDriverTestCase) { if (((WebDriverTestCase) test).getTestLabels().contains("threadHostile")) { return true; } } try { return testClass .getMethod(((TestCase) test).getName()) .isAnnotationPresent(ThreadHostileTest.class); } catch (Throwable t) { return false; } }
/** * Call the setSuite method of the test. The parameter type can be a variant of FuncTestSuite, * meaning that it in the type of the actually FuncTestSuite implementation, or its super class. * * @param test the specified test in which its setSuite method is called * @param suite the parameter of the method */ protected final void setVariantSuite(Test test, FuncTestSuite suite) { try { Method suiteMethod = null; String methodName = "setSuite"; Class[] paramTypes = new Class[1]; Class suiteClass = suite.getClass(); // obtain the setSuite method, try setSuite(suite.getClass()). // if not found, try the super class... while (suiteMethod == null) { try { paramTypes[0] = suiteClass; suiteMethod = test.getClass().getMethod(methodName, paramTypes); } catch (NoSuchMethodException e) { suiteClass = suiteClass.getSuperclass(); if (!FuncTestSuite.class.isAssignableFrom(suiteClass)) { // addTest(warning("Method \""+methodName+"\" not found")); return; } } } if (!Modifier.isPublic(suiteMethod.getModifiers())) { addTest(warning("Method \"" + getName() + "\" should be public")); return; } try { suiteMethod.invoke(test, new Object[] {suite}); } catch (InvocationTargetException e) { e.fillInStackTrace(); addTest(error("Error seting the suite", e)); } catch (IllegalAccessException e) { e.fillInStackTrace(); addTest(error("Error setting the suite", e)); } } catch (Throwable t) { t.printStackTrace(); } }
@Override public void startTest(Test test) { Log.i("test", String.format("%s 测试开始", test.getClass().getName())); ++mTotalTestCounts; }
@Override public void endTest(Test test) { Log.i("test", String.format("%s 测试结束", test.getClass().getName())); }
@Override public void addFailure(Test test, AssertionFailedError assertionFailedError) { Log.e("test", String.format("%s 测试不通过", test.getClass().getName())); Log.e("test", assertionFailedError.getMessage(), assertionFailedError); ++mFailureTestCounts; }
@Override public void addError(Test test, Throwable throwable) { Log.e("test", String.format("%s 测试抛出异常", test.getClass().getName())); ++mErrorTestCounts; }
/** * This constructor extracts the needed information from the given test. * * @param test Test to analyze */ public TestInfos(Test test) { className = test.getClass().getName(); String _methodName = test.toString(); methodName = _methodName.substring(0, _methodName.indexOf('(')); }
public MasterListTestSuite() { super("WTP Source Editing Master List Test Suite"); System.setProperty("wtp.autotest.noninteractive", "true"); addTest(SSEModelTestSuite.suite()); addTest(SSEModelXMLTestSuite.suite()); addTest(DTDCoreTestSuite.suite()); addTest(AllXSDCoreTests.suite()); addTest(CSSCoreTestSuite.suite()); addTest(HTMLCoreTestSuite.suite()); addTest(JSPCoreTestSuite.suite()); // addTest(EncodingTestSuite.suite()); // addTest(CSSEncodingTestSuite.suite()); // addTest(HTMLEncodingTestSuite.suite()); // addTest(JSPEncodingTestSuite.suite()); // // addTest(AllXMLTests.suite()); // addTest(AllXSDTests.suite()); addTest(SSEUITestSuite.suite()); addTest(XMLUITestSuite.suite()); addTest(DTDUITestSuite.suite()); addTest(CSSUITestSuite.suite()); addTest(HTMLUITestSuite.suite()); addTest(JSPUITestSuite.suite()); addTest(RunJSDTCoreTests.suite()); addTest(JSDTCompilerTests.suite()); addTest(JSDTUITests.suite()); addTest(AllWebCoreTests.suite()); addTest(AllWebUITests.suite()); // addTest(new AllTestsSuite()); // addTest(RegressionBucket.suite()); // addTest(AllTestCases.suite()); IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); for (int i = 0; i < elements.length; i++) { if (elements[i].getName().equals("suite")) { TestSuite suite; try { suite = (TestSuite) elements[i].createExecutableExtension(CLASS); addTestSuite(suite.getClass()); System.err.println("Adding TestSuite " + suite.getClass().getName()); } catch (CoreException e) { e.printStackTrace(System.err); Platform.getLog(Platform.getBundle("org.eclipse.wst.sse.unittests")).log(e.getStatus()); } } else if (elements[i].getName().equals("test")) { Test test; try { test = (Test) elements[i].createExecutableExtension(CLASS); addTestSuite(test.getClass()); System.err.println("Adding TestCase " + test.getClass().getName()); } catch (CoreException e) { e.printStackTrace(System.err); Platform.getLog(Platform.getBundle("org.eclipse.wst.sse.unittests")).log(e.getStatus()); } } } }
/** * Runs all tests belonging to this test suite on the grid. * * @param result Test result collector. */ @Override public void run(TestResult result) { if (isDisabled) { copy.run(result); } else { GridTestRouter router = createRouter(); Grid grid = startGrid(); try { List<GridTaskFuture<?>> futs = new ArrayList<GridTaskFuture<?>>(testCount()); List<GridJunit3SerializableTest> tests = new ArrayList<GridJunit3SerializableTest>(testCount()); for (int i = 0; i < testCount(); i++) { Test junit = testAt(i); GridJunit3SerializableTest test; if (junit instanceof TestSuite) { test = new GridJunit3SerializableTestSuite((TestSuite) junit); } else { assert junit instanceof TestCase : "Test must be either TestSuite or TestCase: " + junit; test = new GridJunit3SerializableTestCase((TestCase) junit); } tests.add(test); if (clsLdr == null) { clsLdr = U.detectClassLoader(junit.getClass()); } futs.add( grid.execute( new GridJunit3Task(junit.getClass(), clsLdr), new GridJunit3Argument(router, test, locTests.contains(test.getName())), timeout)); } for (int i = 0; i < testCount(); i++) { GridTaskFuture<?> fut = futs.get(i); GridJunit3SerializableTest origTest = tests.get(i); try { GridJunit3SerializableTest resTest = (GridJunit3SerializableTest) fut.get(); origTest.setResult(resTest); origTest.getTest().run(result); } catch (GridException e) { handleFail(result, origTest, e); } } } finally { stopGrid(); } } }
private Class<? extends Test> getEffectiveClass(Test test) { return test.getClass(); }
/* 63: */ /* 64: */ private Class<? extends Test> getEffectiveClass(Test test) /* 65: */ { /* 66: 53 */ return test.getClass(); /* 67: */ }