SpringJUnit4ClassRunner用于获取特定的logback配置

时间:2014-07-07 11:25:42

标签: java spring junit

有没有办法指定要在Spring运行的JUnit中使用的logback配置文件?

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

  @Autowired
  Something something;
} 

现在,我有 logback.xml 以及其中的多个。有一个应该在prod中运行,然后有一个我想要这个测试。有一个简单的方法吗?


编辑:这个问题特定于我从Eclipse运行JUnit时的情况。我正在使用Windows 7上的Eclipse 4.3。


1 个答案:

答案 0 :(得分:1)

将该位置作为JVM argurment传递给在eclipse中运行测试的配置。

-Dlogback.configurationFile="fullpathtofile\logback.xml"
相关问题