use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestRunning method writeXmlOutput.
/**
* Writes the test results in XML format to the supplied writer.
*
* This method does NOT close the writer object.
* @param allResults The test results.
* @param writer The writer in which the XML data will be written to.
*/
public static void writeXmlOutput(List<TestResults> allResults, Writer writer) throws IOException {
try {
// Build the XML output.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
Document doc = docBuilder.newDocument();
// Create the <tests> tag. All test data will be within this tag.
Element testsEl = doc.createElement("tests");
doc.appendChild(testsEl);
for (TestResults results : allResults) {
for (TestCaseSummary testCase : results.getTestCases()) {
// Create the <test name="..." status="..." time="..."> tag.
// This records a single test case result in the test suite.
Element testEl = doc.createElement("test");
testEl.setAttribute("name", testCase.getTestCaseName());
testEl.setAttribute("status", testCase.isSuccess() ? "PASS" : "FAIL");
testEl.setAttribute("time", Long.toString(testCase.getTotalTime()));
testsEl.appendChild(testEl);
// Loop through the test case and add XML data (name, message, and
// stacktrace) for each individual test, if present.
addExtraXmlInfo(testCase, testEl);
}
}
// Write XML to the writer.
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
} catch (TransformerException | ParserConfigurationException ex) {
throw new IOException("Unable to build the XML document!");
}
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestResultFormatter method reportResult.
/** Writes a detailed summary that ends with a trailing newline. */
public void reportResult(ImmutableList.Builder<String> addTo, TestResults results) {
if (verbosity.shouldPrintBinaryRunInformation() && results.getTotalNumberOfTests() > 1) {
addTo.add("");
addTo.add(String.format(locale, "Results for %s (%d/%d) %s", results.getBuildTarget().getFullyQualifiedName(), results.getSequenceNumber(), results.getTotalNumberOfTests(), verbosity));
}
boolean shouldReportLogSummaryAfterTests = false;
for (TestCaseSummary testCase : results.getTestCases()) {
// Only mention classes with tests.
if (testCase.getPassedCount() == 0 && testCase.getFailureCount() == 0 && testCase.getSkippedCount() == 0) {
continue;
}
String oneLineSummary = testCase.getOneLineSummary(locale, results.getDependenciesPassTheirTests(), ansi);
addTo.add(oneLineSummary);
// violations)
if (testCase.isSuccess()) {
continue;
}
for (TestResultSummary testResult : testCase.getTestResults()) {
if (!results.getDependenciesPassTheirTests()) {
continue;
}
// Report on either explicit failure
if (!testResult.isSuccess()) {
shouldReportLogSummaryAfterTests = true;
reportResultSummary(addTo, testResult);
}
}
}
if (shouldReportLogSummaryAfterTests && verbosity != Verbosity.SILENT) {
for (Path testLogPath : results.getTestLogPaths()) {
if (Files.exists(testLogPath)) {
reportLogSummary(locale, addTo, testLogPath, summaryVerbosity.getMaxDebugLogLines().orElse(DEFAULT_MAX_LOG_LINES));
}
}
}
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestCaseSummariesBuildingXctoolEventHandlerTest method noTestCasesAndOcunitFailureReturnsFailedTestResultSummary.
@Test
public void noTestCasesAndOcunitFailureReturnsFailedTestResultSummary() throws Exception {
Path jsonPath = TestDataHelper.getTestDataDirectory(this).resolve("xctool-output/ocunit-failure.json");
try (Reader jsonReader = Files.newBufferedReader(jsonPath, StandardCharsets.UTF_8)) {
TestCaseSummariesBuildingXctoolEventHandler testCaseSummariesBuilder = new TestCaseSummariesBuildingXctoolEventHandler(TestRule.NOOP_REPORTING_CALLBACK);
XctoolOutputParsing.streamOutputFromReader(jsonReader, testCaseSummariesBuilder);
List<TestCaseSummary> summaries = testCaseSummariesBuilder.getTestCaseSummaries();
assertThat(summaries, hasSize(1));
Matcher<TestResultSummary> summaryMatcher = allOf(hasProperty("type", equalTo(ResultType.FAILURE)), hasProperty("message", containsString("dyld: app was built for iOS 8.3 which is newer than this simulator 8.1")));
assertThat(summaries.get(0).getTestResults(), contains(summaryMatcher));
}
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestCaseSummariesBuildingXctoolEventHandlerTest method mixedPassAndFailReturnsMixedResultSummary.
@Test
@SuppressWarnings("unchecked")
public void mixedPassAndFailReturnsMixedResultSummary() throws Exception {
Path jsonPath = TestDataHelper.getTestDataDirectory(this).resolve("xctool-output/mixed-pass-and-fail.json");
try (Reader jsonReader = Files.newBufferedReader(jsonPath, StandardCharsets.UTF_8)) {
TestCaseSummariesBuildingXctoolEventHandler testCaseSummariesBuilder = new TestCaseSummariesBuildingXctoolEventHandler(TestRule.NOOP_REPORTING_CALLBACK);
XctoolOutputParsing.streamOutputFromReader(jsonReader, testCaseSummariesBuilder);
List<TestCaseSummary> summaries = testCaseSummariesBuilder.getTestCaseSummaries();
assertThat(summaries, hasSize(2));
Matcher<TestResultSummary> isOtherTestsTestSomethingSuccess = allOf(hasProperty("testCaseName", equalTo("OtherTests")), hasProperty("testName", equalTo("-[OtherTests testSomething]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(3L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
List<TestResultSummary> otherTestsResults = summaries.get(0).getTestResults();
assertThat(otherTestsResults, contains(isOtherTestsTestSomethingSuccess));
Matcher<TestResultSummary> isSomeTestsTestBacktraceOutputIsCaptured = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testBacktraceOutputIsCaptured]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString("-[SenTestCase performTest:]")), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestOutputMerging = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testOutputMerging]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString("stdout-line1\nstderr-line1\n")), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestPrintSDK = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testPrintSDK]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(1L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString("SDK: 6.1")), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestStream = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testStream]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(754L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString(">>>> i = 0")), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestWillFail = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testWillFail]")), hasProperty("type", equalTo(ResultType.FAILURE)), hasProperty("time", equalTo(0L)), hasProperty("message", containsString("SomeTests.m:40: 'a' should be equal to 'b'")), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestWillPass = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testWillPass]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
List<TestResultSummary> someTestsResults = summaries.get(1).getTestResults();
assertThat(someTestsResults, contains(isSomeTestsTestBacktraceOutputIsCaptured, isSomeTestsTestOutputMerging, isSomeTestsTestPrintSDK, isSomeTestsTestStream, isSomeTestsTestWillFail, isSomeTestsTestWillPass));
}
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class XctestOutputParsingTest method mixedPassAndFailReturnsMixedResultSummary.
@Test
@SuppressWarnings("unchecked")
public void mixedPassAndFailReturnsMixedResultSummary() throws Exception {
Path outputPath = TestDataHelper.getTestDataDirectory(this).resolve("xctest-output/mixed-pass-and-fail.txt");
try (Reader outputReader = Files.newBufferedReader(outputPath, StandardCharsets.UTF_8)) {
TestCaseSummariesBuildingXctestEventHandler xctestEventHandler = new TestCaseSummariesBuildingXctestEventHandler(TestRule.NOOP_REPORTING_CALLBACK);
XctestOutputParsing.streamOutput(outputReader, xctestEventHandler);
List<TestCaseSummary> summaries = xctestEventHandler.getTestCaseSummaries();
assertThat(summaries, hasSize(2));
Matcher<TestResultSummary> isOtherTestsTestSomethingSuccess = allOf(hasProperty("testCaseName", equalTo("OtherTests")), hasProperty("testName", equalTo("testSomething")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(3L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
List<TestResultSummary> otherTestsResults = summaries.get(0).getTestResults();
assertThat(otherTestsResults, contains(isOtherTestsTestSomethingSuccess));
Matcher<TestResultSummary> isSomeTestsTestWillFail = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("testWillFail")), hasProperty("type", equalTo(ResultType.FAILURE)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestWillPass = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("testWillPass")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
List<TestResultSummary> someTestsResults = summaries.get(1).getTestResults();
assertThat(someTestsResults, contains(isSomeTestsTestWillFail, isSomeTestsTestWillPass));
}
}
Aggregations