Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringJUnit4ClassRunner to pick up specific logback configuration

Tags:

java

junit

spring

Is there any way to specify the logback configuration file to use in a JUnit run by 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 got logback.xml and multiple of them. There is one that is supposed to run in prod and then there is one that I want this test to pick up. Is there a easy way to do it?


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


like image 544
partha Avatar asked Jul 07 '14 11:07

partha


1 Answers

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

-Dlogback.configurationFile="fullpathtofile\logback.xml"
like image 158
UserF40 Avatar answered Oct 21 '22 08:10

UserF40