codeconsole commented on code in PR #16399:
URL: https://github.com/apache/grails-core/pull/16399#discussion_r4106775649
##########
grails-testing-support-core/src/main/groovy/org/grails/testing/GrailsApplicationBuilder.groovy:
##########
@@ -170,9 +178,18 @@ class GrailsApplicationBuilder {
beanFactory.allowCircularReferences =
environment.getProperty(Settings.SPRING_MAIN_ALLOW_CIRCULAR_REFERENCES,
Boolean, Boolean.TRUE)
def classLoader = this.class.classLoader
+ // The test's own configuration first, as an application's comes
before auto-configuration:
+ // parsed ahead of them, its beans are what an auto-configuration's
@ConditionalOnMissingBean sees.
+ configurationClasses?.each { Class<?> configurationClass ->
Review Comment:
I took the second option in 8e96d24249 and documented the difference.
Registering included plugins' beans before configuration parsing would close
both gaps, but it moves the plugin drain for every unit test, not just ones
using the new hooks. It would interact with how `doWithConfig` is applied, for
one: the early phase builds its config before a test's `doWithConfig` runs. I'd
rather make that change in its own PR, where it can be judged on its own.
- The test plugin's registrar bean now has its own type,
`RegisteredGreeting`, so `IncludedPluginBeansSpec` no longer passes on a bean
the plugin wouldn't create in an application.
- The plugin also has a conditional fallback of that type.
`IncludedPluginConditionalBeansSpec` pins the difference: the test gets
`[registeredGreeting, fallbackGreeting]` where an application gets
`registeredGreeting` alone.
- `TestConditionalBeanOverIncludedPluginSpec` pins the same gap for the
test's own conditional bean. It also shows that the plugin's fallback does back
off from the test's bean, as it would in an application, because the test's
configuration is read first.
- "Spring configuration from plugins" now has a warning that a
`@ConditionalOnMissingBean` bean doesn't back off from an included plugin's
`doWithSpring`/`beanRegistrar` beans in a unit test, whether it's the plugin's
or the test's, and that such beans should be looked up by name.
##########
grails-doc/src/en/guide/upgrading/upgrading80x.adoc:
##########
@@ -1695,6 +1695,12 @@ class MyGrailsPlugin extends Plugin {
Both hooks may be used on the same plugin during migration; when a registrar
and the DSL register a bean under the same name, the registrar's definition
wins.
+**Unit tests follow.** `doWithSpring()` on the `GrailsUnitTest` trait — and so
on every testing trait — is deprecated too. A test now declares its beans in a
`beans` block with the `beans` DSL, as an application or plugin does; overrides
`beanRegistrar()`, applied where an application's is; or declares a static
nested `@Configuration` class, which its context registers ahead of the
framework's auto-configurations. A `beans` block compiles into one such class,
named `BeansConfiguration`, so a test that already declares a nested class of
that name must rename it. A test that includes a plugin through
`getIncludePlugins()` also gets the beans the plugin's `beans` block declares,
which `defineBeans(plugin)` cannot apply. See <<unitTesting,Unit Testing>>.
+
+A test that already has a static nested `@Configuration` class meant for
something other than its own context — one built for an
`ApplicationContextRunner`, say — now has it registered there as well; override
`getConfigurationClasses()` to leave it out.
+
+**A `beans` block names a nested type's bean by its simple name.** In earlier
8.0 milestones `bean(Outer.Helper)`, with no name given, registered a bean
named `outer$Helper`. It is now `helper`, the type's decapitalized simple name,
as documented. Name it explicitly, `bean('outer$Helper', Outer.Helper)`, if
anything looks it up by the old name.
Review Comment:
Adjusted in 8e96d24249, but with one correction: the `beans` DSL first
shipped in 8.0.0-M6, not RC1. #16019 is an ancestor of `v8.0.0-M6` (tagged
2026-08-26), and the `outer$Helper` derivation was there from the start. So the
note now reads "In 8.0.0-M6 and 8.0.0-RC1, `bean(Outer.Helper)` with no name
given registered a bean named `outer$Helper`."
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]