Search in sources :

Example 6 with TestCaseSummary

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

the class TestRunningTest method testRunWhenPreviouslyFailed.

@Test
public void testRunWhenPreviouslyFailed() throws Exception {
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setDebugEnabled(false).build();
    FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of()) {

        @Override
        public boolean hasTestResultFiles() {
            return true;
        }
    };
    TestRuleKeyFileHelper testRuleKeyFileHelper = createNiceMock(TestRuleKeyFileHelper.class);
    expect(testRuleKeyFileHelper.isRuleKeyInDir(testRule)).andReturn(true).times(2);
    CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
    BuildResult result = BuildResult.success(testRule, MATCHING_RULE_KEY, CacheResult.miss());
    expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result).times(2);
    replay(cachingBuildEngine, testRuleKeyFileHelper);
    final TestResults failedTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.FAILURE, 5000, null, null, null, null)))));
    assertTrue("Test will be rerun if it previously failed", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED_IF_PASSED, Callables.<TestResults>returning(failedTestResults), /* running with test selectors */
    false, /* hasEnvironmentOverrides */
    false));
    final TestResults passedTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.SUCCESS, 5000, null, null, null, null)))));
    assertFalse("Test will be not rerun if it previously passed", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED_IF_PASSED, Callables.<TestResults>returning(passedTestResults), /* running with test selectors */
    false, /* hasEnvironmentOverrides */
    false));
    verify(cachingBuildEngine, testRuleKeyFileHelper);
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Example 7 with TestCaseSummary

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

the class SuperConsoleEventBusListenerTest method testFailingTest.

