Hakky54 / log-captor

🎯 LogCaptor captures log entries for unit and integration testing purposes
Apache License 2.0
370 stars 25 forks source link

Not working with static variable #98

Closed naviud closed 3 months ago

naviud commented 3 months ago

Describe the bug As mentioned in README, I tried to create a private static LogCaptor variable and initialized from a method annotated with @BeforeAll. So the method should be a static ofc. With that approach, looks like logs are not captured.

But this works perfectly with non static way.

To Reproduce

  1. Simply follow the readme -> https://github.com/Hakky54/log-captor?tab=readme-ov-file#initialize-logcaptor-once-and-reuse-it-during-multiple-tests-with-clearlogs-method-within-the-aftereach-method

Expected behavior Way mentioned above is the elegant way. I believe, it should work in that way as well.

Environmental Data:

Additional context N/A

Hakky54 commented 3 months ago

Hi @naviud thank you creating this ticket and nice to see that developers actually are giving the examples a try. That example should work, so I find it strange that it is not working for you. I added a test case which is exactly running the example which you mentioned, see here: https://github.com/Hakky54/log-captor/pull/99

And it is passing. So it is probably not related to logcapture, but maybe to something else... Is your Junit 5 dependency correctly defined? Or are you using something else to have a similar structure?

Maybe you can create a small POC repository at your github profile, so we can have a look at it together, what do you think?

Hakky54 commented 3 months ago

I am closing this ticket as the issue you mentioned is not happening as shown here: https://github.com/Hakky54/log-captor/pull/99

The tests are passing with the setup you mentioned. So I am assuming it is related to your local dev environment or ide setup. If you still have the issue, I am willing to help you out. You can create a private repo at github and add me as collaborator which will give the the possibility to invesitgate and test it on my side