JUnit 用のログ設定を行う

リリース用のログ設定ファイル、
  logback 使用の場合 → logback.xml
  log4j2 使用の場合 → log4j2.xml
これを src/main/resources に配置するが、Junitテスト用のログ設定を別に用意したい時、、、

import org.junit.BeforeClass;

システムプロパティで、設定ファイルの読込み先指定を
@BeforeClass 付与の static メソッドで、実行する。

logback テスト用 test-logback.xml を使用

@BeforeClass
public static void initialize(){
    System.setProperty("logback.configurationFile","test-logback.xml");
}

src/test/resources に test-logback.xml を配置する。


log4j2 テスト用 test-log4j2.xml を使用

@BeforeClass
public static void initialize(){
    System.setProperty("log4j.configurationFile","test-log4j2.xml");
}

src/test/resources に test-log4j2.xml を配置する。