When using the google-test plugin, how can I add tests only to specific components?

My project is structured such that I have two components — a library containing all the business logic and an executable which is a thin wrapper around it. I’m using the google-test plugin to run tests over the library, but not the executable.

However, test tasks are still created for the non-existent executable tests (e.g. runMainTestGoogleTestExe). When this task runs, the build aborts because it runs the executable’s main() rather than a test suite’s, which then bails because required command-line arguments are missing.

How can I prevent test tasks from being created for my executable?

apply plugin: 'cpp'
apply plugin: 'google-test'

model {
    components {
        main(NativeExecutableSpec) {
            sources {
                cpp {
                    lib library: 'solver', linkage: 'static'
                }
            }
        }

        solver(NativeLibrarySpec)
    }
}
1 Like

Unfortunately, there’s no easy way at this time, aside from using separate Gradle projects for the different components. The plan is to make explicit the configuration of a test suite component for a component, rather than it being implicit for every component.

Would it be possible for the Google Test plugin to check whether the _component_Test directory exists and only create the test suite if it does?
I’m thinking about this method here:

public void createGoogleTestTestSuitePerComponent(TestSuiteContainer testSuites, ModelMap<NativeComponentSpec> components) {
            for (final NativeComponentSpec component : components.values()) {
                final String suiteName = String.format("%sTest", component.getName());
                testSuites.create(suiteName, GoogleTestTestSuiteSpec.class, new Action<GoogleTestTestSuiteSpec>() {
                    @Override
                    public void execute(GoogleTestTestSuiteSpec testSuite) {
                        testSuite.setTestedComponent(component);
                    }
                });
            }
        }