use of com.facebook.buck.test.TestResultSummary in project buck by facebook.
the class TestRunningTest method testXmlGeneration.
/**
* Tests the --xml flag, ensuring that test result data is correctly
* formatted.
*/
@Test
public void testXmlGeneration() throws Exception {
// Set up sample test data.
TestResultSummary result1 = new TestResultSummary(/* testCaseName */
"TestCase", /* testName */
"passTest", /* type */
ResultType.SUCCESS, /* time */
5000, /* message */
null, /* stacktrace */
null, /* stdOut */
null, /* stdErr */
null);
TestResultSummary result2 = new TestResultSummary(/* testCaseName */
"TestCase", /* testName */
"failWithMsg", /* type */
ResultType.FAILURE, /* time */
7000, /* message */
"Index out of bounds!", /* stacktrace */
"Stacktrace", /* stdOut */
null, /* stdErr */
null);
TestResultSummary result3 = new TestResultSummary(/* testCaseName */
"TestCase", /* testName */
"failNoMsg", /* type */
ResultType.SUCCESS, /* time */
4000, /* message */
null, /* stacktrace */
null, /* stdOut */
null, /* stdErr */
null);
List<TestResultSummary> resultList = ImmutableList.of(result1, result2, result3);
TestCaseSummary testCase = new TestCaseSummary("TestCase", resultList);
List<TestCaseSummary> testCases = ImmutableList.of(testCase);
TestResults testResults = FakeTestResults.of(testCases);
List<TestResults> testResultsList = ImmutableList.of(testResults);
// Call the XML generation method with our test data.
StringWriter writer = new StringWriter();
TestRunning.writeXmlOutput(testResultsList, writer);
ByteArrayInputStream resultStream = new ByteArrayInputStream(writer.toString().getBytes());
// Convert the raw XML data into a DOM object, which we will check.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
Document doc = docBuilder.parse(resultStream);
// Check for exactly one <tests> tag.
NodeList testsList = doc.getElementsByTagName("tests");
assertEquals(testsList.getLength(), 1);
// Check for exactly one <test> tag.
Element testsEl = (Element) testsList.item(0);
NodeList testList = testsEl.getElementsByTagName("test");
assertEquals(testList.getLength(), 1);
// Check for exactly three <testresult> tags.
// There should be two failures and one success.
Element testEl = (Element) testList.item(0);
NodeList resultsList = testEl.getElementsByTagName("testresult");
assertEquals(resultsList.getLength(), 3);
// Verify the text elements of the first <testresult> tag.
Element passResultEl = (Element) resultsList.item(0);
assertEquals(passResultEl.getAttribute("name"), "passTest");
assertEquals(passResultEl.getAttribute("time"), "5000");
checkXmlTextContents(passResultEl, "message", "");
checkXmlTextContents(passResultEl, "stacktrace", "");
// Verify the text elements of the second <testresult> tag.
assertEquals(testEl.getAttribute("name"), "TestCase");
Element failResultEl1 = (Element) resultsList.item(1);
assertEquals(failResultEl1.getAttribute("name"), "failWithMsg");
assertEquals(failResultEl1.getAttribute("time"), "7000");
checkXmlTextContents(failResultEl1, "message", "Index out of bounds!");
checkXmlTextContents(failResultEl1, "stacktrace", "Stacktrace");
// Verify the text elements of the third <testresult> tag.
Element failResultEl2 = (Element) resultsList.item(2);
assertEquals(failResultEl2.getAttribute("name"), "failNoMsg");
assertEquals(failResultEl2.getAttribute("time"), "4000");
checkXmlTextContents(failResultEl2, "message", "");
checkXmlTextContents(failResultEl2, "stacktrace", "");
}
use of com.facebook.buck.test.TestResultSummary in project buck by facebook.
the class TestRunningTest method whenAllTestsAreSeparateTestsRunInOrder.
@Test
public void whenAllTestsAreSeparateTestsRunInOrder() throws Exception {
CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().build();
AtomicInteger atomicExecutionOrder = new AtomicInteger(0);
ExecutionOrderAwareFakeStep separateTestStep1 = new ExecutionOrderAwareFakeStep("teststep1", "teststep1", 0, atomicExecutionOrder);
final TestResults fakeTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.SUCCESS, 5000, null, null, null, null)))));
BuildTarget separateTest1Target = BuildTargetFactory.newInstance("//:test1");
FakeTestRule separateTest1 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest1Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep1OutputDir")), // runTestSeparately
true, ImmutableList.of(separateTestStep1), () -> fakeTestResults);
ExecutionOrderAwareFakeStep separateTestStep2 = new ExecutionOrderAwareFakeStep("teststep2", "teststep2", 0, atomicExecutionOrder);
BuildTarget separateTest2Target = BuildTargetFactory.newInstance("//:test2");
FakeTestRule separateTest2 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest2Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep2OutputDir")), // runTestSeparately
true, ImmutableList.of(separateTestStep2), () -> fakeTestResults);
ExecutionOrderAwareFakeStep separateTestStep3 = new ExecutionOrderAwareFakeStep("teststep3", "teststep3", 0, atomicExecutionOrder);
BuildTarget separateTest3Target = BuildTargetFactory.newInstance("//:test3");
FakeTestRule separateTest3 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest3Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep3OutputDir")), // runTestSeparately
true, ImmutableList.of(separateTestStep3), () -> fakeTestResults);
// We explicitly use an actual thread pool here; the logic should ensure the
// separate tests are run in the correct order.
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
FakeBuildEngine fakeBuildEngine = new FakeBuildEngine(ImmutableMap.of(separateTest1Target, BuildResult.success(separateTest1, BUILT_LOCALLY, CacheResult.miss()), separateTest2Target, BuildResult.success(separateTest2, BUILT_LOCALLY, CacheResult.miss()), separateTest3Target, BuildResult.success(separateTest3, BUILT_LOCALLY, CacheResult.miss())), ImmutableMap.of(separateTest1Target, new RuleKey("00"), separateTest2Target, new RuleKey("00"), separateTest3Target, new RuleKey("00")));
ExecutionContext fakeExecutionContext = TestExecutionContext.newInstance();
DefaultStepRunner stepRunner = new DefaultStepRunner();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
int ret = TestRunning.runTests(commandRunnerParams, ImmutableList.of(separateTest1, separateTest2, separateTest3), fakeExecutionContext, DEFAULT_OPTIONS, service, fakeBuildEngine, stepRunner, new SourcePathResolver(ruleFinder), ruleFinder);
assertThat(ret, equalTo(0));
assertThat(separateTestStep1.getExecutionBeginOrder(), equalTo(Optional.of(0)));
assertThat(separateTestStep1.getExecutionEndOrder(), equalTo(Optional.of(1)));
assertThat(separateTestStep2.getExecutionBeginOrder(), equalTo(Optional.of(2)));
assertThat(separateTestStep2.getExecutionEndOrder(), equalTo(Optional.of(3)));
assertThat(separateTestStep3.getExecutionBeginOrder(), equalTo(Optional.of(4)));
assertThat(separateTestStep3.getExecutionEndOrder(), equalTo(Optional.of(5)));
}
use of com.facebook.buck.test.TestResultSummary in project buck by facebook.
the class TestResultFormatterTest method shouldUseDecimalCommaForGerman.
@Test
public void shouldUseDecimalCommaForGerman() {
TestResultFormatter formatter = new TestResultFormatter(new Ansi(false), Verbosity.COMMANDS, TestResultSummaryVerbosity.of(false, false), Locale.GERMAN, Optional.of(logPath), TimeZone.getTimeZone("America/Los_Angeles"));
TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(new TestResultSummary("com.example.FooTest", "successTest", ResultType.SUCCESS, 12300, /*message*/
null, /*stacktrace*/
null, "good stdout", "good stderr")));
TestResults results = FakeTestResults.of(ImmutableList.of(summary));
ImmutableList.Builder<String> builder = ImmutableList.builder();
formatter.reportResult(builder, results);
assertEquals("PASS 12,3s 1 Passed 0 Skipped 0 Failed com.example.FooTest", toString(builder));
}
use of com.facebook.buck.test.TestResultSummary in project buck by facebook.
the class TestResultFormatterTest method createTestResults.
@Before
public void createTestResults() {
stackTrace = Throwables.getStackTraceAsString(new Exception("Ouch"));
successTest = new TestResultSummary("com.example.FooTest", "successTest", ResultType.SUCCESS, 500, /*message*/
null, /*stacktrace*/
null, "good stdout", "good stderr");
failingTest = new TestResultSummary("com.example.FooTest", "failTest", ResultType.FAILURE, 200, "Unexpected fish found", stackTrace, "bad stdout", "bad stderr");
}
Aggregations