Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringBoot3.0.3 appears that the test cannot be used #34364

Closed
livk-cloud opened this issue Feb 24, 2023 · 5 comments
Closed

SpringBoot3.0.3 appears that the test cannot be used #34364

livk-cloud opened this issue Feb 24, 2023 · 5 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@livk-cloud
Copy link

livk-cloud commented Feb 24, 2023

In SpringBoot3.0.3, it is mandatory to specify the Main class for the test.

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

This error occurred when I upgraded from 3.0.2 to 3.0.3. In 3.0.2, there was no such problem

In the update log, I did not get the place where the test has changed

example

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 24, 2023
@livk-cloud
Copy link
Author

livk-cloud commented Feb 24, 2023

I suspect that the change of org.springframework.core.io.support.PathMatchingResourcePatternResolver makes it impossible to search for class

@wilkinsona
Copy link
Member

Thanks for the report. Unfortunately, the sample does not reproduce the problem:

$ mvn test                  
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.livk:spring-test-demo >----------------------
[INFO] Building spring-test-demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ spring-test-demo ---
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ spring-test-demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/awilkinson/Downloads/spring-test-demo/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ spring-test-demo ---
[INFO] skip non existing resourceDirectory /Users/awilkinson/Downloads/spring-test-demo/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ spring-test-demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/awilkinson/Downloads/spring-test-demo/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ spring-test-demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.livk.springtestdemo.SpringTestDemoApplicationTests
07:43:30.100 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [SpringTestDemoApplicationTests]: using SpringBootContextLoader
07:43:30.104 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.livk.springtestdemo.SpringTestDemoApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
07:43:30.105 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.livk.springtestdemo.SpringTestDemoApplicationTests]: SpringTestDemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
07:43:30.140 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using ContextCustomizers for test class [SpringTestDemoApplicationTests]: [ImportsContextCustomizer, ExcludeFilterContextCustomizer, DuplicateJsonObjectContextCustomizer, MockitoContextCustomizer, TestRestTemplateContextCustomizer, DisableObservabilityContextCustomizer, PropertyMappingContextCustomizer, Customizer]
07:43:30.221 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/awilkinson/Downloads/spring-test-demo/target/classes/com/livk/springtestdemo/SpringTestDemoApplication.class]
07:43:30.223 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.livk.springtestdemo.SpringTestDemoApplication for test class com.livk.springtestdemo.SpringTestDemoApplicationTests
07:43:30.323 [main] DEBUG org.springframework.test.context.util.TestContextSpringFactoriesUtils - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom TestExecutionListener classes or make the default TestExecutionListener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
07:43:30.326 [main] DEBUG org.springframework.test.context.util.TestContextSpringFactoriesUtils - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom TestExecutionListener classes or make the default TestExecutionListener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
07:43:30.329 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners for test class [SpringTestDemoApplicationTests]: [ServletTestExecutionListener, DirtiesContextBeforeModesTestExecutionListener, ApplicationEventsTestExecutionListener, MockitoTestExecutionListener, DependencyInjectionTestExecutionListener, DirtiesContextTestExecutionListener, EventPublishingTestExecutionListener, ResetMocksTestExecutionListener, RestDocsTestExecutionListener, MockRestServiceServerResetTestExecutionListener, MockMvcPrintOnlyOnFailureTestExecutionListener, WebDriverTestExecutionListener, MockWebServiceServerTestExecutionListener]
07:43:30.330 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: class [SpringTestDemoApplicationTests], class annotated with @DirtiesContext [false] with mode [null]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.3)

2023-02-24T07:43:30.617Z  INFO 88715 --- [           main] c.l.s.SpringTestDemoApplicationTests     : Starting SpringTestDemoApplicationTests using Java 17.0.6 with PID 88715 (started by awilkinson in /Users/awilkinson/Downloads/spring-test-demo)
2023-02-24T07:43:30.618Z  INFO 88715 --- [           main] c.l.s.SpringTestDemoApplicationTests     : No active profile set, falling back to 1 default profile: "default"
2023-02-24T07:43:31.746Z  INFO 88715 --- [           main] o.s.b.t.m.w.SpringBootMockServletContext : Initializing Spring TestDispatcherServlet ''
2023-02-24T07:43:31.747Z  INFO 88715 --- [           main] o.s.t.web.servlet.TestDispatcherServlet  : Initializing Servlet ''
2023-02-24T07:43:31.749Z  INFO 88715 --- [           main] o.s.t.web.servlet.TestDispatcherServlet  : Completed initialization in 0 ms
2023-02-24T07:43:31.766Z  INFO 88715 --- [           main] c.l.s.SpringTestDemoApplicationTests     : Started SpringTestDemoApplicationTests in 1.402 seconds (process running for 2.365)

MockHttpServletRequest:
      HTTP Method = GET
      Request URI = /home
       Parameters = {}
          Headers = []
             Body = null
    Session Attrs = {}

Handler:
             Type = com.livk.springtestdemo.SpringTestDemoApplication
           Method = com.livk.springtestdemo.SpringTestDemoApplication#home()

Async:
    Async started = false
     Async result = null

Resolved Exception:
             Type = null

ModelAndView:
        View name = null
             View = null
            Model = null

FlashMap:
       Attributes = null

MockHttpServletResponse:
           Status = 200
    Error message = null
          Headers = [Content-Type:"text/plain;charset=UTF-8", Content-Length:"12"]
     Content type = text/plain;charset=UTF-8
             Body = Hello World!
    Forwarded URL = null
   Redirected URL = null
          Cookies = []
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.342 s - in com.livk.springtestdemo.SpringTestDemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.398 s
[INFO] Finished at: 2023-02-24T07:43:32Z
[INFO] ------------------------------------------------------------------------

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Feb 24, 2023
@livk-cloud
Copy link
Author

Thank you for your answer. There is no problem when I test on another computer. Maybe it is caused by some other unknown factors.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2023
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Feb 24, 2023
@wilkinsona
Copy link
Member

I think this is another symptom of the suspected regression in Spring Framework that's been identified in #34379. @livk-cloud, if I am right, you can avoid the problem by not having any spaces in your application's path.

@livk-cloud
Copy link
Author

I think this is another symptom of the suspected regression in Spring Framework that's been identified in #34379. @livk-cloud, if I am right, you can avoid the problem by not having any spaces in your application's path.

Yes, my path contains spaces, when I use _ instead of spaces, my program has no problem, maybe it has something to do with windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants