use of org.eclipse.n4js.tester.domain.TestResult in project n4js by eclipse.
the class CliTestTreeXMLTransformer method stringifyTestCase.
private StringBuilder stringifyTestCase(TestCase testCase, IndentLevel indendLevel) {
StringBuilder sb = new StringBuilder();
TestResult result = testCase.getResult();
TestStatus status = result.getTestStatus();
sb.append(indendLevel.get()).append(START_TESTCASE).append(SP_NAME_EQ).append(testCase.getName()).append(END_QUOTES).append(SP_CLASSNAME_EQ).append(testCase.getClassName()).append(END_QUOTES).append(SP_TIME_EQ).append(converTime(testCase.getResult().getElapsedTime())).append(END_QUOTES).append(END_NL);
// add concrete data
switch(status) {
case PASSED:
// no extra data
break;
case SKIPPED:
case SKIPPED_NOT_IMPLEMENTED:
case SKIPPED_PRECONDITION:
case SKIPPED_IGNORE:
case SKIPPED_FIXME:
indendLevel.increase();
sb.append(indendLevel.get()).append("<skipped/>\n");
indendLevel.decrease();
break;
case FAILED:
case ERROR:
indendLevel.increase();
sb.append(indendLevel.get()).append(START_ERROR).append(SP_MESSAGE_EQ).append(escapeString(testCase.getResult().getMessage())).append(END_QUOTES).append(END_NL);
indendLevel.decrease();
break;
default:
throw new RuntimeException("unhandled status " + status);
}
sb.append(indendLevel.get()).append(END_TESTCASE);
return sb;
}
use of org.eclipse.n4js.tester.domain.TestResult in project n4js by eclipse.
the class TestEndedEventDispatcher method accept.
@Override
public void accept(TestEndedEvent tee) throws E {
TestResult result = tee.getResult();
TestStatus status = result.getTestStatus();
switch(status) {
case PASSED:
passed.accept(tee);
return;
case SKIPPED:
skipped.accept(tee);
return;
case SKIPPED_NOT_IMPLEMENTED:
notimplemented.accept(tee);
return;
case SKIPPED_PRECONDITION:
precondition.accept(tee);
return;
case SKIPPED_IGNORE:
ignore.accept(tee);
return;
case SKIPPED_FIXME:
fixmme.accept(tee);
return;
case FAILED:
failed.accept(tee);
return;
case ERROR:
error.accept(tee);
return;
default:
unhandled.accept(tee);
}
}
use of org.eclipse.n4js.tester.domain.TestResult in project n4js by eclipse.
the class TestResultsView method onSingleClick.
/**
* Invoked when user double-clicks a result node in the UI.
*
* On invocation clears stack trace text are. If selection is a test case with stack trace, trace is shown in the
* trace area.
*/
protected void onSingleClick() {
stackTrace.setText("");
final ISelection selection = testTreeViewer.getSelection();
if (selection.isEmpty()) {
return;
}
if (selection instanceof IStructuredSelection) {
final Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof ResultNode) {
final ResultNode resultNode = (ResultNode) element;
final TestElement testElement = resultNode.getElement();
if (testElement instanceof TestCase) {
final TestCase testCase = (TestCase) testElement;
final TestResult result = testCase.getResult();
if (result != null) {
if (result.getTrace() != null && !result.getTrace().isEmpty()) {
final List<String> trace = newArrayList(result.getTrace());
final String firstLine = trace.get(0);
if ("Error".equals(firstLine) && !isNullOrEmpty(result.getMessage())) {
trace.set(0, result.getMessage());
}
final StringBuilder sb = new StringBuilder();
trace.forEach(line -> sb.append(line).append(lineSeparator()));
stackTrace.setText(sb.toString());
stackTrace.setSelection(0);
} else if ((SKIPPED_IGNORE.equals(result.getTestStatus()) || SKIPPED_FIXME.equals(result.getTestStatus())) && !isNullOrEmpty(result.getMessage())) {
stackTrace.setText(result.getMessage());
stackTrace.setSelection(0);
}
}
}
}
}
}
use of org.eclipse.n4js.tester.domain.TestResult in project n4js by eclipse.
the class MockTest method createTestResult.
private Object createTestResult(final long timeout, final int i) {
final String expected = valueOf(i);
final String actual;
final TestStatus status;
if (0 == i % 19) {
status = FAILED;
actual = "mod 19 for " + i;
} else if (0 == i % 31) {
status = ERROR;
actual = "mod 31 for " + i;
} else if (highestOneBit(i) == i) {
actual = "power of 2 for " + i;
status = SKIPPED;
} else {
actual = expected;
status = PASSED;
}
final TestResult result = new TestResult(status);
result.setElapsedTime(timeout);
result.setActual(actual);
result.setExpected(expected);
return result;
}
use of org.eclipse.n4js.tester.domain.TestResult in project n4js by eclipse.
the class TesterDomainTest method testSerializeTestResult.
/**
*/
@Test
public void testSerializeTestResult() throws Exception {
final TestResult expected = new TestResult(ERROR);
expected.setActual("actual result");
expected.setExpected("expected result");
expected.setTrace(newArrayList("trace 1", "trace 2", "trace 3"));
expected.setMessage("some message");
expected.setElapsedTime(1000L);
final String json = "{\"message\":\"some message\",\"expected\":\"expected result\",\"actual\":\"actual result\",\"trace\":[\"trace 1\",\"trace 2\",\"trace 3\"],\"testStatus\":\"ERROR\",\"elapsedTime\":1000}";
final TestResult actual = mapper.readValue(json, TestResult.class);
assertResultEquals(expected, actual);
final TestResult clone = actual.clone();
assertResultEquals(actual, clone);
assertFalse(actual == clone);
final String sparseJson = "{\"actual\":\"actual result\",\"trace\":[\"trace 1\",\"trace 2\",\"trace 3\"],\"testStatus\":\"ERROR\",\"elapsedTime\":1000}";
final TestResult sparseResult = mapper.readValue(sparseJson, TestResult.class);
assertNull(sparseResult.getMessage());
assertNull(sparseResult.getExpected());
}
Aggregations