Search in sources :

Example 1 with AggregatedTestResultEvent

use of com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent in project randomizedtesting by randomizedtesting.

the class AggregatedSuiteResultEvent method serialize.

public void serialize(JsonWriter w, boolean outputStreams) throws IOException {
    w.beginObject();
    w.name("slave").value(getSlave().id);
    w.name("startTimestamp").value(getStartTimestamp());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ROOT);
    w.name("startTimestampDate").value(sdf.format(new Date(getStartTimestamp())));
    w.name("executionTime").value(getExecutionTime());
    w.name("description");
    JsonHelpers.writeDescription(w, getDescription());
    w.name("tests");
    w.beginArray();
    for (AggregatedTestResultEvent e : getTests()) {
        serialize(w, sdf, e);
    }
    w.endArray();
    w.name("suiteFailures");
    w.beginArray();
    for (FailureMirror m : getFailures()) {
        serialize(w, m);
    }
    w.endArray();
    w.name("executionEvents");
    w.beginArray();
    serializeEvents(w, outputStreams);
    w.endArray();
    w.endObject();
}
Also used : FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with AggregatedTestResultEvent

use of com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent in project randomizedtesting by randomizedtesting.

the class AggregatedSuiteResultEvent method serialize.

private void serialize(JsonWriter w, SimpleDateFormat sdf, AggregatedTestResultEvent e) throws IOException {
    w.beginObject();
    w.name("slave").value(e.getSlave().id);
    w.name("startTimestamp").value(e.getStartTimestamp());
    w.name("startTimestampDate").value(sdf.format(new Date(e.getStartTimestamp())));
    w.name("executionTime").value(e.getExecutionTime());
    w.name("description");
    JsonHelpers.writeDescription(w, e.getDescription());
    w.name("status").value(e.getStatus().name());
    w.name("testFailures");
    w.beginArray();
    for (FailureMirror m : e.getFailures()) {
        serialize(w, m);
    }
    w.endArray();
    w.endObject();
}
Also used : FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror) Date(java.util.Date)

Example 3 with AggregatedTestResultEvent

use of com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent in project randomizedtesting by randomizedtesting.

the class AntXmlReport method buildModel.

/* */
private List<TestCaseModel> buildModel(List<AggregatedTestResultEvent> testEvents) {
    List<TestCaseModel> tests = new ArrayList<>();
    for (AggregatedTestResultEvent e : testEvents) {
        TestCaseModel model = new TestCaseModel();
        if (e.getStatus() == TestStatus.IGNORED || e.getStatus() == TestStatus.IGNORED_ASSUMPTION) {
            if (mavenExtensions) {
                // This emits an empty <skipped /> element.
                model.skipped = "";
            } else {
                // No way to report these in pure ANT XML.
                continue;
            }
        }
        model.name = applyFilters(e.getDescription().getMethodName());
        model.classname = e.getDescription().getClassName();
        model.time = e.getExecutionTime() / 1000.0;
        for (FailureMirror m : e.getFailures()) {
            if (m.isAssumptionViolation()) {
                // Assumptions are not represented in ANT or Maven XMLs.
                continue;
            } else if (m.isAssertionViolation()) {
                model.failures.add(buildModel(m));
            } else {
                model.errors.add(buildModel(m));
            }
        }
        tests.add(model);
    }
    return tests;
}
Also used : AggregatedTestResultEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent) ArrayList(java.util.ArrayList) FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)

Example 4 with AggregatedTestResultEvent

use of com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent in project randomizedtesting by randomizedtesting.

the class TextReport method emitStatusLine.

/**
 * Emit status line for an aggregated event.
 */
