Example #1
0
  @TaskAction
  public void executeTests() {
    for (LogLevel level : LogLevel.values()) {
      if (!LOGGER.isEnabled(level)) {
        continue;
      }
      TestLogging levelLogging = testLogging.get(level);
      TestExceptionFormatter exceptionFormatter = getExceptionFormatter(testLogging);
      TestEventLogger eventLogger =
          new TestEventLogger(outputListener, level, levelLogging, exceptionFormatter);
      addTestListener(eventLogger);
      addTestOutputListener(eventLogger);
    }

    ProgressLoggerFactory progressLoggerFactory = getServices().get(ProgressLoggerFactory.class);
    TestCountLogger testCountLogger = new TestCountLogger(progressLoggerFactory);
    addTestListener(testCountLogger);

    TestResultProcessor resultProcessor =
        new TestListenerAdapter(
            getTestListenerBroadcaster().getSource(), testOutputListenerBroadcaster.getSource());
    testExecuter.execute(this, resultProcessor);

    testFramework.report();

    testFramework = null;

    if (!getIgnoreFailures() && testCountLogger.hadFailures()) {
      throw new GradleException(
          "There were failing tests. See the report at " + getTestReportUrl() + ".");
    }
  }
Example #2
0
  @TaskAction
  public void executeTests() {
    LogLevel currentLevel = getCurrentLogLevel();
    TestLogging levelLogging = testLogging.get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger =
        new TestEventLogger(textOutputFactory, currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    if (!getFilter().getIncludePatterns().isEmpty()) {
      addTestListener(
          new NoMatchingTestsReporter(
              "No tests found for given includes: " + getFilter().getIncludePatterns()));
    }

    File binaryResultsDir = getBinResultsDir();
    getProject().delete(binaryResultsDir);
    getProject().mkdir(binaryResultsDir);

    Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
    TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);

    TestOutputStore.Writer outputWriter = testOutputStore.writer();
    TestReportDataCollector testReportDataCollector =
        new TestReportDataCollector(results, outputWriter);

    addTestListener(testReportDataCollector);
    addTestOutputListener(testReportDataCollector);

    TestCountLogger testCountLogger = new TestCountLogger(progressLoggerFactory);
    addTestListener(testCountLogger);

    TestResultProcessor resultProcessor =
        new TestListenerAdapter(
            getTestListenerBroadcaster().getSource(), testOutputListenerBroadcaster.getSource());

    try {
      testExecuter.execute(this, resultProcessor);
    } finally {
      testListenerBroadcaster.removeAll();
      testOutputListenerBroadcaster.removeAll();
      outputWriter.close();
    }

    new TestResultSerializer(binaryResultsDir).write(results.values());

    TestResultsProvider testResultsProvider =
        new InMemoryTestResultsProvider(results.values(), testOutputStore.reader());

    try {
      JUnitXmlReport junitXml = reports.getJunitXml();
      if (junitXml.isEnabled()) {
        TestOutputAssociation outputAssociation =
            junitXml.isOutputPerTestCase()
                ? TestOutputAssociation.WITH_TESTCASE
                : TestOutputAssociation.WITH_SUITE;
        Binary2JUnitXmlReportGenerator binary2JUnitXmlReportGenerator =
            new Binary2JUnitXmlReportGenerator(
                junitXml.getDestination(), testResultsProvider, outputAssociation);
        binary2JUnitXmlReportGenerator.generate();
      }

      DirectoryReport html = reports.getHtml();
      if (!html.isEnabled()) {
        getLogger().info("Test report disabled, omitting generation of the HTML test report.");
      } else {
        testReporter.generateReport(testResultsProvider, html.getDestination());
      }
    } finally {
      CompositeStoppable.stoppable(testResultsProvider).stop();
    }

    testFramework = null;

    if (testCountLogger.hadFailures()) {
      handleTestFailures();
    }
  }