Static state methods naturally make themselves rather unstable, so my suggestion is based on reorganizing your code from static methods.
I would turn Logger into an instance class that accepts an IO object in the constructor. This will allow you to stub the I / O object, and you can state that the method of your I / O object Close
was called.
This is only if you want to make your code 100% available for testing. Otherwise, I would agree with Mo that if it is not subject to verification, then do not write a forced test ... they are usually very fragile. In the end, you need to be pragmatic about your code. The registrar is often useful for maintaining static, however, as I mentioned, they are usually very unstable ... so just be pragmatic in your work and donβt write tests in a simple attempt to get 100% coverage of the code., That 100 % will come with a price ...
UPDATE
This is why this cannot be verified based on dogmatic POV unit testing. You are not testing the unit of work, but instead you are checking the Logger AND Logger dependencies (in this case, the IO object). It also slows down your tests and requires setting up the environment and state (you must first open the actual file to close it, right?). All this is bad for unit testing, but fine for integration testing ... so it depends on which tests you also write.
source share