i am trying to find if there's a way to detect resource leak in tests. with junit or any other library.
last time, i was using junit5 @TempDir and i had my outputstream not closed it was throwing unable to delete temporary folder. it didn't listed the correct reason, nor i could find online. i just guessed and i checked if i am close my FileOutputStream and it was it. then it started working. no exception by junit.
but this is not very useful. is there a good way to find in tests if any resource is not closed.
General resource leaks
Consider static code analysis for the problem of detecting resource leaks generally. For instance Sonar has some help: https://rules.sonarsource.com/java/tag/leak/RSPEC-2095/
Leaks specific to JUnit
Sure, static code analysers may not spot problems where the resource is undetectable, e.g. in the case of
@TempDir, so you should suggest this directly the JUnit team... provide a PR even!