/** * @return Actual calculated result as Object */ private Object getActualResultInternal(Object objTestUnit) { ITestUnit testUnit = (ITestUnit) objTestUnit; return testUnit.getActualResult(); }
public long getExecutionTime() { long executionTime = 0; if (testUnits != null) { for (ITestUnit testUnit : testUnits) { executionTime += testUnit.getExecutionTime(); } } return executionTime; }
public List<ITestUnit> getFilteredTestUnits(boolean failuresOnly, int size) { if (testUnits != null && failuresOnly) { List<ITestUnit> failedUnits = new ArrayList<>(); for (ITestUnit testUnit : testUnits) { if (testUnit.getResultStatus() != TestStatus.TR_OK // Failed unit && (failedUnits.size() < size || size == -1)) { failedUnits.add(testUnit); } } return failedUnits; } return testUnits; }
TestStatus status = testUnit.getResultStatus(); if (status != TR_OK) { String failureType = status == TR_NEQ ? FAILURE : ERROR; String description = testUnit.getDescription(); formatTime(testUnit.getExecutionTime()), " sec. ", failureType); StringBuilder summaryBuilder = new StringBuilder(modulePrefix + test.getName() + "#" + num); List<ComparedResult> comparisonResults = testUnit.getComparisonResults(); int rowNum = 0; for (ComparedResult comparisonResult : comparisonResults) { Throwable error = (Throwable) testUnit.getActualResult(); info(" Error: ", error, "\n", ExceptionUtils.getStackTrace(error)); Throwable cause = ExceptionUtils.getRootCause(error);
private void writeTestcase(String testName, ITestUnit test) throws XMLStreamException { if (test.getResultStatus() == TR_OK) { empty("testcase"); } else { start("testcase"); } attr("name", test.getTest().getId()); attr("classname", testName); attr("time", getTime(test.getExecutionTime())); writeErrorOrFailureElement(test); if (test.getResultStatus() != TR_OK) { end(); } }
boolean hasExpected = result.hasExpected(); for (ITestUnit testUnit : result.getTestUnits()) { TestStatus testStatus = hasExpected ? testUnit.getResultStatus() : TestStatus.TR_OK; boolean ok = testStatus == TestStatus.TR_OK; createCell(row, colNum++, testUnit.getTest().getId(), ok ? styles.resultSuccessId : styles.resultFailureId); createCell(row, colNum++, testUnit.getDescription(), styles.resultOther); for (ParameterWithValueDeclaration parameter : testUnit.getContextParams(result)) { createCell(row, colNum++, parameter.getValue(), styles.resultOther); for (ParameterWithValueDeclaration parameter : testUnit.getTest().getExecutionParams()) { createCell(row, colNum++, parameter, styles.resultOther);
private void writeErrorOrFailureElement(ITestUnit test) throws XMLStreamException { TestStatus testStatus = test.getResultStatus(); switch (testStatus) { case TR_OK: break; case TR_NEQ: start("failure"); attr("type", "ComparisonFailure"); writeCData(failureMessage(test)); end(); break; case TR_EXCEPTION: Throwable throwable = (Throwable) test.getActualResult(); start("error"); attr("type", throwable.getClass().getName()); attr("message", throwable.getMessage()); writeCData(ExceptionUtils.getStackTrace(throwable)); end(); break; default: throw new IllegalArgumentException("Unexpected TestStatus." + testStatus.name()); } }
private Map<Point, ComparedResult> getFieldsCoordinates(ITestUnit testUnit, SpreadsheetResult spreadsheetResult) { Map<Point, ComparedResult> fieldsCoordinates = new HashMap<>(); List<ComparedResult> fieldsToTest = testUnit.getComparisonResults(); if (fieldsToTest != null) { Map<String, Point> coordinates = getAbsoluteSpreadsheetFieldCoordinates(spreadsheetResult); for (ComparedResult fieldToTest : fieldsToTest) { Point fieldCoordinates = coordinates.get(fieldToTest.getFieldName()); if (fieldCoordinates != null) { fieldsCoordinates.put(fieldCoordinates, fieldToTest); } } } return fieldsCoordinates; }
public boolean hasDescription() { for (ITestUnit testUnit : testUnits) { if (testUnit.getTest().getDescription() != null) { return true; } } return false; }
@Override protected void writeResult(Row row, int colNum, ITestUnit testUnit) { createCell(row, colNum, testUnit.getActualParam(), styles.resultSuccess); } }
@Override protected void writeResult(Row row, int colNum, ITestUnit testUnit) { for (ComparedResult parameter : testUnit.getResultParams()) { boolean okField = parameter.getStatus() == TestStatus.TR_OK; Cell cell = createCell(row, colNum++, parameter.getActualValue(), okField ? styles.resultSuccess : styles.resultFailure); if (!okField) { String expected = "Expected: "; Object expectedValue = getSimpleValue(parameter.getExpectedValue()); if (expectedValue != null) { expected += FormattersManager.format(expectedValue); } setCellComment(cell, expected); } } }
TestStatus status = testUnit.getResultStatus(); if (status != TR_OK) { String failureType = status == TR_NEQ ? FAILURE : ERROR; String description = testUnit.getDescription(); formatTime(testUnit.getExecutionTime()), " sec. ", failureType); StringBuilder summaryBuilder = new StringBuilder(modulePrefix + test.getName() + "#" + num); List<ComparedResult> comparisonResults = testUnit.getComparisonResults(); int rowNum = 0; for (ComparedResult comparisonResult : comparisonResults) { Throwable error = (Throwable) testUnit.getActualResult(); info(" Error: ", error, "\n", ExceptionUtils.getStackTrace(error)); Throwable cause = ExceptionUtils.getRootCause(error);
private void writeTestcase(String testName, ITestUnit test) throws XMLStreamException { if (test.getResultStatus() == TR_OK) { empty("testcase"); } else { start("testcase"); } attr("name", test.getTest().getId()); attr("classname", testName); attr("time", getTime(test.getExecutionTime())); writeErrorOrFailureElement(test); if (test.getResultStatus() != TR_OK) { end(); } }
private void writeErrorOrFailureElement(ITestUnit test) throws XMLStreamException { TestStatus testStatus = test.getResultStatus(); switch (testStatus) { case TR_OK: break; case TR_NEQ: start("failure"); attr("type", "ComparisonFailure"); writeCData(failureMessage(test)); end(); break; case TR_EXCEPTION: Throwable throwable = (Throwable) test.getActualResult(); start("error"); attr("type", throwable.getClass().getName()); attr("message", throwable.getMessage()); writeCData(ExceptionUtils.getStackTrace(throwable)); end(); break; default: throw new IllegalArgumentException("Unexpected TestStatus." + testStatus.name()); } }
private Map<Point, ComparedResult> getFieldsCoordinates(ITestUnit testUnit, SpreadsheetResult spreadsheetResult) { Map<Point, ComparedResult> fieldsCoordinates = new HashMap<>(); List<ComparedResult> fieldsToTest = testUnit.getComparisonResults(); if (fieldsToTest != null) { Map<String, Point> coordinates = DefaultResultBuilder.getAbsoluteSpreadsheetFieldCoordinates(spreadsheetResult); for (ComparedResult fieldToTest : fieldsToTest) { Point fieldCoordinates = coordinates.get(fieldToTest.getFieldName()); if (fieldCoordinates != null) { fieldsCoordinates.put(fieldCoordinates, fieldToTest); } } } return fieldsCoordinates; }
public boolean hasContext() { for (ITestUnit testUnit : testUnits) { if (testUnit.getTest().isRuntimeContextDefined()) { return true; } } return false; }
/** * @return Actual calculated result as Object */ private Object getActualResultInternal(Object objTestUnit) { ITestUnit testUnit = (ITestUnit) objTestUnit; return testUnit.getActualResult(); }
public int getNumberOfAssertionFailures() { int cnt = 0; for (int i = 0; i < getNumberOfTestUnits(); i++) { if (testUnits.get(i).getResultStatus() == TestStatus.TR_NEQ) { ++cnt; } } return cnt; }
private String failureMessage(ITestUnit testUnit) { StringBuilder summaryBuilder = new StringBuilder(); List<ComparedResult> comparisonResults = testUnit.getComparisonResults(); for (ComparedResult comparisonResult : comparisonResults) { if (comparisonResult.getStatus() != TR_OK) { summaryBuilder.append('\n'); if (comparisonResult.getFieldName().equals(ThisField.THIS)) { summaryBuilder.append("Expected: <") .append(comparisonResult.getExpectedValue()) .append("> but was <") .append(comparisonResult.getActualValue()) .append(">"); } else { summaryBuilder.append("Field ") .append(comparisonResult.getFieldName()) .append(" expected: <") .append(comparisonResult.getExpectedValue()) .append("> but was <") .append(comparisonResult.getActualValue()) .append(">"); } } } return summaryBuilder.toString(); }
public boolean hasExpected() { for (ITestUnit testUnit : testUnits) { TestDescription test = testUnit.getTest(); if (test.isExpectedResultDefined() || test.isExpectedErrorDefined()) { return true; } } return false; }