Search in sources :

Example 1 with FailureMirror

use of com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror 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 2 with FailureMirror

use of com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror 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 3 with FailureMirror

use of com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror in project randomizedtesting by randomizedtesting.

the class AntXmlReport method buildModel.

/**
   * Build data model for serialization.
   */
private TestSuiteModel buildModel(AggregatedSuiteResultEvent e) throws IOException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
    TestSuiteModel suite = new TestSuiteModel();
    suite.hostname = "nohost.nodomain";
    suite.name = e.getDescription().getDisplayName();
    suite.properties = buildModel(e.getSlave().getSystemProperties());
    suite.time = e.getExecutionTime() / 1000.0;
    suite.timestamp = df.format(new Date(e.getStartTimestamp()));
    suite.testcases = buildModel(e.getTests());
    suite.tests = suite.testcases.size();
    if (mavenExtensions) {
        suite.skipped = 0;
    }
    // Suite-level failures and errors are simulated as test cases.
    for (FailureMirror m : e.getFailures()) {
        TestCaseModel model = new TestCaseModel();
        // empirical ANT output.
        model.classname = "junit.framework.TestSuite";
        model.name = applyFilters(m.getDescription().getClassName());
        model.time = 0;
        if (m.isAssertionViolation()) {
            model.failures.add(buildModel(m));
        } else {
            model.errors.add(buildModel(m));
        }
        suite.testcases.add(model);
    }
    // faked suite-level errors).
    for (TestCaseModel tc : suite.testcases) {
        suite.errors += tc.errors.size();
        suite.failures += tc.failures.size();
        if (mavenExtensions && tc.skipped != null) {
            suite.skipped += 1;
        }
    }
    StringWriter sysout = new StringWriter();
    StringWriter syserr = new StringWriter();
    if (outputStreams) {
        e.getSlave().decodeStreams(e.getEventStream(), sysout, syserr);
    }
    suite.sysout = sysout.toString();
    suite.syserr = syserr.toString();
    return suite;
}
Also used : StringWriter(java.io.StringWriter) FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with FailureMirror

use of com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror in project randomizedtesting by randomizedtesting.

the class FailureEvent method deserialize.

@Override
public void deserialize(JsonReader reader) throws IOException {
    reader.beginObject();
    expectProperty(reader, "description");
    Description description = JsonHelpers.readDescription(reader);
    String message = readStringOrNullProperty(reader, "message");
    String trace = readStringOrNullProperty(reader, "trace");
    String throwableString = readStringOrNullProperty(reader, "throwableString");
    String throwableClass = readStringOrNullProperty(reader, "throwableClass");
    boolean assertionViolation = readBoolean(reader, "assertionViolation");
    boolean assumptionViolation = readBoolean(reader, "assumptionViolation");
    this.failure = new FailureMirror(description, message, trace, throwableString, throwableClass, assertionViolation, assumptionViolation);
    reader.endObject();
}
Also used : Description(org.junit.runner.Description) FailureMirror(com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)

Example 5 with FailureMirror

use of com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror 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)

Aggregations

FailureMirror (com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror)6 Date (java.util.Date)3 AggregatedTestResultEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent)2 StringWriter (java.io.StringWriter)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)1 Description (org.junit.runner.Description)1