@Override public void startTest(final Test arg0) { registerTestCase(JUnitVersionHelper.getTestCaseName(arg0)); } });
private String getTestName(Test test) { String testName = JUnitVersionHelper.getTestCaseName(test); if(testName==null) testName="unknown"; // if you extend from junit.framework.TestCase where you have public testXXX methods, // those test names are just the method name, and doesn't include the package name. // this doesn't work well with our harness, which uses the fully-qualified name as the // test names. To bridge this gap, detect the plain TestCase classes and fix up // the package name. if(testName.indexOf('.')==-1) testName = test.getClass().getPackage().getName()+"."+testName; return testName; }
/** * Interface TestListener. * * <p>A new Test is started. * @param t the test. */ @Override public void startTest(final Test t) { final String testName = JUnitVersionHelper.getTestCaseName(t); logTestListenerEvent("startTest(" + testName + ")"); }
/** * Interface TestListener. * * <p>A Test is finished. * @param test the test. */ @Override public void endTest(final Test test) { final String testName = JUnitVersionHelper.getTestCaseName(test); logTestListenerEvent("endTest(" + testName + ")"); }
private static String createDescription(final Test test) throws BuildException { return JUnitVersionHelper.getTestCaseName(test) + "(" + JUnitVersionHelper.getTestCaseClassName(test) + ")"; }
/** * Interface TestListener. * * <p>A Test is finished. * @param test the test. */ @Override public void endTest(Test test) { if (Boolean.TRUE.equals(failed.get(test))) { return; } synchronized (wri) { try { wri.write("Testcase: " + JUnitVersionHelper.getTestCaseName(test)); Long l = testStarts.get(test); double seconds = 0; // can be null if an error occurred in setUp if (l != null) { seconds = (System.currentTimeMillis() - l) / ONE_SECOND; } wri.write(" took " + nf.format(seconds) + " sec"); wri.newLine(); } catch (IOException ex) { throw new BuildException(ex); } } }
/** * Interface TestListener. * * <p>An error occurred while running the test. * @param test the test. * @param t the error thrown by the test. */ @Override public void addError(final Test test, final Throwable t) { final String testName = JUnitVersionHelper.getTestCaseName(test); logTestListenerEvent("addError(" + testName + ", " + t.getMessage() + ")"); if (haltOnError) { res.stop(); } }
/** * Interface TestListener for JUnit <= 3.4. * * <p>A Test failed. * @param test the test. * @param t the exception thrown by the test. */ public void addFailure(final Test test, final Throwable t) { final String testName = JUnitVersionHelper.getTestCaseName(test); logTestListenerEvent("addFailure(" + testName + ", " + t.getMessage() + ")"); if (haltOnFailure) { res.stop(); } }
public static String getIgnoreMessage(Test test) { String message = null; try { Class<?> junit4FacadeClass = Class.forName("junit.framework.JUnit4TestCaseFacade"); if (test != null && test.getClass().isAssignableFrom(junit4FacadeClass)) { //try and get the message coded as part of the ignore /* * org.junit.runner.Description contains a getAnnotation(Class) method... but this * wasn't in older versions of JUnit4 so we have to try and do this by reflection */ Class<?> testClass = Class.forName(JUnitVersionHelper.getTestCaseClassName(test)); Method testMethod = testClass.getMethod(JUnitVersionHelper.getTestCaseName(test)); Class<? extends Annotation> ignoreAnnotation = Class .forName("org.junit.Ignore").asSubclass(Annotation.class); Annotation annotation = testMethod.getAnnotation(ignoreAnnotation); if (annotation != null) { Method valueMethod = annotation.annotationType().getMethod("value"); String value = (String) valueMethod.invoke(annotation); if (value != null && !value.isEmpty()) { message = value; } } } } catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException e) { // silently ignore - we'll report a skip with no message } return message; }
&& !ignoredTests.containsKey(testDescription)) { currentTest = doc.createElement(TESTCASE); final String n = JUnitVersionHelper.getTestCaseName(test); currentTest.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n);