-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
OutputCapture reset method is package-private #33151
Comments
It looks like support for resetting the captured output was lost amid some of the changes for (#14738, #17029, etc). We can certainly consider reinstating it in some form.
What test framework are you using? I believe JUnit (4 and 5) uses a per-method lifecycle for each test instance by default. |
@wilkinsona Actually, I mean reset method is package-private. Yeah, you are right by default per-method lifecycle is being used, but as far as I use dependency injection for injection CapturedOutput as method parameter, so state of object is not being wiped. |
@wilkinsona Probably, this is not too much to implement. I would be grateful to contribute a little. (using this guide) |
Ok, you're using
Due to the pushing and popping performed by |
@wilkinsona Actually, I have checked this behavior and you are right one test not see logs of another one. But in method being tested I log multiple messages with different log level and it would be so helpful to have method to check message in array view not as string one. |
Can you please expand a bit on what you mean by "array view"? |
@wilkinsona OutputCapture has private field systemCaptures of Deque type. CapturedOutput interface have no any access method to this field. I don't want to assert string with every log line by matching it with any regex or using mockito assetrContains on string. I want check collection of elements where each of element represent one log line. Such representation will help to asset for example with Kluent |
If you want to to do per line assertions you can do |
If you're using Java 11 or later, |
Hello, I'm currently trying to utilize
OutputCapture
in my unit testing to test logging level. And I face issue that I'm not able to resetOutputCapture
, but according this pull request this functionality should be implemented. My spring-boot version is 2.7.4.Probably, I can change fixture of test every time by using
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
, but I suppose that is not the best solution.I suppose, adding any functionality to check logging level would be a very good contributing as well.
The text was updated successfully, but these errors were encountered: