-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SolrTestCase now supports @LogLevel #2869
base: main
Are you sure you want to change the base?
Conversation
Refactored the functionality into a TestRule, and moved from STCJ4 up to SolrTestCase. Move reinstatement of the root log level to shutdown()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some basic observational testing of some classes that used LogLevel at method and class level to see that logs showed up for only certain methods but not others.
Not doing a JIRA for a test refactorings like this.
// re-instate original log level. | ||
if (!INITIAL_ROOT_LOG_LEVEL.equals(getLogLevelString())) { | ||
changeLogLevel(INITIAL_ROOT_LOG_LEVEL); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The move of this re-instate / reset of the root log level into shutdown() is debatable. I was trying to reduce little details in STC/STCJ4.
* A JUnit {@link TestRule} that sets (and resets) the Log4j2 log level based on the {@code | ||
* LogLevel} annotation. | ||
*/ | ||
public class LogLevelTestRule implements TestRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this is the perfect use case for a JUnit's TestRule. It takes advantage of observing the annotations that are present so that it can insert the Statement or skip it. And it works at both the class and method level with the same Statement. And it's generally useful -- I could see someone taking this into their own projects.
Maybe a case could be made for putting this rule as an inner class under LogLevel, so that it's more packaged together.
I don't know about the But I'm curious: why not just leave that Either way I would suggest updating the |
Rules bring an encapsulation benefit -- I'd say that's the biggest IMO. Also mix/match, yes. But I don't see why any test would want to opt-out of this one given how cheap/light-weight it is, with its annotation based activation of the underlying Statement wrapper. I think we want to make it super-easy to debug a test with logs -- just add an annotation. Likewise I'm grateful other rules are defined always like system property clearing; I don't want tests to waste lines of code over basic book-keeping. I'd feel differently about a rule that seems heavy and/or is imposing in some way. |
Refactored the functionality into a TestRule, and moved from STCJ4 up to SolrTestCase.
Move reinstatement of the root log level to shutdown()
(part of bigger goal of abandoning SolrTestCaseJ4)