From 6d09459cfce484cb9835489186a93ac6f4058b3f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 13 Dec 2024 19:01:45 -0800 Subject: [PATCH] Improve error message when unable to find `@SpringBootConfiguration` Closes gh-43357 --- .../test/context/SpringBootTestContextBootstrapper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java index 40970888546f..27532bca5edc 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -243,8 +243,11 @@ private Class findConfigurationClass(Class testClass) { return ClassUtils.resolveClassName(foundClassName, testClass.getClassLoader()); } Class found = new AnnotatedClassFinder(SpringBootConfiguration.class).findFromClass(testClass); - Assert.state(found != null, "Unable to find a @SpringBootConfiguration, you need to use " - + "@ContextConfiguration or @SpringBootTest(classes=...) with your test"); + Assert.state(found != null, + "Unable to find a @SpringBootConfiguration by searching packages upwards from the test. " + + "You can use @ContextConfiguration, @SpringBootTest(classes=...) or other Spring Test " + + "supported mechanisms to explicitly declare the configuration classes to load. Classes " + + "annotated with @TestConfiguration are not considered."); this.aotTestAttributes.setAttribute(propertyName, found.getName()); return found; }