/** {@inheritDoc} */ private void notifyTestFailed(final Description junitDescription, final Throwable cause) { if (junitRunNotifier != null && junitDescription != null) { log.debug(junitDescription.getDisplayName() + " notify running TestFailed"); log.debug(junitDescription.getDisplayName() + " notify TestFailed"); junitRunNotifier.fireTestFailure(new Failure(junitDescription, cause)); } }
TestData getOrCreateTestData(Description description) { TestData value = testDataMap.get(description.getDisplayName()); if (value != null) return value; // another thread may have just added after our null check value = new TestData(description.getDisplayName()); TestData oldValue = testDataMap.putIfAbsent(description.getDisplayName(), value); if (oldValue == null) { return value; } else { return oldValue; } }
@Override public void testFailure(Failure failure) throws Exception { // Ignore assumptions. if (failure.getException() instanceof AssumptionViolatedException) { return; } final Description d = failure.getDescription(); final StringBuilder b = new StringBuilder(); b.append("FAILURE : ").append(d.getDisplayName()).append("\n"); b.append("REPRODUCE WITH : mvn test"); ReproduceErrorMessageBuilder builder = reproduceErrorMessageBuilder(b).appendAllOpts(failure.getDescription()); if (mustAppendClusterSeed(failure)) { appendClusterSeed(builder); } b.append("\n"); b.append("Throwable:\n"); if (failure.getException() != null) { traces().formatThrowable(b, failure.getException()); } logger.error(b.toString()); }
public ParsedDescription(Description description) { // The format of displayName is: "testMethodName(fullyQualifiedTestClassName)". String displayName = description.getDisplayName(); int openParenIndex = displayName.indexOf('('); testCaseName = displayName.substring(openParenIndex + 1, displayName.length() - 1); testName = displayName.substring(0, openParenIndex); }
private void createStory(Description description) { if (description.getAnnotation(Story.class) != null) createStoryFromAnnotation(description.getAnnotation(Story.class)); else { createStoryFromDescription(description.getDisplayName()); } }
private boolean isItSingleScenario(Description description) { try { return description.getMethodName() != null; } catch (NoSuchMethodError e) { // junit 4.5 return description.getDisplayName() != null; } }
/** {@inheritDoc} */ private void notifyTestFinished(final Description junitDescription) { if (junitRunNotifier != null && junitDescription != null) { log.debug(junitDescription.getDisplayName() + " notifyTestFinished"); junitRunNotifier.fireTestFinished(junitDescription); } }
private String getReadableTestName(final Description description) { String testName = description.getMethodName(); if (testName == null) { testName = description.getDisplayName(); } return testName; }
private String createScenarioNameFromTestMethodName( Description description, Parameters parametersAnnotation) { try { return decamelise(description.getMethodName()); } catch (NoSuchMethodError e) { // junit 4.5 return decamelise(description.getDisplayName()); } }
@Override protected void failed(Throwable e, Description description) { testReporter.error( String.format( "Test Failed (%s): %s", memWatcher.getMemString(), description.getDisplayName()), e); failureCount++; }
@Override public void testRunStarted(final Description description) throws Exception { if (!HybrisJUnit4Test.intenseChecksActivated()) { return; } currentTestClass = description.getDisplayName(); heapAtTestStart = memoryBean.getHeapMemoryUsage(); nonHeapAtTestStart = memoryBean.getNonHeapMemoryUsage(); }
@Override public void testFinished(Description description) throws Exception { String name = description.getDisplayName(); if (results.containsKey(name)) return; JUnitResult result = new JUnitResult(); result.name = name; result.status = "passed"; results.put(name, result); }
@Override public void evaluate() throws Throwable { Throwable caughtThrowable = null; for (int i = 0; i < repeatCount; i++) { try { statement.evaluate(); return; } catch (Throwable t) { caughtThrowable = t; System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed"); if (delayMs > 0 && repeatCount > i + 1) { Thread.sleep(delayMs); } } } System.err.println( description.getDisplayName() + ": giving up after " + repeatCount + " failures"); throw caughtThrowable; }
private String parseDescription(Description description) { String displayName = description.getDisplayName(); int p1 = displayName.indexOf("("); int p2 = displayName.indexOf(")"); if (p1 < 0 || p2 < 0 || p2 <= p1) { return displayName; } String methodName = displayName.substring(0, p1); String className = displayName.substring(p1 + 1, p2); return replaceAll(className) + " " + methodName; }
/** * Called after a test failed. It: * * <ul> * <li>dump database content * </ul> */ @Override protected void failed(final Throwable e, final Description description) { POJOLookupMap.get().dumpStatus("After test failed: " + description.getDisplayName()); // // Dump retained context values for (final Entry<String, Object> entry : context.entrySet()) { final String name = entry.getKey(); final Object value = entry.getValue(); System.out.println("\n" + name + ": " + value); } }
public static String findClassName(Description description) { String displayName = description.getDisplayName(); Matcher matcher = BRACKETS.matcher(displayName); String name = matcher.find() ? matcher.group(1) : displayName; if (name == null || "null".equals(name)) { Description childDescription = description.getChildren().get(0); if (childDescription != null) { String childName = childDescription.getDisplayName(); matcher = BRACKETS.matcher(childName); name = matcher.find() ? matcher.group(1) : childName; } if (name == null) { name = "Error instantiating test"; } } return name; }
public Statement apply(final Statement base, Description description) { Class<?> testClass = description.getTestClass(); init(description.getMethodName(), testClass.getSimpleName()); suppressCleanupErrors = testClass.getAnnotation(LeaksFileHandles.class) != null || description.getAnnotation(LeaksFileHandles.class) != null // For now, assume that all tests run with the daemon executer leak file handles // This seems to be true for any test that uses // `GradleExecuter.requireOwnGradleUserHomeDir` || "daemon".equals(System.getProperty("org.gradle.integtest.executer")); return new TestDirectoryCleaningStatement(base, description.getDisplayName()); }
private Description findDescription(Description parentDescription, String displayName) { if (displayName.equals(parentDescription.getDisplayName())) { return parentDescription; } for (Description desc : parentDescription.getChildren()) { Description found = findDescription(desc, displayName); if (found != null) { return found; } } return null; }
@Override protected void finished(Description description) { StringBuilder sb = new StringBuilder(); sb.append("Report for ").append(description.getDisplayName()).append('\n'); String delimiter = '+' + Joiner.on('+').join(line(20), line(70), line(10), line(10)) + "+\n"; sb.append(delimiter); sb.append(String.format("|%-20s|%-70s|%-10s|%-10s|%n", "Element", "Subject", "Status", "ms.")); sb.append(delimiter); for (LogEvent e : logEvents) { sb.append( String.format( "|%-20s|%-70s|%-10s|%-10s|%n", e.getElement(), e.getSubject(), e.getStatus(), e.getDuration())); } sb.append(delimiter); log.info(sb.toString()); }
/** * {@inheritDoc} * * @see org.junit.rules.TestWatcher#starting(org.junit.runner.Description) */ @Override protected void starting(Description d) { testClass = d.getTestClass(); className = testClass.getName(); methodName = d.getMethodName(); displayName = d.getDisplayName(); log( "\n\t>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\tRunning Test [%s.%s]\n\t>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", testClass.getSimpleName(), methodName); if (!preparedClasses.contains(testClass)) { log("Preparing Test Class [%s]", className); preparedClasses.add(testClass); UnsafeAdapterConfigurator.setConfiguration(testClass); Assert.assertFalse( "UnsafeAdapter is not in expected state", UnsafeAdapterConfigurator.requiresReset(testClass)); log( "Prepared Test Class [%s], Unsafe Adapter Config: %s", className, UnsafeAdapterConfigurator.printActualConfiguration()); } }
@Override public void succeeded(Description description) { testReporter.info( String.format( "Test Succeeded (%s): %s", memWatcher.getMemString(), description.getDisplayName())); }
private String getMethodName(Description description) { return description.getDisplayName().split("\\(|\\)")[0]; }
private static String getTestCaseName(Description description) { return description.getDisplayName().split("\\(|\\)")[1]; }
private boolean match(String step, Description description) { return description .getDisplayName() .startsWith(JUnitDescriptionGenerator.getJunitSafeString(step)); }
@Override public void testFinished(Description desc) { System.out.println("Finished:" + desc.getDisplayName()); }
@Override public void testStarted(Description description) throws Exception { logger.trace("Test {} started", description.getDisplayName()); }
@Override public void testFinished(Description description) throws Exception { logger.info("Test {} finished", description.getDisplayName()); }
public void testIgnored(Description description) throws Exception { pw.println("testIgnored " + description.getDisplayName()); }