I noticed this as part of working on https://github.com/spring-projects/spring-boot/pull/29611. The documentation was rebuilt but the tests didn't run. The simplest fix is to add an input to the test task:

tasks.named('test') {
    inputs.dir('src/docs/gradle').withPathSensitivity(PathSensitivity.RELATIVE).withPropertyName('buildScripts')
}

This will fix the problem, but will mean that adding or changing an example in the docs will cause all of the plugin's tests to run. If that proves frustrating we could split the documentation-specific tests out into a separate source set but I'm not sure we should bother at first.