私は重複したファイル(testとmainのlog4j.properties)が好きではないので、かなりたくさんのテストクラスがあり、それぞれSpringJUnit4ClassRunnerクラスで動作しますので、カスタマイズする必要があります。これは私が使用するものです。
import java.io.FileNotFoundException;
import org.junit.runners.model.InitializationError;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Log4jConfigurer;
public class MySpringJUnit4ClassRunner extends SpringJUnit4ClassRunner {
static {
String log4jLocation = "classpath:log4j-oops.properties";
try {
Log4jConfigurer.initLogging(log4jLocation);
} catch (FileNotFoundException ex) {
System.err.println("Cannot Initialize log4j at location: " + log4jLocation);
}
}
public MySpringJUnit4ClassRunner(Class<?> clazz) throws InitializationError {
super(clazz);
}
}
あなたがそれを使用し、MySpringJUnit4ClassRunner
@RunWith(MySpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:conf/applicationContext.xml")
public class TestOrderController {
private Logger LOG = LoggerFactory.getLogger(this.getClass());
private MockMvc mockMvc;
...
}
でSpringJUnit4ClassRunnerを置き換えるだけで参考のために、ここでは変換パターンの参照のためのリンクを次のとおりです。http://logging.apache。 org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html – lanoxx
なぜこれを行うのか説明できますか? – iLoveCamelCase
project/src/test/resources/log4j.properties –