@Test
public void testFailingTest() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
    TestConsole console = new TestConsole();
    BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
    ImmutableSet<BuildTarget> testTargets = ImmutableSet.of(testTarget);
    Iterable<String> testArgs = Iterables.transform(testTargets, Object::toString);
    FakeBuildRule testBuildRule = new FakeBuildRule(testTarget, pathResolver, ImmutableSortedSet.of());
    SuperConsoleEventBusListener listener = new SuperConsoleEventBusListener(emptySuperConsoleConfig, console, fakeClock, noisySummaryVerbosity, new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties()), Optional.empty(), Locale.US, logPath, timeZone);
    eventBus.register(listener);
    ProjectBuildFileParseEvents.Started parseEventStarted = new ProjectBuildFileParseEvents.Started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 0L, ImmutableList.of("[+] PARSING BUCK FILES...0.0s"));
    validateConsole(listener, 100L, ImmutableList.of("[+] PARSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new ProjectBuildFileParseEvents.Finished(parseEventStarted), 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 200L, ImmutableList.of("[-] PARSING BUCK FILES...FINISHED 0.2s"));
    BuildEvent.Started buildEventStarted = BuildEvent.started(testArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ParseEvent.Started parseStarted = ParseEvent.started(testTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 300L, ImmutableList.of("[+] PROCESSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 400L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.2s";
    validateConsole(listener, 540L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.1s"));
    BuildRuleEvent.Started started = BuildRuleEvent.started(testBuildRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 800L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.4s", " |=> //:test...  0.2s (checking_cache)"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String buildingLine = "[-] BUILDING...FINISHED 0.8s";
    validateConsole(listener, 1300L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.started(// isRunAllTests
    true, TestSelectorList.empty(), // shouldExplainTestSelectorList
    false, ImmutableSet.copyOf(testArgs)), 2500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.5s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRuleEvent.started(testTarget), 3100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.7s", " |=> //:test...  0.1s"));
    UUID stepUuid = new UUID(0, 1);
    StepEvent.Started stepEventStarted = StepEvent.started("step_name", "step_desc", stepUuid);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 3300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3400L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.9s", " |=> //:test...  0.3s (running step_name[0.1s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, 0), 3500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3600L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.1s", " |=> //:test...  0.5s"));
    UUID testUUID = new UUID(2, 3);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.started(testUUID, "TestClass", "Foo"), 3700L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3800L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.3s", " |=> //:test...  0.7s (running Foo[0.1s])"));
    TestResultSummary testResultSummary = new TestResultSummary("TestClass", "Foo", ResultType.FAILURE, // time
    0L, // message
    "Foo.java:47: Assertion failure: 'foo' != 'bar'", // stacktrace
    null, // stdOut
    "Message on stdout", // stdErr
    "Message on stderr");
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.finished(testUUID, testResultSummary), 3900L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsoleWithLogLines(listener, 4000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.5s (0 PASS/1 FAIL)", " |=> //:test...  0.9s"), ImmutableList.of("FAILURE TestClass Foo: Foo.java:47: Assertion failure: 'foo' != 'bar'"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.finished(ImmutableSet.copyOf(testArgs), ImmutableList.of(TestResults.of(testTarget, ImmutableList.of(new TestCaseSummary("TestClass", ImmutableList.of(testResultSummary))), // contacts
    ImmutableSet.of(), // labels
    ImmutableSet.of()))), 4100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String testingLine = "[-] TESTING...FINISHED 1.6s (0 PASS/1 FAIL)";
    validateConsoleWithStdOutAndErr(listener, 4200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, testingLine), ImmutableList.of(), Optional.of(Joiner.on('\n').join("RESULTS FOR ALL TESTS", "FAIL    <100ms  0 Passed   0 Skipped   1 Failed   TestClass", "FAILURE TestClass Foo: Foo.java:47: Assertion failure: 'foo' != 'bar'", "====STANDARD OUT====", "Message on stdout", "====STANDARD ERR====", "Message on stderr", "TESTS FAILED: 1 FAILURE", "Failed target: //:test", "FAIL TestClass", "")), // We don't care about stderr, since the last frame will be flushed there.
    Optional.empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ConsoleTestUtils.postStoreStarted(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreStarted) ProjectBuildFileParseEvents(com.facebook.buck.json.ProjectBuildFileParseEvents) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) UUID(java.util.UUID) ConsoleTestUtils.postStoreFinished(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished) StepEvent(com.facebook.buck.step.StepEvent) RuleKey(com.facebook.buck.rules.RuleKey) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 8 with TestCaseSummary

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

the class SuperConsoleEventBusListenerTest method testSimpleTest.

@Test
public void testSimpleTest() {
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
    SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
    ImmutableSet<BuildTarget> testTargets = ImmutableSet.of(testTarget);
    Iterable<String> testArgs = Iterables.transform(testTargets, Object::toString);
    FakeBuildRule testBuildRule = new FakeBuildRule(testTarget, pathResolver, ImmutableSortedSet.of());
    ProjectBuildFileParseEvents.Started parseEventStarted = new ProjectBuildFileParseEvents.Started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 0L, ImmutableList.of("[+] PARSING BUCK FILES...0.0s"));
    validateConsole(listener, 100L, ImmutableList.of("[+] PARSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new ProjectBuildFileParseEvents.Finished(parseEventStarted), 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 200L, ImmutableList.of("[-] PARSING BUCK FILES...FINISHED 0.2s"));
    BuildEvent.Started buildEventStarted = BuildEvent.started(testArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ParseEvent.Started parseStarted = ParseEvent.started(testTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 300L, ImmutableList.of("[+] PROCESSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 400L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.2s";
    validateConsole(listener, 540L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.1s"));
    BuildRuleEvent.Started started = BuildRuleEvent.started(testBuildRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 800L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.4s", " |=> //:test...  0.2s (checking_cache)"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String buildingLine = "[-] BUILDING...FINISHED 0.8s";
    validateConsole(listener, 1300L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.started(// isRunAllTests
    true, TestSelectorList.empty(), // shouldExplainTestSelectorList
    false, ImmutableSet.copyOf(testArgs)), 2500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.5s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRuleEvent.started(testTarget), 3100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.7s", " |=> //:test...  0.1s"));
    UUID stepUuid = new UUID(0, 1);
    StepEvent.Started stepEventStarted = StepEvent.started("step_name", "step_desc", stepUuid);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 3300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3400L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.9s", " |=> //:test...  0.3s (running step_name[0.1s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, 0), 3500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3600L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.1s", " |=> //:test...  0.5s"));
    UUID testUUID = new UUID(2, 3);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.started(testUUID, "TestClass", "Foo"), 3700L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3800L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.3s", " |=> //:test...  0.7s (running Foo[0.1s])"));
    TestResultSummary testResultSummary = new TestResultSummary("TestClass", "Foo", ResultType.SUCCESS, // time
    0L, // message
    null, // stacktrace
    null, // stdOut
    null, // stdErr
    null);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.finished(testUUID, testResultSummary), 3900L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 4000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.5s (1 PASS/0 FAIL)", " |=> //:test...  0.9s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.finished(ImmutableSet.copyOf(testArgs), ImmutableList.of(TestResults.of(testTarget, ImmutableList.of(new TestCaseSummary("TestClass", ImmutableList.of(testResultSummary))), // contacts
    ImmutableSet.of(), // labels
    ImmutableSet.of()))), 4100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String testingLine = "[-] TESTING...FINISHED 1.6s (1 PASS/0 FAIL)";
    validateConsoleWithStdOutAndErr(listener, 4200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, testingLine), ImmutableList.of(), Optional.of(Joiner.on('\n').join("RESULTS FOR ALL TESTS", "PASS    <100ms  1 Passed   0 Skipped   0 Failed   TestClass", "TESTS PASSED", "")), // We don't care about stderr, since the last frame will be flushed there.
    Optional.empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ConsoleTestUtils.postStoreStarted(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreStarted) ProjectBuildFileParseEvents(com.facebook.buck.json.ProjectBuildFileParseEvents) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) UUID(java.util.UUID) ConsoleTestUtils.postStoreFinished(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished) StepEvent(com.facebook.buck.step.StepEvent) RuleKey(com.facebook.buck.rules.RuleKey) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) Test(org.junit.Test)

Example 9 with TestCaseSummary

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

the class TestResultFormatterTest method shouldReportTheNumberOfFailingTestsWithMoreThanOneTest.

@Test
public void shouldReportTheNumberOfFailingTestsWithMoreThanOneTest() {
    TestResultFormatter formatter = createSilentFormatter();
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(successTest, failingTest, new TestResultSummary("com.example.FooTest", "anotherFail", ResultType.FAILURE, 200, "Unexpected fnord found", null, null, null)));
    TestResults results = TestResults.of(BuildTargetFactory.newInstance("//foo:bar"), ImmutableList.of(summary), /* contacts */
    ImmutableSet.of(), /* labels */
    ImmutableSet.of());
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    formatter.runComplete(builder, ImmutableList.of(results), ImmutableList.of());
    String expectedOutput = Joiner.on('\n').join("TESTS FAILED: 2 FAILURES", "Failed target: //foo:bar", "FAIL com.example.FooTest");
    assertEquals(expectedOutput, 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) TestResultSummary(com.facebook.buck.test.TestResultSummary) Test(org.junit.Test)

Example 10 with TestCaseSummary

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

the class TestResultFormatterTest method shouldNotOutputLogLinesOfFailingTestIfMaxLinesIsZero.

@Test
public void shouldNotOutputLogLinesOfFailingTestIfMaxLinesIsZero() throws IOException {
    TestResultFormatter formatter = createFormatterWithMaxLogLines(0);
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(failingTest));
    Files.write(logPath, ImmutableList.of("None", "of", "these", "will", "appear"), 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"), 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