Search in sources :

Example 26 with TestCaseSummary

use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.

the class TestResultFormatterTest method shouldOutputTruncatedLogLinesOfFailingTest.

@Test
public void shouldOutputTruncatedLogLinesOfFailingTest() throws IOException {
    TestResultFormatter formatter = createFormatterWithMaxLogLines(3);
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(failingTest));
    Files.write(logPath, ImmutableList.of("This log won't appear", "This one will", "Another one", "Should be last"), StandardCharsets.UTF_8);
    TestResults results = TestResults.builder().setBuildTarget(BuildTargetFactory.newInstance("//foo:bar")).setTestCases(ImmutableList.of(summary)).addTestLogPaths(logPath).build();
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    formatter.reportResult(builder, results);
    String expected = String.format(Joiner.on('\n').join("FAIL     200ms  0 Passed   0 Skipped   1 Failed   com.example.FooTest", "FAILURE %s %s: %s", "%s", "====TEST LOGS====", "Last 3 test log lines from log.txt:", "This one will", "Another one", "Should be last"), failingTest.getTestCaseName(), failingTest.getTestName(), failingTest.getMessage(), stackTrace);
    assertEquals(expected, toString(builder));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) FakeTestResults(com.facebook.buck.test.FakeTestResults) TestResults(com.facebook.buck.test.TestResults) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 27 with TestCaseSummary

use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.

the class TestResultFormatterTest method allTestsPassingShouldNotEmptyTestLogs.

@Test
public void allTestsPassingShouldNotEmptyTestLogs() throws IOException {
    Path testLogPath = vfs.getPath("test-log.txt");
    Files.write(testLogPath, new byte[0]);
    TestResultFormatter formatter = createSilentFormatter();
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(successTest));
    TestResults results = FakeTestResults.withTestLogs(ImmutableList.of(summary), ImmutableList.of(testLogPath));
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    formatter.runComplete(builder, ImmutableList.of(results), ImmutableList.of());
    assertEquals("TESTS PASSED", toString(builder));
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) FakeTestResults(com.facebook.buck.test.FakeTestResults) TestResults(com.facebook.buck.test.TestResults) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 28 with TestCaseSummary

use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.

the class TestResultFormatterTest method shouldReportMinimalInformationForAPassingTest.

@Test
public void shouldReportMinimalInformationForAPassingTest() {
    TestResultFormatter formatter = createSilentFormatter();
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(successTest));
    TestResults results = FakeTestResults.of(ImmutableList.of(summary));
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    formatter.reportResult(builder, results);
    assertEquals("PASS     500ms  1 Passed   0 Skipped   0 Failed   com.example.FooTest", toString(builder));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) FakeTestResults(com.facebook.buck.test.FakeTestResults) TestResults(com.facebook.buck.test.TestResults) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 29 with TestCaseSummary

use of com.facebook.buck.test.TestCaseSummary 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));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) FakeTestResults(com.facebook.buck.test.FakeTestResults) TestResults(com.facebook.buck.test.TestResults) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Ansi(com.facebook.buck.util.Ansi) TestResultSummary(com.facebook.buck.test.TestResultSummary) Test(org.junit.Test)

Example 30 with TestCaseSummary

use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.

the class TestResultFormatterTest method shouldNotOutputLogLinesOfFailingTestWhenLogIsEmpty.

@Test
public void shouldNotOutputLogLinesOfFailingTestWhenLogIsEmpty() throws IOException {
    TestResultFormatter formatter = createFormatterWithMaxLogLines(10);
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(failingTest));
    Files.write(logPath, new byte[0]);
    TestResults results = TestResults.builder().setBuildTarget(BuildTargetFactory.newInstance("//foo:bar")).setTestCases(ImmutableList.of(summary)).addTestLogPaths(logPath).build();
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    formatter.reportResult(builder, results);
    String expected = String.format(Joiner.on('\n').join("FAIL     200ms  0 Passed   0 Skipped   1 Failed   com.example.FooTest", "FAILURE %s %s: %s", "%s"), failingTest.getTestCaseName(), failingTest.getTestName(), failingTest.getMessage(), stackTrace);
    assertEquals(expected, toString(builder));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) FakeTestResults(com.facebook.buck.test.FakeTestResults) TestResults(com.facebook.buck.test.TestResults) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

TestCaseSummary (com.facebook.buck.test.TestCaseSummary)34 Test (org.junit.Test)28 TestResults (com.facebook.buck.test.TestResults)25 FakeTestResults (com.facebook.buck.test.FakeTestResults)22 ImmutableList (com.google.common.collect.ImmutableList)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 TestResultSummary (com.facebook.buck.test.TestResultSummary)16 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 Path (java.nio.file.Path)7 BuildTarget (com.facebook.buck.model.BuildTarget)6 RuleKey (com.facebook.buck.rules.RuleKey)6 FakeTestRule (com.facebook.buck.rules.FakeTestRule)4 ExecutionContext (com.facebook.buck.step.ExecutionContext)4 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)4 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)3 BuckEventBus (com.facebook.buck.event.BuckEventBus)3 ConsoleTestUtils.postStoreFinished (com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished)3