문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 마지막 판 양쪽 다음 판 | ||
java:slf4j [2021/08/17 15:25] kwon37xi |
java:slf4j [2023/11/30 15:28] kwon37xi [Test Slf4j - Reflection 사용] |
||
---|---|---|---|
줄 173: | 줄 173: | ||
System.setProperty(" | System.setProperty(" | ||
</ | </ | ||
+ | |||
+ | ===== Test Slf4j - Reflection 사용 ===== | ||
+ | * [[java: | ||
+ | |||
+ | <code java> | ||
+ | TestTargetClass testTarget = new TestTarget(); | ||
+ | private Logger mockedLogger; | ||
+ | |||
+ | @BeforeEach | ||
+ | void setUp() throws NoSuchFieldException, | ||
+ | mockedLogger = mock(Logger.class); | ||
+ | |||
+ | Field logField = TestTargetClass.class.getDeclaredField(" | ||
+ | logField.setAccessible(true); | ||
+ | |||
+ | Field modifiersField = Field.class.getDeclaredField(" | ||
+ | modifiersField.setAccessible(true); | ||
+ | modifiersField.setInt(logField, | ||
+ | |||
+ | logField.set(null, | ||
+ | } | ||
+ | |||
+ | @Test | ||
+ | void testMethod() { | ||
+ | testTarget.callMethod() | ||
+ | |||
+ | verify(mockedLogger).info(" | ||
+ | |||
+ | } | ||
+ | |||
+ | // Lombok @Slf4j 로 private static final Logger log 필드 주입 | ||
+ | @Slf4j | ||
+ | public static class TestTargetClass { | ||
+ | public void callMethod() { | ||
+ | log.info(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
===== Test Slf4j ===== | ===== Test Slf4j ===== | ||
+ | * [[https:// | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * http:// | ||
===== 참조 ===== | ===== 참조 ===== | ||
* [[https:// | * [[https:// | ||