Can gradle tasks be created that subset the tests in a project?

119 views Asked by At

I am using the gradle tooling api to kick off tests based on receiving a webhook.

I don't see a way to pass parameters to the tooling API. I can run tests with something like:

        String workingDir = System.getProperty("user.dir");

        ProjectConnection connection = GradleConnector.newConnector()
                .forProjectDirectory(new File(workingDir))
                .connect();
        try {
            connection.newBuild().forTasks("test").run();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            connection.close();
        }

But I don't see a way to run something like "gradle test --tests=xxx" so I was hoping I could make gradle tasks that were subsets of tests like "gradle dev_tests", "gradle int_tests".

Does anyone know if this is possible and if so, how to do it?

1

There are 1 answers

2
Tony Farias On BEST ANSWER

Per the gradle docs, newBuild() functions, conveniently ,as a builder pattern. You can set several parameters before calling run() on it .

//select tasks to run:
    build.forTasks( "test");

    //include some build arguments:
    build.withArguments("--tests=xxx");
    ...
    build.run();

Source: https://docs.gradle.org/current/javadoc/org/gradle/tooling/BuildLauncher.html