コード例 #1
0
  /** {@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));
    }
  }
コード例 #2
0
  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;
    }
  }
コード例 #3
0
  @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());
  }
コード例 #4
0
 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);
 }
コード例 #5
0
 private void createStory(Description description) {
   if (description.getAnnotation(Story.class) != null)
     createStoryFromAnnotation(description.getAnnotation(Story.class));
   else {
     createStoryFromDescription(description.getDisplayName());
   }
 }
コード例 #6
0
 private boolean isItSingleScenario(Description description) {
   try {
     return description.getMethodName() != null;
   } catch (NoSuchMethodError e) { // junit 4.5
     return description.getDisplayName() != null;
   }
 }
コード例 #7
0
  /** {@inheritDoc} */
  private void notifyTestFinished(final Description junitDescription) {
    if (junitRunNotifier != null && junitDescription != null) {
      log.debug(junitDescription.getDisplayName() + " notifyTestFinished");

      junitRunNotifier.fireTestFinished(junitDescription);
    }
  }
コード例 #8
0
 private String getReadableTestName(final Description description) {
   String testName = description.getMethodName();
   if (testName == null) {
     testName = description.getDisplayName();
   }
   return testName;
 }
コード例 #9
0
 private String createScenarioNameFromTestMethodName(
     Description description, Parameters parametersAnnotation) {
   try {
     return decamelise(description.getMethodName());
   } catch (NoSuchMethodError e) { // junit 4.5
     return decamelise(description.getDisplayName());
   }
 }
コード例 #10
0
ファイル: DrillTest.java プロジェクト: mdaparte/drill
 @Override
 protected void failed(Throwable e, Description description) {
   testReporter.error(
       String.format(
           "Test Failed (%s): %s", memWatcher.getMemString(), description.getDisplayName()),
       e);
   failureCount++;
 }
コード例 #11
0
 @Override
 public void testRunStarted(final Description description) throws Exception {
   if (!HybrisJUnit4Test.intenseChecksActivated()) {
     return;
   }
   currentTestClass = description.getDisplayName();
   heapAtTestStart = memoryBean.getHeapMemoryUsage();
   nonHeapAtTestStart = memoryBean.getNonHeapMemoryUsage();
 }
コード例 #12
0
    @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);
    }
コード例 #13
0
    @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;
    }
コード例 #14
0
 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;
 }
コード例 #15
0
  /**
   * 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);
    }
  }
コード例 #16
0
  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;
  }
コード例 #17
0
  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());
  }
コード例 #18
0
  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;
  }
コード例 #19
0
  @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());
  }
コード例 #20
0
  /**
   * {@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());
    }
  }
コード例 #21
0
ファイル: DrillTest.java プロジェクト: mdaparte/drill
 @Override
 public void succeeded(Description description) {
   testReporter.info(
       String.format(
           "Test Succeeded (%s): %s", memWatcher.getMemString(), description.getDisplayName()));
 }
コード例 #22
0
 private String getMethodName(Description description) {
   return description.getDisplayName().split("\\(|\\)")[0];
 }
コード例 #23
0
 private static String getTestCaseName(Description description) {
   return description.getDisplayName().split("\\(|\\)")[1];
 }
コード例 #24
0
 private boolean match(String step, Description description) {
   return description
       .getDisplayName()
       .startsWith(JUnitDescriptionGenerator.getJunitSafeString(step));
 }
コード例 #25
0
 @Override
 public void testFinished(Description desc) {
   System.out.println("Finished:" + desc.getDisplayName());
 }
コード例 #26
0
 @Override
 public void testStarted(Description description) throws Exception {
   logger.trace("Test {} started", description.getDisplayName());
 }
コード例 #27
0
 @Override
 public void testFinished(Description description) throws Exception {
   logger.info("Test {} finished", description.getDisplayName());
 }
コード例 #28
0
 public void testIgnored(Description description) throws Exception {
   pw.println("testIgnored " + description.getDisplayName());
 }