org.junit.rules.TestRule
public final class ExpectedLogMessagesRule extends Object implements org.junit.rules.TestRule
Constructor | Description |
---|---|
ExpectedLogMessagesRule() |
Modifier and Type | Method | Description |
---|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
|
void |
expectErrorsForTag(String tag) |
Blanket suppress test failures due to errors from a tag.
|
void |
expectLogMessage(int level,
String tag,
String message) |
Adds an expected log statement.
|
void |
expectLogMessageWithThrowable(int level,
String tag,
String message,
Throwable throwable) |
Adds an expected log statement with extra check of
Throwable . |
void |
expectLogMessageWithThrowableMatcher(int level,
String tag,
String message,
org.hamcrest.Matcher<Throwable> throwableMatcher) |
Adds an expected log statement with extra check of
Matcher . |
void |
ignoreMissingLoggedTags(boolean shouldIgnore) |
If set true, tests that call
expectErrorsForTag(String) but do not log errors for the
given tag will not fail. |
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
public void expectLogMessage(int level, String tag, String message)
expectLogMessageWithThrowable(int, String, String, Throwable)
.
Do not use this to suppress failures. Use this to test that expected error cases in
your code cause log messages to be printed.public void expectLogMessageWithThrowable(int level, String tag, String message, Throwable throwable)
Throwable
. If this log is not
printed during test execution, the test case will fail. Do not use this to suppress failures.
Use this to test that expected error cases in your code cause log messages to be printed.public void expectLogMessageWithThrowableMatcher(int level, String tag, String message, org.hamcrest.Matcher<Throwable> throwableMatcher)
Matcher
. If this log is not printed
during test execution, the test case will fail. Do not use this to suppress failures. Use this
to test that expected error cases in your code cause log messages to be printed.public void expectErrorsForTag(String tag)
ignoreMissingLoggedTags(boolean)
is used).
Avoid using this method when possible. Prefer to assert on the presence of a specific
message using expectLogMessage(int, java.lang.String, java.lang.String)
in test cases that *intentionally* trigger an error.
public void ignoreMissingLoggedTags(boolean shouldIgnore)
expectErrorsForTag(String)
but do not log errors for the
given tag will not fail. By default this is false.
Avoid using this method when possible. Prefer tests that print (or do not print) log messages deterministically.