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();
}
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();
}
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;
}
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);
}
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();
}
}
Aggregations