Search in sources :

Example 6 with TestResults

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

the class TestRunningTest method testIsTestRunRequiredForTestInDebugMode.

@Test
public void testIsTestRunRequiredForTestInDebugMode() throws IOException, ExecutionException, InterruptedException {
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setDebugEnabled(true).build();
    assertTrue(executionContext.isDebugEnabled());
    assertTrue("In debug mode, test should always run regardless of any cached results since " + "the user is expecting to hook up a debugger.", TestRunning.isTestRunRequiredForTest(createMock(TestRule.class), createMock(CachingBuildEngine.class), executionContext, createMock(TestRuleKeyFileHelper.class), TestRunningOptions.TestResultCacheMode.ENABLED, Callables.<TestResults>returning(null), false, /* hasEnvironmentOverrides */
    false));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) Test(org.junit.Test)

Example 7 with TestResults

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

the class CxxTestTest method interpretResults.

@Test
public void interpretResults() throws Exception {
    final Path expectedExitCode = Paths.get("output");
    final Path expectedOutput = Paths.get("output");
    final Path expectedResults = Paths.get("results");
    FakeCxxTest cxxTest = new FakeCxxTest() {

        @Override
        public SourcePath getSourcePathToOutput() {
            return new ExplicitBuildTargetSourcePath(getBuildTarget(), Paths.get("output"));
        }

        @Override
        protected Path getPathToTestExitCode() {
            return expectedExitCode;
        }

        @Override
        protected Path getPathToTestOutput() {
            return expectedOutput;
        }

        @Override
        protected Path getPathToTestResults() {
            return expectedResults;
        }

        @Override
        protected ImmutableList<TestResultSummary> parseResults(Path exitCode, Path output, Path results) throws Exception {
            assertEquals(expectedExitCode, exitCode);
            assertEquals(expectedOutput, output);
            assertEquals(expectedResults, results);
            return ImmutableList.of();
        }
    };
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    Callable<TestResults> result = cxxTest.interpretTestResults(executionContext, /* isUsingTestSelectors */
    false);
    result.call();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestResults(com.facebook.buck.test.TestResults) TestResultSummary(com.facebook.buck.test.TestResultSummary) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 8 with TestResults

use of com.facebook.buck.test.TestResults 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 9 with TestResults

use of com.facebook.buck.test.TestResults 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)

Example 10 with TestResults

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

the class TestResultFormatterTest method failingTestShouldShowTestStatusMessages.

@Test
public void failingTestShouldShowTestStatusMessages() throws IOException {
    TestResultFormatter formatter = createSilentFormatter();
    TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(successTest, failingTest));
    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(TestStatusMessage.of("Hello world", Level.INFO, 1450473060000L)));
    String expectedOutput = Joiner.on('\n').join("====TEST STATUS MESSAGES====", "[2015-12-18 13:11:00.000][INFO] Hello world", "TESTS FAILED: 1 FAILURE", "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) Test(org.junit.Test)

Aggregations

TestResults (com.facebook.buck.test.TestResults)33 Test (org.junit.Test)28 FakeTestResults (com.facebook.buck.test.FakeTestResults)27 TestCaseSummary (com.facebook.buck.test.TestCaseSummary)25 ImmutableList (com.google.common.collect.ImmutableList)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 ExecutionContext (com.facebook.buck.step.ExecutionContext)10 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)10 TestResultSummary (com.facebook.buck.test.TestResultSummary)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)8 FakeTestRule (com.facebook.buck.rules.FakeTestRule)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)8 BuildResult (com.facebook.buck.rules.BuildResult)6 CachingBuildEngine (com.facebook.buck.rules.CachingBuildEngine)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)4 Path (java.nio.file.Path)4 BuildTarget (com.facebook.buck.model.BuildTarget)3 FakeBuildEngine (com.facebook.buck.rules.FakeBuildEngine)3