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

TestExecutionListener class not found logged at INFO [SPR-16369] #20916

Closed
spring-issuemaster opened this issue Jan 12, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jan 12, 2018

Dave Syer opened SPR-16369 and commented

spring-test has this in META-INF/spring.factories:

org.springframework.test.context.TestExecutionListener = \
	org.springframework.test.context.web.ServletTestExecutionListener,\
	org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener,\
	org.springframework.test.context.support.DependencyInjectionTestExecutionListener,\
	org.springframework.test.context.support.DirtiesContextTestExecutionListener,\
	org.springframework.test.context.transaction.TransactionalTestExecutionListener,\
	org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener

and then it logs at INFO level (in AbstractTestContextBootstrapper.instantiateListeners()) any of those that it cannot load. This is kind of ugly because it generates a lot of logging (several lines per test in a phase that is too early to change using Spring Boot configuration). Maybe they could be logged at a lower level?

Example logs:

2018-01-12 08:49:51.439  INFO 29447 --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
2018-01-12 08:49:51.439  INFO 29447 --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
2018-01-12 08:49:51.439  INFO 29447 --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
2018-01-12 08:49:51.439  INFO 29447 --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@5b275174, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@10ef5fa0, org.springframework.test.context.support.DirtiesContextTestExecutionListener@244e619a, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@10acd6, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@61dde151, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@b25b095, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@5cb042da, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@59c33386, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@571a9686]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

Referenced from: commits ea5f8f5, a15975d, 19640ec, 2145766

Backported to: 4.3.14

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 13, 2018

Sam Brannen commented

Thanks for tackling this one (and the refactoring you performed), Juergen Hoeller!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 17, 2018

Dave Syer commented

I think something is broken here now:

try {
     listeners.add(BeanUtils.instantiateClass(listenerClass));
}
catch (NoClassDefFoundError err) {
     if (logger.isDebugEnabled()) {
              logger.debug(String.format("Could not instantiate TestExecutionListener [%s]. " +
                                "Specify custom listener classes or make the default listener classes " +
                                "(and their required dependencies) available. Offending class: [%s]",
                                listenerClass.getName(), err.getMessage()));
     }
}

The exception is not NoClassDefFoundError but BeanInstantiationException so it isn't caught and logged.

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.test.context.transaction.TransactionalTestExecutionListener]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:175)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:120)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.instantiateListeners(AbstractTestContextBootstrapper.java:185)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.getTestExecutionListeners(AbstractTestContextBootstrapper.java:169)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:136)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:120)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
    at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:523)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: java.lang.NoClassDefFoundError: org/springframework/transaction/annotation/AnnotationTransactionAttributeSource
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.<init>(TransactionalTestExecutionListener.java:137)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 31 more
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 17, 2018

Juergen Hoeller commented

Ah, so such a NoClassDefFoundError comes out as an InvocationTargetException from the constructor which we'll then adapt to a BeanInstantiationException... I'll revise that code accordingly. All I wanted to get rid of there is extra catch blocks for NoClassDefFoundError when it can only really occur through one specific code path, and it looks like that code path is not the raw throwing one but the indirect BeanInstantiationException variant.

This also needs to be documented at BeanUtils.instantiateClass level since the lack of a well-defined contract there is exactly what leads to the defensive overuse of catch blocks outside.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 17, 2018

Juergen Hoeller commented

I've pushed my revision to master. Let me know whether it works for you now, Dave...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 17, 2018

Juergen Hoeller commented

One more time: I missed the case where unresolvable classes may occur in the constructor signature itself. Finally revising BeanUtils.instantiateClass to consistently catch and wrap that case as well and therefore providing a reliable exception expectation for its direct callers, we should be good to go now. About to be committed...

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 18, 2018

Dave Syer commented

Works now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.