Created
November 8, 2012 07:38
-
-
Save sifue/4037421 to your computer and use it in GitHub Desktop.
Logbackのログ出力内容をJUnitとMockitoでテストする ref: http://qiita.com/items/45ff10586ef609df1bc2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 何かしらのログを出力する処理 | |
verify(mockAppender).doAppend(argThat(new ArgumentMatcher<LoggingEvent>() { | |
@Override | |
public boolean matches(Object argument) { | |
return ((LoggingEvent)argument).getFormattedMessage().contains("initOption() fail perse."); | |
} | |
})); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
以上のようなテストメソッドを書くことで、ログに"initOption() fail perse."を含む | |
メッセージが出力されたかどうかをテストできます。 | |
ちなみに利用したJUnitとMockitoのバージョンを表すMavenのpom.xml以下の通り。 | |
```xml | |
<dependencies> | |
<!-- JUNIT DEPENDENCY FOR TESTING --> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.10</version> | |
<scope>test</scope> | |
</dependency> | |
<!-- Mockito for support of mocking in test --> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-all</artifactId> | |
<version>1.9.0</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment