Search in sources :

Example 1 with TestReportDataCollector

use of org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector in project gradle by gradle.

the class AbstractTestTask method executeTests.

@TaskAction
public void executeTests() {
    LogLevel currentLevel = determineCurrentLogLevel();
    TestLogging levelLogging = getTestLogging().get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    TestExecutionSpec executionSpec = createTestExecutionSpec();
    final File binaryResultsDir = getBinaryResultsDirectory().getAsFile().get();
    FileSystemOperations fs = getFileSystemOperations();
    fs.delete(new Action<DeleteSpec>() {

        @Override
        public void execute(DeleteSpec spec) {
            spec.delete(binaryResultsDir);
        }
    });
    binaryResultsDir.mkdirs();
    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(getProgressLoggerFactory());
    addTestListener(testCountLogger);
    getTestListenerInternalBroadcaster().add(new TestListenerAdapter(testListenerBroadcaster.getSource(), getTestOutputListenerBroadcaster().getSource()));
    ProgressLogger parentProgressLogger = getProgressLoggerFactory().newOperation(AbstractTestTask.class);
    parentProgressLogger.setDescription("Test Execution");
    parentProgressLogger.started();
    TestWorkerProgressListener testWorkerProgressListener = new TestWorkerProgressListener(getProgressLoggerFactory(), parentProgressLogger);
    getTestListenerInternalBroadcaster().add(testWorkerProgressListener);
    TestExecuter<TestExecutionSpec> testExecuter = Cast.uncheckedNonnullCast(createTestExecuter());
    TestListenerInternal resultProcessorDelegate = getTestListenerInternalBroadcaster().getSource();
    if (failFast) {
        resultProcessorDelegate = new FailFastTestListenerInternal(testExecuter, resultProcessorDelegate);
    }
    TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(resultProcessorDelegate);
    try {
        testExecuter.execute(executionSpec, resultProcessor);
    } finally {
        parentProgressLogger.completed();
        testWorkerProgressListener.completeAll();
        testListenerBroadcaster.removeAll();
        getTestOutputListenerBroadcaster().removeAll();
        getTestListenerInternalBroadcaster().removeAll();
        outputWriter.close();
    }
    new TestResultSerializer(binaryResultsDir).write(results.values());
    createReporting(results, testOutputStore);
    handleCollectedResults(testCountLogger);
}
Also used : TestResultSerializer(org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer) HashMap(java.util.HashMap) TestResultProcessor(org.gradle.api.internal.tasks.testing.TestResultProcessor) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestClassResult(org.gradle.api.internal.tasks.testing.junit.result.TestClassResult) TestCountLogger(org.gradle.api.internal.tasks.testing.logging.TestCountLogger) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestExecutionSpec(org.gradle.api.internal.tasks.testing.TestExecutionSpec) FileSystemOperations(org.gradle.api.file.FileSystemOperations) LogLevel(org.gradle.api.logging.LogLevel) TestEventLogger(org.gradle.api.internal.tasks.testing.logging.TestEventLogger) TestWorkerProgressListener(org.gradle.api.internal.tasks.testing.logging.TestWorkerProgressListener) DeleteSpec(org.gradle.api.file.DeleteSpec) FailFastTestListenerInternal(org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal) TestReportDataCollector(org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector) TestLogging(org.gradle.api.tasks.testing.logging.TestLogging) TestListenerInternal(org.gradle.api.internal.tasks.testing.results.TestListenerInternal) FailFastTestListenerInternal(org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal) TestListenerAdapter(org.gradle.api.internal.tasks.testing.results.TestListenerAdapter) TestOutputStore(org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore) TestExceptionFormatter(org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

File (java.io.File)1 HashMap (java.util.HashMap)1 DeleteSpec (org.gradle.api.file.DeleteSpec)1 FileSystemOperations (org.gradle.api.file.FileSystemOperations)1 FailFastTestListenerInternal (org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal)1 TestExecutionSpec (org.gradle.api.internal.tasks.testing.TestExecutionSpec)1 TestResultProcessor (org.gradle.api.internal.tasks.testing.TestResultProcessor)1 TestClassResult (org.gradle.api.internal.tasks.testing.junit.result.TestClassResult)1 TestOutputStore (org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore)1 TestReportDataCollector (org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector)1 TestResultSerializer (org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer)1 TestCountLogger (org.gradle.api.internal.tasks.testing.logging.TestCountLogger)1 TestEventLogger (org.gradle.api.internal.tasks.testing.logging.TestEventLogger)1 TestExceptionFormatter (org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter)1 TestWorkerProgressListener (org.gradle.api.internal.tasks.testing.logging.TestWorkerProgressListener)1 StateTrackingTestResultProcessor (org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor)1 TestListenerAdapter (org.gradle.api.internal.tasks.testing.results.TestListenerAdapter)1 TestListenerInternal (org.gradle.api.internal.tasks.testing.results.TestListenerInternal)1 LogLevel (org.gradle.api.logging.LogLevel)1 TaskAction (org.gradle.api.tasks.TaskAction)1