Java 类org.gradle.api.tasks.testing.TestDescriptor 实例源码

项目:Reer    文件:AbstractTestLogger.java   
private String getEventPath(TestDescriptor descriptor) {
    List<String> names = Lists.newArrayList();
    TestDescriptor current = descriptor;
    while (current != null) {
        if (isAtomicTestWhoseParentIsNotTheTestClass(current)) {
            // This deals with the fact that in TestNG, there are no class-level events,
            // but we nevertheless want to see the class name. We use "." rather than
            // " > " as a separator to make it clear that the class is not a separate
            // level. This matters when configuring granularity.
            names.add(current.getClassName() + "." + current.getName());
        } else {
            names.add(current.getName());
        }
        current = current.getParent();
    }

    int effectiveDisplayGranularity = displayGranularity == -1
            ? names.size() - 1 : Math.min(displayGranularity, names.size() - 1);
    List<String> displayedNames = Lists.reverse(names).subList(effectiveDisplayGranularity, names.size());
    return Joiner.on(" > ").join(displayedNames) + " ";
}
项目:Reer    文件:ShortExceptionFormatter.java   
private void printException(TestDescriptor descriptor, Throwable exception, boolean cause, int indentLevel, StringBuilder builder) {
    String indent = Strings.repeat(INDENT, indentLevel);
    builder.append(indent);
    if (cause) {
        builder.append("Caused by: ");
    }
    String className = exception instanceof PlaceholderException
            ? ((PlaceholderException) exception).getExceptionClassName() : exception.getClass().getName();
    builder.append(className);

    StackTraceFilter filter = new StackTraceFilter(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
    List<StackTraceElement> stackTrace = filter.filter(exception);
    if (stackTrace.size() > 0) {
        StackTraceElement element = stackTrace.get(0);
        builder.append(" at ");
        builder.append(element.getFileName());
        builder.append(':');
        builder.append(element.getLineNumber());
    }
    builder.append('\n');

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), true, indentLevel + 1, builder);
    }
}
项目:Pushjet-Android    文件:AbstractTestLogger.java   
private String getEventPath(TestDescriptor descriptor) {
    List<String> names = Lists.newArrayList();
    TestDescriptor current = descriptor;
    while (current != null) {
        if (isAtomicTestWhoseParentIsNotTheTestClass(current)) {
            // This deals with the fact that in TestNG, there are no class-level events,
            // but we nevertheless want to see the class name. We use "." rather than
            // " > " as a separator to make it clear that the class is not a separate
            // level. This matters when configuring granularity.
            names.add(current.getClassName() + "." + current.getName());
        } else {
            names.add(current.getName());
        }
        current = current.getParent();
    }

    int effectiveDisplayGranularity = displayGranularity == -1
            ? names.size() - 1 : Math.min(displayGranularity, names.size() - 1);
    List<String> displayedNames = Lists.reverse(names).subList(effectiveDisplayGranularity, names.size());
    return Joiner.on(" > ").join(displayedNames) + " ";
}
项目:Pushjet-Android    文件:ShortExceptionFormatter.java   
private void printException(TestDescriptor descriptor, Throwable exception, boolean cause, int indentLevel, StringBuilder builder) {
    String indent = Strings.repeat(INDENT, indentLevel);
    builder.append(indent);
    if (cause) {
        builder.append("Caused by: ");
    }
    String className = exception instanceof PlaceholderException
            ? ((PlaceholderException) exception).getExceptionClassName() : exception.getClass().getName();
    builder.append(className);

    StackTraceFilter filter = new StackTraceFilter(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
    List<StackTraceElement> stackTrace = filter.filter(exception);
    if (stackTrace.size() > 0) {
        StackTraceElement element = stackTrace.get(0);
        builder.append(" at ");
        builder.append(element.getFileName());
        builder.append(':');
        builder.append(element.getLineNumber());
    }
    builder.append('\n');

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), true, indentLevel + 1, builder);
    }
}
项目:Pushjet-Android    文件:AbstractTestLogger.java   
private String getEventPath(TestDescriptor descriptor) {
    List<String> names = Lists.newArrayList();
    TestDescriptor current = descriptor;
    while (current != null) {
        if (isAtomicTestWhoseParentIsNotTheTestClass(current)) {
            // This deals with the fact that in TestNG, there are no class-level events,
            // but we nevertheless want to see the class name. We use "." rather than
            // " > " as a separator to make it clear that the class is not a separate
            // level. This matters when configuring granularity.
            names.add(current.getClassName() + "." + current.getName());
        } else {
            names.add(current.getName());
        }
        current = current.getParent();
    }

    int effectiveDisplayGranularity = displayGranularity == -1
            ? names.size() - 1 : Math.min(displayGranularity, names.size() - 1);
    List<String> displayedNames = Lists.reverse(names).subList(effectiveDisplayGranularity, names.size());
    return Joiner.on(" > ").join(displayedNames) + " ";
}
项目:Pushjet-Android    文件:ShortExceptionFormatter.java   
private void printException(TestDescriptor descriptor, Throwable exception, boolean cause, int indentLevel, StringBuilder builder) {
    String indent = Strings.repeat(INDENT, indentLevel);
    builder.append(indent);
    if (cause) {
        builder.append("Caused by: ");
    }
    String className = exception instanceof PlaceholderException
            ? ((PlaceholderException) exception).getExceptionClassName() : exception.getClass().getName();
    builder.append(className);

    StackTraceFilter filter = new StackTraceFilter(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
    List<StackTraceElement> stackTrace = filter.filter(exception);
    if (stackTrace.size() > 0) {
        StackTraceElement element = stackTrace.get(0);
        builder.append(" at ");
        builder.append(element.getFileName());
        builder.append(':');
        builder.append(element.getLineNumber());
    }
    builder.append('\n');

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), true, indentLevel + 1, builder);
    }
}
项目:Reer    文件:FullExceptionFormatter.java   
@Override
public String format(TestDescriptor descriptor, List<Throwable> exceptions) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < exceptions.size(); i++) {
        printException(descriptor, exceptions.get(i), null, 0, builder);
        if (i < exceptions.size() - 1) {
            builder.append('\n');
        }
    }
    return builder.toString();
}
项目:Reer    文件:FullExceptionFormatter.java   
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
项目:Reer    文件:FullExceptionFormatter.java   
private Spec<StackTraceElement> createCompositeFilter(TestDescriptor descriptor) {
    List<Spec<StackTraceElement>> filters = Lists.newArrayList();
    for (TestStackTraceFilter type : testLogging.getStackTraceFilters()) {
        filters.add(createFilter(descriptor, type));
    }
    return new AndSpec<StackTraceElement>(filters);
}
项目:Reer    文件:FullExceptionFormatter.java   
private Spec<StackTraceElement> createFilter(TestDescriptor descriptor, TestStackTraceFilter filterType) {
    switch (filterType) {
        case ENTRY_POINT:
            return new ClassMethodNameStackTraceSpec(descriptor.getClassName(), descriptor.getName());
        case TRUNCATE:
            return new TruncatedStackTraceSpec(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
        case GROOVY:
            return new GroovyStackTraceSpec();
        default:
            throw new AssertionError();
    }
}
项目:Reer    文件:AbstractTestLogger.java   
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
项目:Reer    文件:ShortExceptionFormatter.java   
@Override
public String format(TestDescriptor descriptor, List<Throwable> exceptions) {
    StringBuilder builder = new StringBuilder();
    for (Throwable exception : exceptions) {
        printException(descriptor, exception, false, 1, builder);
    }
    return builder.toString();
}
项目:Reer    文件:TestCountLogger.java   
@Override
public void afterTest(TestDescriptor testDescriptor, TestResult result) {
    totalTests += result.getTestCount();
    failedTests += result.getFailedTestCount();
    skippedTests += result.getSkippedTestCount();
    progressLogger.progress(summary());
}
项目:Reer    文件:TestCountLogger.java   
@Override
public void beforeSuite(TestDescriptor suite) {
    if (suite.getParent() == null) {
        progressLogger = factory.newOperation(TestCountLogger.class);
        progressLogger.setDescription("Run tests");
        progressLogger.started();
        progressLogger.progress(summary());
    }
}
项目:Reer    文件:TestCountLogger.java   
@Override
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
public String format(TestDescriptor descriptor, List<Throwable> exceptions) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < exceptions.size(); i++) {
        printException(descriptor, exceptions.get(i), null, 0, builder);
        if (i < exceptions.size() - 1) {
            builder.append('\n');
        }
    }
    return builder.toString();
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
private Spec<StackTraceElement> createCompositeFilter(TestDescriptor descriptor) {
    List<Spec<StackTraceElement>> filters = Lists.newArrayList();
    for (TestStackTraceFilter type : testLogging.getStackTraceFilters()) {
        filters.add(createFilter(descriptor, type));
    }
    return new AndSpec<StackTraceElement>(filters);
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
private Spec<StackTraceElement> createFilter(TestDescriptor descriptor, TestStackTraceFilter filterType) {
    switch (filterType) {
        case ENTRY_POINT:
            return new ClassMethodNameStackTraceSpec(descriptor.getClassName(), descriptor.getName());
        case TRUNCATE:
            return new TruncatedStackTraceSpec(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
        case GROOVY:
            return new GroovyStackTraceSpec();
        default:
            throw new AssertionError();
    }
}
项目:Pushjet-Android    文件:AbstractTestLogger.java   
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
项目:Pushjet-Android    文件:ShortExceptionFormatter.java   
public String format(TestDescriptor descriptor, List<Throwable> exceptions) {
    StringBuilder builder = new StringBuilder();
    for (Throwable exception : exceptions) {
        printException(descriptor, exception, false, 1, builder);
    }
    return builder.toString();
}
项目:Pushjet-Android    文件:TestCountLogger.java   
public void beforeSuite(TestDescriptor suite) {
    if (suite.getParent() == null) {
        progressLogger = factory.newOperation(TestCountLogger.class);
        progressLogger.setDescription("Run tests");
        progressLogger.started();
    }
}
项目:Pushjet-Android    文件:TestCountLogger.java   
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
项目:Pushjet-Android    文件:StateTrackingTestResultProcessor.java   
private TestDescriptor findDescriptor(Object testId) {
    TestState state = executing.get(testId);
    if (state != null) {
        return state.test;
    }

    TestDescriptor d = currentParent;
    if (d != null) {
        return d;
    }

    //in theory this should not happen
    return new UnknownTestDescriptor();
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
public String format(TestDescriptor descriptor, List<Throwable> exceptions) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < exceptions.size(); i++) {
        printException(descriptor, exceptions.get(i), null, 0, builder);
        if (i < exceptions.size() - 1) {
            builder.append('\n');
        }
    }
    return builder.toString();
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
private void printException(TestDescriptor descriptor, Throwable exception,
                            @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
private Spec<StackTraceElement> createCompositeFilter(TestDescriptor descriptor) {
    List<Spec<StackTraceElement>> filters = Lists.newArrayList();
    for (TestStackTraceFilter type : testLogging.getStackTraceFilters()) {
        filters.add(createFilter(descriptor, type));
    }
    return new AndSpec<StackTraceElement>(filters);
}
项目:Pushjet-Android    文件:FullExceptionFormatter.java   
private Spec<StackTraceElement> createFilter(TestDescriptor descriptor, TestStackTraceFilter filterType) {
    switch (filterType) {
        case ENTRY_POINT:
            return new ClassMethodNameStackTraceSpec(descriptor.getClassName(), descriptor.getName());
        case TRUNCATE:
            return new TruncatedStackTraceSpec(new ClassMethodNameStackTraceSpec(descriptor.getClassName(), null));
        case GROOVY:
            return new GroovyStackTraceSpec();
        default:
            throw new AssertionError();
    }
}
项目:Pushjet-Android    文件:AbstractTestLogger.java   
protected void logEvent(TestDescriptor descriptor, TestLogEvent event, @Nullable String details) {
    StyledTextOutput output = textOutputFactory.create("TestEventLogger", logLevel);
    if (!descriptor.equals(lastSeenTestDescriptor) || event != lastSeenTestEvent) {
        output.println().append(getEventPath(descriptor));
        output.withStyle(getStyle(event)).println(event.toString());
    }
    lastSeenTestDescriptor = descriptor;
    lastSeenTestEvent = event;
    if (details != null) {
        output.append(TextUtil.toPlatformLineSeparators(details));
    }
}
项目:Pushjet-Android    文件:ShortExceptionFormatter.java   
public String format(TestDescriptor descriptor, List<Throwable> exceptions) {
    StringBuilder builder = new StringBuilder();
    for (Throwable exception : exceptions) {
        printException(descriptor, exception, false, 1, builder);
    }
    return builder.toString();
}
项目:Pushjet-Android    文件:TestCountLogger.java   
public void beforeSuite(TestDescriptor suite) {
    if (suite.getParent() == null) {
        progressLogger = factory.newOperation(TestCountLogger.class);
        progressLogger.setDescription("Run tests");
        progressLogger.started();
    }
}
项目:Pushjet-Android    文件:TestCountLogger.java   
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null) {
        if (failedTests > 0) {
            logger.error(TextUtil.getPlatformLineSeparator() + summary());
        }
        progressLogger.completed();

        if (result.getResultType() == TestResult.ResultType.FAILURE) {
            hadFailures = true;
        }
    }
}
项目:Pushjet-Android    文件:StateTrackingTestResultProcessor.java   
private TestDescriptor findDescriptor(Object testId) {
    TestState state = executing.get(testId);
    if (state != null) {
        return state.test;
    }

    TestDescriptor d = currentParent;
    if (d != null) {
        return d;
    }

    //in theory this should not happen
    return new UnknownTestDescriptor();
}
项目:gradle-metrics-plugin    文件:GradleTestSuiteCollector.java   
@Override
public void afterTest(TestDescriptor testDescriptor, TestResult testResult) {
    checkNotNull(testDescriptor);
    checkNotNull(testResult);
    Result result = getTestResult(testResult);
    org.gradle.api.tasks.testing.Test testTask = (org.gradle.api.tasks.testing.Test) task;
    String suiteName = testTask.getName();
    long startTime = testResult.getStartTime();
    long elapsed = testResult.getEndTime() - startTime;
    Test test = new Test(testDescriptor.getName(), testDescriptor.getClassName(), suiteName, result, new DateTime(startTime), elapsed);
    dispatcherSupplier.get().test(test);
}
项目:Reer    文件:FullExceptionFormatter.java   
private List<StackTraceElement> filterStackTrace(Throwable exception, TestDescriptor descriptor) {
    Spec<StackTraceElement> filterSpec = createCompositeFilter(descriptor);
    StackTraceFilter filter = new StackTraceFilter(filterSpec);
    return filter.filter(exception);
}
项目:Reer    文件:AbstractTestLogger.java   
protected void logEvent(TestDescriptor descriptor, TestLogEvent event) {
    logEvent(descriptor, event, null);
}
项目:Reer    文件:AbstractTestLogger.java   
private boolean isAtomicTestWhoseParentIsNotTheTestClass(TestDescriptor current) {
    return !current.isComposite() && current.getClassName() != null && (current.getParent() == null
            || !current.getClassName().equals(current.getParent().getName()));
}
项目:Reer    文件:TestCountLogger.java   
@Override
public void beforeTest(TestDescriptor testDescriptor) {
}
项目:Reer    文件:NoMatchingTestsReporter.java   
@Override
public void beforeSuite(TestDescriptor suite) {}
项目:Reer    文件:NoMatchingTestsReporter.java   
@Override
public void afterSuite(TestDescriptor suite, TestResult result) {
    if (suite.getParent() == null && result.getTestCount() == 0) {
        throw new TestExecutionException(message);
    }
}