Apart from the reasons you gave, I would argue that unit tests also remove the need for comments in several situations.
Aside from all the benefits that unit tests bring, they also can clearly define the intent of each code block. In your regex example, I would say that even without refactoring the method to simpler regex expressions, you can have multiple tests that help understand what that method is validating.
And unlike comments, unit tests can be enforced to be valid and updated when the code changes.
That’s a very good point. The only caveat is that you have to actually open the separate file for the unit tests, which isn’t a big deal it’s just another level of separation between the code and it’s specifications.
Apart from the reasons you gave, I would argue that unit tests also remove the need for comments in several situations.
Aside from all the benefits that unit tests bring, they also can clearly define the intent of each code block. In your regex example, I would say that even without refactoring the method to simpler regex expressions, you can have multiple tests that help understand what that method is validating.
And unlike comments, unit tests can be enforced to be valid and updated when the code changes.
That’s a very good point. The only caveat is that you have to actually open the separate file for the unit tests, which isn’t a big deal it’s just another level of separation between the code and it’s specifications.
You don't always need to. Many IDEs will run them in a window and display test names and failures. That can be explanatory enough in many cases