Given a native C++ project, using the google-test plugin automatically creates a test suite for each component. I’d like to be able to create additional test suite(s) for a component each with their own source set, for example to be able to separate unit tests from integration tests. My attempt so far (as described below) has been unsuccessful - does anyone know how this can be done?
Using the google-test sample project as a starting point, I’ve tried adding the following to the model.
testSuites {
operatorsIntegTest(GoogleTestTestSuiteSpec) {
sources {
cpp.source.srcDir 'src/operatorsIntegTest/cpp'
}
}
}
Trying to build results in a NPE
> Exception thrown while executing model rule: GoogleTestPlugin.Rules#createGoogleTestTestBinaries > afterEach()
> java.lang.NullPointerException (no error message)
The cause of the stack trace is
Caused by: java.lang.NullPointerException
at org.gradle.nativeplatform.test.googletest.plugins.GoogleTestPlugin$Rules$2.execute(GoogleTestPlugin.java:105)
at org.gradle.nativeplatform.test.googletest.plugins.GoogleTestPlugin$Rules$2.execute(GoogleTestPlugin.java:102)
104 public void execute(final GoogleTestTestSuiteSpec testSuiteSpec) {
105 for (final NativeBinarySpec testedBinary : testSuiteSpec.getTestedComponent().getBinaries().withType(NativeBinarySpec.class).values()) {
So it looks like it’s failing because the testedComponent is null, which makes sense as there is nothing binding the test suite to the component. Finding a setTestedComponent method, I’ve tried setting it explicitly as follows:
testSuites {
operatorsIntegTest(GoogleTestTestSuiteSpec) {
testedComponent project.components.findByName('operators')
sources {
cpp.source.srcDir 'src/operatorsIntegTest/cpp'
}
}
}
but after some digging it appears that project.components is still empty at the time this is evaluated. I’ve tried wrapping the setting of testedComponent in doLast, but that results in
> Exception thrown while executing model rule: GoogleTestPlugin.Rules#configureGoogleTestTestSuiteSources
> Exception thrown while executing model rule: model.testSuites > create(operatorsIntegTest)
> Attempt to mutate closed view of model of type 'org.gradle.platform.base.test.TestSuiteContainer' given to rule 'model.testSuites'
Is there another way to get the operations component during the configuration phase?