Specifying a custom log4j.properties file for all of JUnit tests run from Eclipse

后端 未结 2 1500
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 07:51

I would like to specify a specific Eclipse VM argument to all of the JUnit tests I run from Eclipse i.e.

-Dlog4j.configuration=log4j-dev.propert         


        
2条回答
  •  感情败类
    2020-11-27 08:08

    You do not need to give the JVM a different property name. The logging code searches for the log4j.properties file using the classpath. So all you need to do is ensure that your test log4j.properties file is in a location that it will find before the release file.

    I use Maven, which lays out files in directories to make that easy. My release log4j.properties goes in the directory src/main/resources. My test version goes in src/test/resources. The Eclipse build path (classpath) is set up to search src/test/resources before src/main/resources, so your unit tests use the test file. The JAR (or WAR) build instructions use the files from src/main/resources.

提交回复
热议问题