SpringJUnit4ClassRunner to select a specific log configuration

Can I specify a log configuration file that will be used when starting JUnit with Spring?

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/my/app/springConfiguration.xml") public class MyTest { private static final Logger logger = LoggerFactory.getLogger(MyTest.class); @Autowired Something something; } 

Now I have logback.xml and a few of them. There is one that should work in prod, and then there is one that I want this test to take. Is there an easy way to do this?


Edit: This question is specific to the case when I run JUnit from my Eclipse. I am working on Eclipse 4.3 on Windows 7.


+7
java spring junit
source share
1 answer

Pass the location as a JVM argument in the configuration that runs your tests in eclipse.

 -Dlogback.configurationFile="fullpathtofile\logback.xml" 
+1
source share

All Articles