I am running integration tests for my Spring Boot application with Maven's Failsafe plugin. When I create a simple test such as this one:
@RunWith (SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(App.class)
public class MyTestIT {
@Test
public void test() {
assertTrue (true);
}
}
And then run mvn verify
I see the following log entries just before the Spring application starts (e.g. even before the Spring Boot banner):
Running org.....MyTestIT
2016-04-14 13:25:01.166 INFO ???? --- [ main]
or.sp.te.co.su.AbstractContextLoader :
Could not detect default resource locations for test class
[org....MyTestIT]: no resource found for suffixes
{-context.xml, Context.groovy}.
2016-04-14 13:25:01.175 INFO ???? --- [ main]
or.sp.te.co.su.DefaultTestContextBootstrapper :
Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [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]
2016-04-14 13:25:01.185 INFO ???? --- [ main]
or.sp.te.co.su.DefaultTestContextBootstrapper : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@57c758ac, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@a9cd3b1, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@13e39c73, org.springframework.test.context.support.DirtiesContextTestExecutionListener@64cd705f, org.springframework.test.context.transaction.TransactionalTestExecutionListener@9225652, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@654f0d9c]
Followed by the Spring Boot banner. The tests then run through without any error. While these messages are printed with an INFO log level and the tests run fine, I guess everything is fine, but I still find these messages irritating. So is there something wrong with my configuration? Should I worry about these messages?
Even if there was nothing wrong, I would still like to understand whats happending there and what the messages mean.
My maven-failsafe-plugin
is just using the default configuration and my App.java
is just a simple class annotated with @SpringBootApplication
.
UPDATE 1:
Here is the configuration of my test plugins:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Ignore any tests that are marked by the @IntegrationTest annotation of Spring Boot -->
<excludedGroups>org.springframework.boot.test.IntegrationTest</excludedGroups>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
I also have a spring-boot-starter-test
dependency configured and I am using spring-boot-devtools
. Besides that everything else is not test related.
The project it self is pretty standard, using hibernate and mysql and web-mvc for rest endpoints. I have two configuration classes for spring security on the class pass.
In the main/resources
folder I have an application.properties
file and a log4j2.xml. There is no test/resources
folder, but when I just copy the main/resources folder to test/resources
the above log messages still appear.
UPDATE 2:
I just created a small sample application trying to recreate the issue, and it seems the mentioned log-output starts to appear as soon as I put a log4j2.xml
file into a resources folder. I tried putting it in src/main
or src/test
or both with identical effects.
This is the default behaviour when running Spring integration tests.
From the reference documentation
If you omit both the locations and value attributes from the @ContextConfiguration annotation, the TestContext framework will attempt to detect a default XML resource location. Specifically, GenericXmlContextLoader and GenericXmlWebContextLoader detect a default location based on the name of the test class. If your class is named com.example.MyTest, GenericXmlContextLoader loads your application context from "classpath:com/example/MyTest-context.xml".
So, it's not related whatsoever to Maven, log4j or the positioning/assistance of resource folder.
Should I worry about these messages?
Not at all, apparently.
but I still find these messages irritating
Don't know if and how to turn off that check (Course you can eliminate it by changing the log level of AbstractContextLoader
to WARN
).
You can use AnnotationConfigContextLoader
in combination with @Configuration.
See here for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With