private void emitStatusLine(AggregatedResultEvent result, TestStatus status, long timeMillis) throws IOException {
    final StringBuilder line = new StringBuilder();
    line.append(shortTimestamp(result.getStartTimestamp()));
    line.append(Strings.padEnd(statusNames.get(status), 8, ' '));
    line.append(formatDurationInSeconds(timeMillis));
    if (forkedJvmCount > 1) {
        line.append(String.format(Locale.ROOT, jvmIdFormat, result.getSlave().id));
    }
    line.append(" | ");
    line.append(formatDescription(result.getDescription()));
    if (!result.isSuccessful()) {
        line.append(FAILURE_MARKER);
    }
    line.append("\n");
    if (showThrowable) {
        // GH-82 (cause for ignored tests).
        if (status == TestStatus.IGNORED && result instanceof AggregatedTestResultEvent) {
            final StringWriter sw = new StringWriter();
            PrefixedWriter pos = new PrefixedWriter(indent, sw, DEFAULT_MAX_LINE_WIDTH);
            pos.write("Cause: ");
            pos.write(((AggregatedTestResultEvent) result).getCauseForIgnored());
            pos.completeLine();
            line.append(sw.toString());
        }
        final List<FailureMirror> failures = result.getFailures();
        if (!failures.isEmpty()) {
            final StringWriter sw = new StringWriter();
            PrefixedWriter pos = new PrefixedWriter(indent, sw, DEFAULT_MAX_LINE_WIDTH);
            int count = 0;
            for (FailureMirror fm : failures) {
                count++;
                if (fm.isAssumptionViolation()) {
                    pos.write(String.format(Locale.ROOT, "Assumption #%d: %s", count, MoreObjects.firstNonNull(fm.getMessage(), "(no message)")));
                } else {
                    pos.write(String.format(Locale.ROOT, "Throwable #%d: %s", count, showStackTraces ? filterStackTrace(fm.getTrace()) : fm.getThrowableString()));
                }
            }
            pos.completeLine();
            if (sw.getBuffer().length() > 0) {
                line.append(sw.toString());
            }
        }
    }
    logShort(line);
}
Also used : AggregatedTestResultEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent) StringWriter(java.io.StringWriter) FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)

Example 5 with AggregatedTestResultEvent

use of com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent in project randomizedtesting by randomizedtesting.

the class TextReport method emitBufferedEvents.

private void emitBufferedEvents(AggregatedSuiteResultEvent e) throws IOException {
    final IdentityHashMap<TestFinishedEvent, AggregatedTestResultEvent> eventMap = new IdentityHashMap<>();
    for (AggregatedTestResultEvent tre : e.getTests()) {
        eventMap.put(tre.getTestFinishedEvent(), tre);
    }
    final boolean emitOutput = (outputMode != OutputMode.NEVER) && ((outputMode == OutputMode.ALWAYS && !isPassthrough()) || (outputMode == OutputMode.ONERROR && !e.isSuccessful()));
    for (IEvent event : e.getEventStream()) {
        switch(event.getType()) {
            case APPEND_STDOUT:
                if (emitOutput)
                    ((IStreamEvent) event).copyTo(outStream);
                break;
            case APPEND_STDERR:
                if (emitOutput)
                    ((IStreamEvent) event).copyTo(errStream);
                break;
            case TEST_FINISHED:
                assert eventMap.containsKey(event);
                final AggregatedTestResultEvent aggregated = eventMap.get(event);
                if (displayStatus.get(aggregated.getStatus())) {
                    flushOutput();
                    emitStatusLine(aggregated, aggregated.getStatus(), aggregated.getExecutionTime());
                }
            default:
                break;
        }
    }
    if (emitOutput) {
        flushOutput();
    }
}
Also used : AggregatedTestResultEvent(com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent) IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) TestFinishedEvent(com.carrotsearch.ant.tasks.junit4.events.TestFinishedEvent) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

FailureMirror (com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)4 AggregatedTestResultEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent)3 Date (java.util.Date)2 IEvent (com.carrotsearch.ant.tasks.junit4.events.IEvent)1 TestFinishedEvent (com.carrotsearch.ant.tasks.junit4.events.TestFinishedEvent)1 StringWriter (java.io.StringWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1