Search in sources :

Example 1 with TestExecutionException

use of org.gradle.api.tasks.testing.TestExecutionException in project gradle by gradle.

the class TestExecutionRequestActionRunner method run.

@Override
public void run(BuildAction action, BuildController buildController) {
    if (!(action instanceof TestExecutionRequestAction)) {
        return;
    }
    GradleInternal gradle = buildController.getGradle();
    try {
        TestExecutionRequestAction testExecutionRequestAction = (TestExecutionRequestAction) action;
        TestExecutionResultEvaluator testExecutionResultEvaluator = new TestExecutionResultEvaluator(testExecutionRequestAction);
        buildOperationService.addListener(testExecutionResultEvaluator);
        try {
            doRun(testExecutionRequestAction, buildController);
        } finally {
            buildOperationService.removeListener(testExecutionResultEvaluator);
        }
        testExecutionResultEvaluator.evaluate();
    } catch (RuntimeException rex) {
        Throwable throwable = findRootCause(rex);
        if (throwable instanceof TestExecutionException) {
            throw new InternalTestExecutionException("Error while running test(s)", throwable);
        } else {
            throw rex;
        }
    }
    PayloadSerializer payloadSerializer = gradle.getServices().get(PayloadSerializer.class);
    buildController.setResult(new BuildActionResult(payloadSerializer.serialize(null), null));
}
Also used : TestExecutionRequestAction(org.gradle.tooling.internal.provider.TestExecutionRequestAction) GradleInternal(org.gradle.api.internal.GradleInternal) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) TestExecutionException(org.gradle.api.tasks.testing.TestExecutionException) InternalTestExecutionException(org.gradle.tooling.internal.protocol.test.InternalTestExecutionException) BuildActionResult(org.gradle.tooling.internal.provider.BuildActionResult) InternalTestExecutionException(org.gradle.tooling.internal.protocol.test.InternalTestExecutionException)

Example 2 with TestExecutionException

use of org.gradle.api.tasks.testing.TestExecutionException in project gradle by gradle.

the class TestExecutionBuildConfigurationAction method configureBuildForTestDescriptors.

private List<Test> configureBuildForTestDescriptors(GradleInternal gradle, TestExecutionRequestAction testExecutionRequest) {
    final Collection<InternalTestDescriptor> testDescriptors = testExecutionRequest.getTestExecutionDescriptors();
    final List<String> testTaskPaths = org.gradle.util.CollectionUtils.collect(testDescriptors, new Transformer<String, InternalTestDescriptor>() {

        @Override
        public String transform(InternalTestDescriptor testDescriptor) {
            return ((DefaultTestDescriptor) testDescriptor).getTaskPath();
        }
    });
    List<Test> testTasksToRun = new ArrayList<Test>();
    for (final String testTaskPath : testTaskPaths) {
        final Task task = gradle.getRootProject().getTasks().findByPath(testTaskPath);
        if (task == null) {
            throw new TestExecutionException(String.format("Requested test task with path '%s' cannot be found.", testTaskPath));
        } else if (!(task instanceof Test)) {
            throw new TestExecutionException(String.format("Task '%s' of type '%s' not supported for executing tests via TestLauncher API.", testTaskPath, task.getClass().getName()));
        } else {
            Test testTask = (Test) task;
            for (InternalTestDescriptor testDescriptor : testDescriptors) {
                DefaultTestDescriptor defaultTestDescriptor = (DefaultTestDescriptor) testDescriptor;
                if (defaultTestDescriptor.getTaskPath().equals(testTaskPath)) {
                    String className = defaultTestDescriptor.getClassName();
                    String methodName = defaultTestDescriptor.getMethodName();
                    if (className == null && methodName == null) {
                        testTask.getFilter().includeTestsMatching("*");
                    } else {
                        testTask.getFilter().includeTest(className, methodName);
                    }
                }
            }
            testTasksToRun.add(testTask);
        }
    }
    return testTasksToRun;
}
Also used : Task(org.gradle.api.Task) TestExecutionException(org.gradle.api.tasks.testing.TestExecutionException) Test(org.gradle.api.tasks.testing.Test) DefaultTestDescriptor(org.gradle.tooling.internal.provider.events.DefaultTestDescriptor) InternalTestDescriptor(org.gradle.tooling.internal.protocol.events.InternalTestDescriptor)

Aggregations

TestExecutionException (org.gradle.api.tasks.testing.TestExecutionException)2 Task (org.gradle.api.Task)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 Test (org.gradle.api.tasks.testing.Test)1 InternalTestDescriptor (org.gradle.tooling.internal.protocol.events.InternalTestDescriptor)1 InternalTestExecutionException (org.gradle.tooling.internal.protocol.test.InternalTestExecutionException)1 BuildActionResult (org.gradle.tooling.internal.provider.BuildActionResult)1 TestExecutionRequestAction (org.gradle.tooling.internal.provider.TestExecutionRequestAction)1 DefaultTestDescriptor (org.gradle.tooling.internal.provider.events.DefaultTestDescriptor)1 PayloadSerializer (org.gradle.tooling.internal.provider.serialization.PayloadSerializer)1